@@ -11,7 +11,7 @@ import (
11
11
"github.com/thirdweb-dev/indexer/internal/common"
12
12
)
13
13
14
- func SerializeFullBlocks (chainId * big.Int , blocks []RPCFetchBatchResult [common.RawBlock ], logs []RPCFetchBatchResult [common.RawLogs ], traces []RPCFetchBatchResult [common.RawTraces ], receipts []RPCFetchBatchResult [common.RawReceipts ]) []GetFullBlockResult {
14
+ func SerializeFullBlocks (chainId * big.Int , blocks []RPCFetchBatchResult [* big. Int , common.RawBlock ], logs []RPCFetchBatchResult [* big. Int , common.RawLogs ], traces []RPCFetchBatchResult [* big. Int , common.RawTraces ], receipts []RPCFetchBatchResult [* big. Int , common.RawReceipts ]) []GetFullBlockResult {
15
15
if blocks == nil {
16
16
return []GetFullBlockResult {}
17
17
}
@@ -21,46 +21,46 @@ func SerializeFullBlocks(chainId *big.Int, blocks []RPCFetchBatchResult[common.R
21
21
rawReceiptsMap := mapBatchResultsByBlockNumber [common.RawReceipts ](receipts )
22
22
rawTracesMap := mapBatchResultsByBlockNumber [common.RawTraces ](traces )
23
23
24
- for _ , rawBlock := range blocks {
24
+ for _ , rawBlockData := range blocks {
25
25
result := GetFullBlockResult {
26
- BlockNumber : rawBlock . BlockNumber ,
26
+ BlockNumber : rawBlockData . Key ,
27
27
}
28
- if rawBlock .Result == nil {
29
- log .Warn ().Err (rawBlock .Error ).Msgf ("Received a nil block result for block %s." , rawBlock . BlockNumber .String ())
30
- result .Error = fmt .Errorf ("received a nil block result from RPC. %v" , rawBlock .Error )
28
+ if rawBlockData .Result == nil {
29
+ log .Warn ().Err (rawBlockData .Error ).Msgf ("Received a nil block result for block %s." , rawBlockData . Key .String ())
30
+ result .Error = fmt .Errorf ("received a nil block result from RPC. %v" , rawBlockData .Error )
31
31
results = append (results , result )
32
32
continue
33
33
}
34
34
35
- if rawBlock .Error != nil {
36
- result .Error = rawBlock .Error
35
+ if rawBlockData .Error != nil {
36
+ result .Error = rawBlockData .Error
37
37
results = append (results , result )
38
38
continue
39
39
}
40
40
41
- result .Data .Block = serializeBlock (chainId , rawBlock .Result )
41
+ result .Data .Block = serializeBlock (chainId , rawBlockData .Result )
42
42
blockTimestamp := result .Data .Block .Timestamp
43
43
44
- if rawReceipts , exists := rawReceiptsMap [rawBlock . BlockNumber .String ()]; exists {
44
+ if rawReceipts , exists := rawReceiptsMap [rawBlockData . Key .String ()]; exists {
45
45
if rawReceipts .Error != nil {
46
46
result .Error = rawReceipts .Error
47
47
} else {
48
48
result .Data .Logs = serializeLogsFromReceipts (chainId , rawReceipts .Result , result .Data .Block )
49
- result .Data .Transactions = serializeTransactions (chainId , rawBlock .Result ["transactions" ].([]interface {}), blockTimestamp , & rawReceipts .Result )
49
+ result .Data .Transactions = serializeTransactions (chainId , rawBlockData .Result ["transactions" ].([]interface {}), blockTimestamp , & rawReceipts .Result )
50
50
}
51
51
} else {
52
- if rawLogs , exists := rawLogsMap [rawBlock . BlockNumber .String ()]; exists {
52
+ if rawLogs , exists := rawLogsMap [rawBlockData . Key .String ()]; exists {
53
53
if rawLogs .Error != nil {
54
54
result .Error = rawLogs .Error
55
55
} else {
56
56
result .Data .Logs = serializeLogs (chainId , rawLogs .Result , result .Data .Block )
57
- result .Data .Transactions = serializeTransactions (chainId , rawBlock .Result ["transactions" ].([]interface {}), blockTimestamp , nil )
57
+ result .Data .Transactions = serializeTransactions (chainId , rawBlockData .Result ["transactions" ].([]interface {}), blockTimestamp , nil )
58
58
}
59
59
}
60
60
}
61
61
62
62
if result .Error == nil {
63
- if rawTraces , exists := rawTracesMap [rawBlock . BlockNumber .String ()]; exists {
63
+ if rawTraces , exists := rawTracesMap [rawBlockData . Key .String ()]; exists {
64
64
if rawTraces .Error != nil {
65
65
result .Error = rawTraces .Error
66
66
} else {
@@ -75,26 +75,26 @@ func SerializeFullBlocks(chainId *big.Int, blocks []RPCFetchBatchResult[common.R
75
75
return results
76
76
}
77
77
78
- func mapBatchResultsByBlockNumber [T any ](results []RPCFetchBatchResult [T ]) map [string ]* RPCFetchBatchResult [T ] {
78
+ func mapBatchResultsByBlockNumber [T any ](results []RPCFetchBatchResult [* big. Int , T ]) map [string ]* RPCFetchBatchResult [* big. Int , T ] {
79
79
if results == nil {
80
- return make (map [string ]* RPCFetchBatchResult [T ], 0 )
80
+ return make (map [string ]* RPCFetchBatchResult [* big. Int , T ], 0 )
81
81
}
82
- resultsMap := make (map [string ]* RPCFetchBatchResult [T ], len (results ))
82
+ resultsMap := make (map [string ]* RPCFetchBatchResult [* big. Int , T ], len (results ))
83
83
for _ , result := range results {
84
- resultsMap [result .BlockNumber .String ()] = & result
84
+ resultsMap [result .Key .String ()] = & result
85
85
}
86
86
return resultsMap
87
87
}
88
88
89
- func SerializeBlocks (chainId * big.Int , blocks []RPCFetchBatchResult [common.RawBlock ]) []GetBlocksResult {
89
+ func SerializeBlocks (chainId * big.Int , blocks []RPCFetchBatchResult [* big. Int , common.RawBlock ]) []GetBlocksResult {
90
90
results := make ([]GetBlocksResult , 0 , len (blocks ))
91
91
92
92
for _ , rawBlock := range blocks {
93
93
result := GetBlocksResult {
94
- BlockNumber : rawBlock .BlockNumber ,
94
+ BlockNumber : rawBlock .Key ,
95
95
}
96
96
if rawBlock .Result == nil {
97
- log .Warn ().Msgf ("Received a nil block result for block %s." , rawBlock .BlockNumber .String ())
97
+ log .Warn ().Msgf ("Received a nil block result for block %s." , rawBlock .Key .String ())
98
98
result .Error = fmt .Errorf ("received a nil block result from RPC" )
99
99
results = append (results , result )
100
100
continue
@@ -473,3 +473,15 @@ func interfaceToJsonString(value interface{}) string {
473
473
}
474
474
return string (jsonString )
475
475
}
476
+
477
+ func SerializeTransactions (chainId * big.Int , transactions []RPCFetchBatchResult [string , common.RawTransaction ]) []GetTransactionsResult {
478
+ results := make ([]GetTransactionsResult , 0 , len (transactions ))
479
+ for _ , transaction := range transactions {
480
+ result := GetTransactionsResult {
481
+ Error : transaction .Error ,
482
+ Data : serializeTransaction (chainId , transaction .Result , time.Time {}, nil ),
483
+ }
484
+ results = append (results , result )
485
+ }
486
+ return results
487
+ }
0 commit comments