@@ -93,6 +93,9 @@ type Header struct {
9393
9494 // ParentBeaconRoot was added by EIP-4788 and is ignored in legacy headers.
9595 ParentBeaconRoot * common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
96+
97+ // DepositsHash was added by EIP-6110 and is ignored in legacy headers.
98+ DepositsHash * common.Hash `json:"depositsRoot" rlp:"optional"`
9699}
97100
98101// field type overrides for gencodec
@@ -171,6 +174,7 @@ type Body struct {
171174 Transactions []* Transaction
172175 Uncles []* Header
173176 Withdrawals []* Withdrawal `rlp:"optional"`
177+ Deposits []* Deposit `rlp:"optional"`
174178}
175179
176180// Block represents an Ethereum block.
@@ -195,6 +199,7 @@ type Block struct {
195199 uncles []* Header
196200 transactions Transactions
197201 withdrawals Withdrawals
202+ deposits Deposits
198203
199204 // caches
200205 hash atomic.Pointer [common.Hash ]
@@ -212,6 +217,7 @@ type extblock struct {
212217 Txs []* Transaction
213218 Uncles []* Header
214219 Withdrawals []* Withdrawal `rlp:"optional"`
220+ Deposits []* Deposit `rlp:"optional"`
215221}
216222
217223// NewBlock creates a new block. The input data is copied, changes to header and to the
@@ -272,6 +278,30 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade
272278 return b .WithWithdrawals (withdrawals )
273279}
274280
281+ // NewBlockWithWithdrawals creates a new block with withdrawals. The input data is copied,
282+ // changes to header and to the field values will not affect the block.
283+ //
284+ // The values of TxHash, UncleHash, ReceiptHash and Bloom in header are ignored and set to
285+ // values derived from the given txs, uncles and receipts.
286+ func NewBlockWithDeposits (header * Header , txs []* Transaction , uncles []* Header , receipts []* Receipt , withdrawals []* Withdrawal , deposits []* Deposit , hasher TrieHasher ) * Block {
287+ b := NewBlockWithWithdrawals (header , txs , uncles , receipts , withdrawals , hasher )
288+
289+ if deposits == nil {
290+ b .header .DepositsHash = nil
291+ } else if len (deposits ) == 0 {
292+ b .header .DepositsHash = & EmptyWithdrawalsHash
293+ } else {
294+ h := DeriveSha (Deposits (deposits ), hasher )
295+ b .header .DepositsHash = & h
296+ }
297+
298+ b = b .WithWithdrawals (withdrawals )
299+
300+ // TODO(matt): copy this
301+ b .deposits = deposits
302+ return b
303+ }
304+
275305// CopyHeader creates a deep copy of a block header.
276306func CopyHeader (h * Header ) * Header {
277307 cpy := * h
@@ -304,6 +334,10 @@ func CopyHeader(h *Header) *Header {
304334 cpy .ParentBeaconRoot = new (common.Hash )
305335 * cpy .ParentBeaconRoot = * h .ParentBeaconRoot
306336 }
337+ if h .DepositsHash != nil {
338+ cpy .DepositsHash = new (common.Hash )
339+ * cpy .DepositsHash = * h .DepositsHash
340+ }
307341 return & cpy
308342}
309343
@@ -332,7 +366,7 @@ func (b *Block) EncodeRLP(w io.Writer) error {
332366// Body returns the non-header content of the block.
333367// Note the returned data is not an independent copy.
334368func (b * Block ) Body () * Body {
335- return & Body {b .transactions , b .uncles , b .withdrawals }
369+ return & Body {b .transactions , b .uncles , b .withdrawals , b . deposits }
336370}
337371
338372// Accessors for body data. These do not return a copy because the content
@@ -341,6 +375,7 @@ func (b *Block) Body() *Body {
341375func (b * Block ) Uncles () []* Header { return b .uncles }
342376func (b * Block ) Transactions () Transactions { return b .transactions }
343377func (b * Block ) Withdrawals () Withdrawals { return b .withdrawals }
378+ func (b * Block ) Deposits () Deposits { return b .deposits }
344379
345380func (b * Block ) Transaction (hash common.Hash ) * Transaction {
346381 for _ , transaction := range b .transactions {
@@ -468,6 +503,23 @@ func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
468503 return block
469504}
470505
506+ func (b * Block ) WithBody2 (body * Body ) * Block {
507+ block := & Block {
508+ header : b .header ,
509+ transactions : make ([]* Transaction , len (body .Transactions )),
510+ uncles : make ([]* Header , len (body .Uncles )),
511+ withdrawals : make ([]* Withdrawal , len (body .Withdrawals )),
512+ deposits : make ([]* Deposit , len (body .Deposits )),
513+ }
514+ copy (block .transactions , body .Transactions )
515+ for i := range body .Uncles {
516+ block .uncles [i ] = CopyHeader (body .Uncles [i ])
517+ }
518+ copy (block .withdrawals , body .Withdrawals )
519+ copy (block .deposits , body .Deposits )
520+ return block
521+ }
522+
471523// WithWithdrawals returns a copy of the block containing the given withdrawals.
472524func (b * Block ) WithWithdrawals (withdrawals []* Withdrawal ) * Block {
473525 block := & Block {
0 commit comments