@@ -11,7 +11,7 @@ import (
1111 "github.com/thirdweb-dev/indexer/internal/common"
1212)
1313
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 {
1515 if blocks == nil {
1616 return []GetFullBlockResult {}
1717 }
@@ -21,46 +21,46 @@ func SerializeFullBlocks(chainId *big.Int, blocks []RPCFetchBatchResult[common.R
2121 rawReceiptsMap := mapBatchResultsByBlockNumber [common.RawReceipts ](receipts )
2222 rawTracesMap := mapBatchResultsByBlockNumber [common.RawTraces ](traces )
2323
24- for _ , rawBlock := range blocks {
24+ for _ , rawBlockData := range blocks {
2525 result := GetFullBlockResult {
26- BlockNumber : rawBlock . BlockNumber ,
26+ BlockNumber : rawBlockData . Key ,
2727 }
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 )
3131 results = append (results , result )
3232 continue
3333 }
3434
35- if rawBlock .Error != nil {
36- result .Error = rawBlock .Error
35+ if rawBlockData .Error != nil {
36+ result .Error = rawBlockData .Error
3737 results = append (results , result )
3838 continue
3939 }
4040
41- result .Data .Block = serializeBlock (chainId , rawBlock .Result )
41+ result .Data .Block = serializeBlock (chainId , rawBlockData .Result )
4242 blockTimestamp := result .Data .Block .Timestamp
4343
44- if rawReceipts , exists := rawReceiptsMap [rawBlock . BlockNumber .String ()]; exists {
44+ if rawReceipts , exists := rawReceiptsMap [rawBlockData . Key .String ()]; exists {
4545 if rawReceipts .Error != nil {
4646 result .Error = rawReceipts .Error
4747 } else {
4848 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 )
5050 }
5151 } else {
52- if rawLogs , exists := rawLogsMap [rawBlock . BlockNumber .String ()]; exists {
52+ if rawLogs , exists := rawLogsMap [rawBlockData . Key .String ()]; exists {
5353 if rawLogs .Error != nil {
5454 result .Error = rawLogs .Error
5555 } else {
5656 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 )
5858 }
5959 }
6060 }
6161
6262 if result .Error == nil {
63- if rawTraces , exists := rawTracesMap [rawBlock . BlockNumber .String ()]; exists {
63+ if rawTraces , exists := rawTracesMap [rawBlockData . Key .String ()]; exists {
6464 if rawTraces .Error != nil {
6565 result .Error = rawTraces .Error
6666 } else {
@@ -75,26 +75,26 @@ func SerializeFullBlocks(chainId *big.Int, blocks []RPCFetchBatchResult[common.R
7575 return results
7676}
7777
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 ] {
7979 if results == nil {
80- return make (map [string ]* RPCFetchBatchResult [T ], 0 )
80+ return make (map [string ]* RPCFetchBatchResult [* big. Int , T ], 0 )
8181 }
82- resultsMap := make (map [string ]* RPCFetchBatchResult [T ], len (results ))
82+ resultsMap := make (map [string ]* RPCFetchBatchResult [* big. Int , T ], len (results ))
8383 for _ , result := range results {
84- resultsMap [result .BlockNumber .String ()] = & result
84+ resultsMap [result .Key .String ()] = & result
8585 }
8686 return resultsMap
8787}
8888
89- func SerializeBlocks (chainId * big.Int , blocks []RPCFetchBatchResult [common.RawBlock ]) []GetBlocksResult {
89+ func SerializeBlocks (chainId * big.Int , blocks []RPCFetchBatchResult [* big. Int , common.RawBlock ]) []GetBlocksResult {
9090 results := make ([]GetBlocksResult , 0 , len (blocks ))
9191
9292 for _ , rawBlock := range blocks {
9393 result := GetBlocksResult {
94- BlockNumber : rawBlock .BlockNumber ,
94+ BlockNumber : rawBlock .Key ,
9595 }
9696 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 ())
9898 result .Error = fmt .Errorf ("received a nil block result from RPC" )
9999 results = append (results , result )
100100 continue
@@ -473,3 +473,15 @@ func interfaceToJsonString(value interface{}) string {
473473 }
474474 return string (jsonString )
475475}
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