@@ -67,6 +67,60 @@ func (h *HeaderExtra) UnmarshalJSON(eth *ethtypes.Header, input []byte) error {
6767 return nil
6868}
6969
70+ func (h * HeaderExtra ) Copy (header * Header ) * Header {
71+ extraCopy := & HeaderExtra {
72+ ExtDataHash : h .ExtDataHash ,
73+ }
74+
75+ if h .BlockGasCost != nil {
76+ extraCopy .BlockGasCost = big .NewInt (0 )
77+ extraCopy .BlockGasCost .SetBytes (h .BlockGasCost .Bytes ())
78+ }
79+
80+ if h .ExtDataGasUsed != nil {
81+ extraCopy .ExtDataGasUsed = big .NewInt (0 )
82+ extraCopy .ExtDataGasUsed .SetBytes (h .ExtDataGasUsed .Bytes ())
83+ }
84+
85+ cpy := copyBaseHeader (header )
86+ return WithHeaderExtras (cpy , extraCopy )
87+ }
88+
89+ // TODO add test to make sure this mirrors copy with a no extra header.
90+ func copyBaseHeader (h * ethtypes.Header ) * ethtypes.Header {
91+ cpy := * h
92+ if cpy .Difficulty = new (big.Int ); h .Difficulty != nil {
93+ cpy .Difficulty .Set (h .Difficulty )
94+ }
95+ if cpy .Number = new (big.Int ); h .Number != nil {
96+ cpy .Number .Set (h .Number )
97+ }
98+ if h .BaseFee != nil {
99+ cpy .BaseFee = new (big.Int ).Set (h .BaseFee )
100+ }
101+ if len (h .Extra ) > 0 {
102+ cpy .Extra = make ([]byte , len (h .Extra ))
103+ copy (cpy .Extra , h .Extra )
104+ }
105+ if h .WithdrawalsHash != nil {
106+ cpy .WithdrawalsHash = new (common.Hash )
107+ * cpy .WithdrawalsHash = * h .WithdrawalsHash
108+ }
109+ if h .ExcessBlobGas != nil {
110+ cpy .ExcessBlobGas = new (uint64 )
111+ * cpy .ExcessBlobGas = * h .ExcessBlobGas
112+ }
113+ if h .BlobGasUsed != nil {
114+ cpy .BlobGasUsed = new (uint64 )
115+ * cpy .BlobGasUsed = * h .BlobGasUsed
116+ }
117+ if h .ParentBeaconRoot != nil {
118+ cpy .ParentBeaconRoot = new (common.Hash )
119+ * cpy .ParentBeaconRoot = * h .ParentBeaconRoot
120+ }
121+ return & cpy
122+ }
123+
70124//go:generate go run github.com/fjl/gencodec -type HeaderSerializable -field-override headerMarshaling -out gen_header_json.go
71125//go:generate go run github.com/ava-labs/libevm/rlp/rlpgen -type HeaderSerializable -out gen_header_rlp.go
72126
0 commit comments