@@ -5,11 +5,13 @@ import (
5
5
"fmt"
6
6
"math/big"
7
7
"reflect"
8
+ "strconv"
8
9
9
10
"github.com/ethereum/go-ethereum/beacon/engine"
10
11
"github.com/ethereum/go-ethereum/common"
11
12
"github.com/ethereum/go-ethereum/common/hexutil"
12
13
"github.com/ethereum/go-ethereum/core/types"
14
+ "github.com/ethereum/go-ethereum/rlp"
13
15
"github.com/ethereum/go-ethereum/trie"
14
16
"github.com/holiman/uint256"
15
17
)
@@ -142,8 +144,7 @@ type ExecutionPayload struct {
142
144
ExtraData BytesMax32 `json:"extraData"`
143
145
BaseFeePerGas Uint256Quantity `json:"baseFeePerGas"`
144
146
BlockHash common.Hash `json:"blockHash"`
145
- // nil if not present, pre-shanghai
146
- Withdrawals * types.Withdrawals `json:"withdrawals,omitempty"`
147
+ Withdrawals * Withdrawals `json:"withdrawals,omitempty"`
147
148
// Array of transaction objects, each object is a byte list (DATA) representing
148
149
// TransactionType || TransactionPayload or LegacyTransaction as defined in EIP-2718
149
150
Transactions []Data `json:"transactions"`
@@ -237,7 +238,7 @@ func BlockAsPayload(bl *types.Block, canyonForkTime *uint64) (*ExecutionPayload,
237
238
}
238
239
239
240
if canyonForkTime != nil && uint64 (payload .Timestamp ) >= * canyonForkTime {
240
- payload .Withdrawals = & types. Withdrawals {}
241
+ payload .Withdrawals = & Withdrawals {}
241
242
}
242
243
243
244
return payload , nil
@@ -251,7 +252,7 @@ type PayloadAttributes struct {
251
252
// suggested value for the coinbase field of the new payload
252
253
SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient"`
253
254
// Withdrawals to include into the block -- should be nil or empty depending on Shanghai enablement
254
- Withdrawals * types. Withdrawals `json:"withdrawals,omitempty"`
255
+ Withdrawals * Withdrawals `json:"withdrawals,omitempty"`
255
256
// Transactions to force into the block (always at the start of the transactions list).
256
257
Transactions []Data `json:"transactions,omitempty"`
257
258
// NoTxPool to disable adding any transactions from the transaction-pool.
@@ -317,3 +318,65 @@ type SystemConfig struct {
317
318
GasLimit uint64 `json:"gasLimit"`
318
319
// More fields can be added for future SystemConfig versions.
319
320
}
321
+
322
+ // Withdrawal represents a validator withdrawal from the consensus layer.
323
+ // https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#withdrawal
324
+ type Withdrawal struct {
325
+ Index uint64 `json:"index"` // monotonically increasing identifier issued by consensus layer
326
+ Validator uint64 `json:"validatorIndex"` // index of validator associated with withdrawal
327
+ Address common.Address `json:"address"` // target address for withdrawn ether
328
+ Amount uint64 `json:"amount"` // value of withdrawal in Gwei
329
+ }
330
+
331
+ // Withdrawals implements DerivableList for withdrawals.
332
+ type Withdrawals []Withdrawal
333
+
334
+ // Len returns the length of s.
335
+ func (s Withdrawals ) Len () int { return len (s ) }
336
+
337
+ // EncodeIndex encodes the i'th withdrawal to w. Note that this does not check for errors
338
+ // because we assume that *Withdrawal will only ever contain valid withdrawals that were either
339
+ // constructed by decoding or via public API in this package.
340
+ func (s Withdrawals ) EncodeIndex (i int , w * bytes.Buffer ) {
341
+ _ = rlp .Encode (w , s [i ])
342
+ }
343
+
344
+ type Bytes48 [48 ]byte
345
+
346
+ func (b * Bytes48 ) UnmarshalJSON (text []byte ) error {
347
+ return hexutil .UnmarshalFixedJSON (reflect .TypeOf (b ), text , b [:])
348
+ }
349
+
350
+ func (b * Bytes48 ) UnmarshalText (text []byte ) error {
351
+ return hexutil .UnmarshalFixedText ("Bytes32" , text , b [:])
352
+ }
353
+
354
+ func (b Bytes48 ) MarshalText () ([]byte , error ) {
355
+ return hexutil .Bytes (b [:]).MarshalText ()
356
+ }
357
+
358
+ func (b Bytes48 ) String () string {
359
+ return hexutil .Encode (b [:])
360
+ }
361
+
362
+ // TerminalString implements log.TerminalStringer, formatting a string for console
363
+ // output during logging.
364
+ func (b Bytes48 ) TerminalString () string {
365
+ return fmt .Sprintf ("%x..%x" , b [:3 ], b [45 :])
366
+ }
367
+
368
+ type Uint64String uint64
369
+
370
+ func (v Uint64String ) MarshalText () (out []byte , err error ) {
371
+ out = strconv .AppendUint (out , uint64 (v ), 10 )
372
+ return
373
+ }
374
+
375
+ func (v * Uint64String ) UnmarshalText (b []byte ) error {
376
+ n , err := strconv .ParseUint (string (b ), 0 , 64 )
377
+ if err != nil {
378
+ return err
379
+ }
380
+ * v = Uint64String (n )
381
+ return nil
382
+ }
0 commit comments