11package client
22
33import (
4- "fmt"
54 "math/big"
65
76 "github.com/attestantio/go-eth2-client/spec/bellatrix"
@@ -37,9 +36,9 @@ type RawTransactionWithSender struct {
3736// such as Header, Transactions and Withdrawals.
3837type Block struct {
3938 Hash common.Hash
40- Header types.Header
41- Transactions []types.Transaction
42- Withdrawals []types.Withdrawal
39+ Header * types.Header
40+ Transactions []* types.Transaction
41+ Withdrawals []* types.Withdrawal
4342}
4443
4544// Helper type that wraps a signed beacon block from any of the supported hard-forks.
@@ -102,23 +101,23 @@ func DecodeBellatrixExecutionPayload(input *api.ExecutionPayloadMsg) (*Block, er
102101 payload := new (bellatrix.ExecutionPayload )
103102
104103 if err := payload .UnmarshalSSZ (input .SszPayload ); err != nil {
105- fmt .Println ("error unmarshalling execution payload:" , err )
106104 return nil , err
107105 }
108106
109- transactions := make ([]types.Transaction , len (payload .Transactions ))
110- for _ , rawTx := range payload .Transactions {
107+ transactions := make ([]* types.Transaction , len (payload .Transactions ))
108+ for i , rawTx := range payload .Transactions {
111109 tx := new (types.Transaction )
112110 if err := tx .UnmarshalBinary (rawTx ); err != nil {
113111 continue
114112 }
115- transactions = append (transactions , * tx )
113+
114+ transactions [i ] = tx
116115 }
117116
118117 basefee := new (big.Int ).SetBytes (reverseBytes (payload .BaseFeePerGas [:]))
119118 diff , _ := new (big.Int ).SetString ("58750003716598352816469" , 10 )
120119
121- header := types.Header {
120+ header := & types.Header {
122121 ParentHash : common .Hash (payload .ParentHash ),
123122 Coinbase : common .Address (payload .FeeRecipient ),
124123 Root : payload .StateRoot ,
@@ -142,7 +141,7 @@ func DecodeBellatrixExecutionPayload(input *api.ExecutionPayloadMsg) (*Block, er
142141 Header : header ,
143142 Transactions : transactions ,
144143 // No withdrawals pre Capella
145- Withdrawals : []types.Withdrawal {},
144+ Withdrawals : []* types.Withdrawal {},
146145 }
147146
148147 return block , nil
@@ -152,23 +151,23 @@ func DecodeCapellaExecutionPayload(input *api.ExecutionPayloadMsg) (*Block, erro
152151 payload := new (capella.ExecutionPayload )
153152
154153 if err := payload .UnmarshalSSZ (input .SszPayload ); err != nil {
155- fmt .Println ("error unmarshalling execution payload:" , err )
156154 return nil , err
157155 }
158156
159- transactions := make ([]types.Transaction , len (payload .Transactions ))
160- for _ , rawTx := range payload .Transactions {
157+ transactions := make ([]* types.Transaction , len (payload .Transactions ))
158+ for i , rawTx := range payload .Transactions {
161159 tx := new (types.Transaction )
162160 if err := tx .UnmarshalBinary (rawTx ); err != nil {
163161 continue
164162 }
165- transactions = append (transactions , * tx )
163+
164+ transactions [i ] = tx
166165 }
167166
168167 basefee := new (big.Int ).SetBytes (reverseBytes (payload .BaseFeePerGas [:]))
169168 diff , _ := new (big.Int ).SetString ("58750003716598352816469" , 10 )
170169
171- header := types.Header {
170+ header := & types.Header {
172171 ParentHash : common .Hash (payload .ParentHash ),
173172 Coinbase : common .Address (payload .FeeRecipient ),
174173 Root : payload .StateRoot ,
@@ -187,16 +186,14 @@ func DecodeCapellaExecutionPayload(input *api.ExecutionPayloadMsg) (*Block, erro
187186 TxHash : common.Hash {}, // TODO: this is not present in block
188187 }
189188
190- withdrawals := make ([]types.Withdrawal , len (payload .Withdrawals ))
191- for _ , withdrawal := range payload .Withdrawals {
192- wd := types.Withdrawal {
189+ withdrawals := make ([]* types.Withdrawal , len (payload .Withdrawals ))
190+ for i , withdrawal := range payload .Withdrawals {
191+ withdrawals [ i ] = & types.Withdrawal {
193192 Index : uint64 (withdrawal .Index ),
194193 Validator : uint64 (withdrawal .ValidatorIndex ),
195194 Address : common .Address (withdrawal .Address ),
196195 Amount : uint64 (withdrawal .Amount ),
197196 }
198-
199- withdrawals = append (withdrawals , wd )
200197 }
201198
202199 block := & Block {
@@ -213,22 +210,22 @@ func DecodeDenebExecutionPayload(input *api.ExecutionPayloadMsg) (*Block, error)
213210 payload := new (deneb.ExecutionPayload )
214211
215212 if err := payload .UnmarshalSSZ (input .SszPayload ); err != nil {
216- fmt .Println ("error unmarshalling execution payload:" , err )
217213 return nil , err
218214 }
219215
220- transactions := make ([]types.Transaction , len (payload .Transactions ))
221- for _ , rawTx := range payload .Transactions {
216+ transactions := make ([]* types.Transaction , len (payload .Transactions ))
217+ for i , rawTx := range payload .Transactions {
222218 tx := new (types.Transaction )
223219 if err := tx .UnmarshalBinary (rawTx ); err != nil {
224220 continue
225221 }
226- transactions = append (transactions , * tx )
222+
223+ transactions [i ] = tx
227224 }
228225
229226 diff , _ := new (big.Int ).SetString ("58750003716598352816469" , 10 )
230227
231- header := types.Header {
228+ header := & types.Header {
232229 ParentHash : common .Hash (payload .ParentHash ),
233230 Coinbase : common .Address (payload .FeeRecipient ),
234231 Root : common .Hash (payload .StateRoot ),
@@ -250,16 +247,14 @@ func DecodeDenebExecutionPayload(input *api.ExecutionPayloadMsg) (*Block, error)
250247 ParentBeaconRoot : & common.Hash {}, // TODO: this is not present in block
251248 }
252249
253- withdrawals := make ([]types.Withdrawal , len (payload .Withdrawals ))
254- for _ , withdrawal := range payload .Withdrawals {
255- wd := types.Withdrawal {
250+ withdrawals := make ([]* types.Withdrawal , len (payload .Withdrawals ))
251+ for i , withdrawal := range payload .Withdrawals {
252+ withdrawals [ i ] = & types.Withdrawal {
256253 Index : uint64 (withdrawal .Index ),
257254 Validator : uint64 (withdrawal .ValidatorIndex ),
258255 Address : common .Address (withdrawal .Address ),
259256 Amount : uint64 (withdrawal .Amount ),
260257 }
261-
262- withdrawals = append (withdrawals , wd )
263258 }
264259
265260 block := & Block {
0 commit comments