@@ -31,13 +31,9 @@ type CmdData struct {
3131 } `json:"payload"`
3232}
3333
34- func PrepareTransactions (network string , blockId int64 , payload fetch.ProcessedPayload ) ([]repository.TransactionAttributes , error ) {
34+ func PrepareTransactions (network string , blockId int64 , payload fetch.ProcessedPayload , block repository. BlockAttributes ) ([]repository.TransactionAttributes , error ) {
3535 transactions := payload .Transactions
3636
37- if len (transactions ) == 0 {
38- return []repository.TransactionAttributes {}, nil
39- }
40-
4137 transactionRecords := make ([]repository.TransactionAttributes , 0 , len (transactions ))
4238
4339 var cmdData CmdData
@@ -91,9 +87,14 @@ func PrepareTransactions(network string, blockId int64, payload fetch.ProcessedP
9187 }
9288 }
9389
94- chainId , err := strconv .Atoi (cmdData .Meta .ChainId )
95- if err != nil {
96- return nil , fmt .Errorf ("converting ChainId for transaction %s: %w" , t .Hash , err )
90+ var chainId int
91+ if cmdData .Meta .ChainId != "" {
92+ chainId , err = strconv .Atoi (cmdData .Meta .ChainId )
93+ if err != nil {
94+ return nil , fmt .Errorf ("converting ChainId for transaction %s: %w" , t .Hash , err )
95+ }
96+ } else {
97+ chainId = block .ChainId
9798 }
9899
99100 txId := strconv .Itoa (t .TxId )
@@ -137,6 +138,14 @@ func PrepareTransactions(network string, blockId int64, payload fetch.ProcessedP
137138 transactionRecords = append (transactionRecords , transactionRecord )
138139 }
139140
141+ coinbaseTx , err := processCoinbaseTransaction (string (payload .Coinbase ), blockId , block .CreationTime , int64 (block .ChainId ))
142+
143+ if err != nil {
144+ return nil , fmt .Errorf ("processing coinbase transaction %d: %w" , blockId , err )
145+ }
146+
147+ transactionRecords = append (transactionRecords , coinbaseTx )
148+
140149 return transactionRecords , nil
141150}
142151
0 commit comments