|
| 1 | +package cltypes |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/erigontech/erigon/cl/merkle_tree" |
| 5 | + ssz2 "github.com/erigontech/erigon/cl/ssz" |
| 6 | + "github.com/erigontech/erigon/common" |
| 7 | + "github.com/erigontech/erigon/common/clonable" |
| 8 | + "github.com/erigontech/erigon/common/length" |
| 9 | + "github.com/erigontech/erigon/common/ssz" |
| 10 | +) |
| 11 | + |
| 12 | +type BuilderIndex uint64 |
| 13 | + |
| 14 | +var ( |
| 15 | + _ ssz.HashableSSZ = (*Builder)(nil) |
| 16 | + _ ssz.HashableSSZ = (*BuilderPendingWithdrawal)(nil) |
| 17 | + _ ssz.HashableSSZ = (*BuilderPendingPayment)(nil) |
| 18 | + |
| 19 | + _ ssz2.SizedObjectSSZ = (*Builder)(nil) |
| 20 | + _ ssz2.SizedObjectSSZ = (*BuilderPendingWithdrawal)(nil) |
| 21 | + _ ssz2.SizedObjectSSZ = (*BuilderPendingPayment)(nil) |
| 22 | +) |
| 23 | + |
| 24 | +// Builder represents a builder in the consensus layer. |
| 25 | +type Builder struct { |
| 26 | + Pubkey common.Bytes48 `json:"pubkey"` |
| 27 | + Version uint8 `json:"version"` |
| 28 | + ExecutionAddress common.Address `json:"execution_address"` |
| 29 | + Balance uint64 `json:"balance"` |
| 30 | + DepositEpoch uint64 `json:"deposit_epoch"` |
| 31 | + WithdrawableEpoch uint64 `json:"withdrawable_epoch"` |
| 32 | +} |
| 33 | + |
| 34 | +func (b *Builder) EncodingSizeSSZ() int { |
| 35 | + return length.Bytes48 + 1 + length.Addr + 8 + 8 + 8 |
| 36 | +} |
| 37 | + |
| 38 | +func (b *Builder) Static() bool { |
| 39 | + return true |
| 40 | +} |
| 41 | + |
| 42 | +func (b *Builder) EncodeSSZ(buf []byte) ([]byte, error) { |
| 43 | + return ssz2.MarshalSSZ(buf, b.Pubkey[:], b.Version, b.ExecutionAddress[:], b.Balance, b.DepositEpoch, b.WithdrawableEpoch) |
| 44 | +} |
| 45 | + |
| 46 | +func (b *Builder) DecodeSSZ(buf []byte, version int) error { |
| 47 | + return ssz2.UnmarshalSSZ(buf, version, b.Pubkey[:], &b.Version, b.ExecutionAddress[:], &b.Balance, &b.DepositEpoch, &b.WithdrawableEpoch) |
| 48 | +} |
| 49 | + |
| 50 | +func (b *Builder) Clone() clonable.Clonable { |
| 51 | + return &Builder{} |
| 52 | +} |
| 53 | + |
| 54 | +func (b *Builder) HashSSZ() ([32]byte, error) { |
| 55 | + return merkle_tree.HashTreeRoot(b.Pubkey[:], uint64(b.Version), b.ExecutionAddress[:], b.Balance, b.DepositEpoch, b.WithdrawableEpoch) |
| 56 | +} |
| 57 | + |
| 58 | +// BuilderPendingWithdrawal represents a pending withdrawal for a builder. |
| 59 | +type BuilderPendingWithdrawal struct { |
| 60 | + FeeRecipient common.Address `json:"fee_recipient"` |
| 61 | + Amount uint64 `json:"amount"` |
| 62 | + BuilderIndex BuilderIndex `json:"builder_index"` |
| 63 | +} |
| 64 | + |
| 65 | +func (b *BuilderPendingWithdrawal) EncodingSizeSSZ() int { |
| 66 | + return length.Addr + 8 + 8 |
| 67 | +} |
| 68 | + |
| 69 | +func (b *BuilderPendingWithdrawal) Static() bool { |
| 70 | + return true |
| 71 | +} |
| 72 | + |
| 73 | +func (b *BuilderPendingWithdrawal) EncodeSSZ(buf []byte) ([]byte, error) { |
| 74 | + return ssz2.MarshalSSZ(buf, b.FeeRecipient[:], b.Amount, b.BuilderIndex) |
| 75 | +} |
| 76 | + |
| 77 | +func (b *BuilderPendingWithdrawal) DecodeSSZ(buf []byte, version int) error { |
| 78 | + return ssz2.UnmarshalSSZ(buf, version, b.FeeRecipient[:], &b.Amount, &b.BuilderIndex) |
| 79 | +} |
| 80 | + |
| 81 | +func (b *BuilderPendingWithdrawal) Clone() clonable.Clonable { |
| 82 | + return &BuilderPendingWithdrawal{} |
| 83 | +} |
| 84 | + |
| 85 | +func (b *BuilderPendingWithdrawal) HashSSZ() ([32]byte, error) { |
| 86 | + return merkle_tree.HashTreeRoot(b.FeeRecipient[:], b.Amount, b.BuilderIndex) |
| 87 | +} |
| 88 | + |
| 89 | +// BuilderPendingPayment represents a pending payment for a builder. |
| 90 | +type BuilderPendingPayment struct { |
| 91 | + Weight uint64 `json:"weight"` |
| 92 | + Withdrawal *BuilderPendingWithdrawal `json:"withdrawal"` |
| 93 | +} |
| 94 | + |
| 95 | +func (b *BuilderPendingPayment) HashSSZ() ([32]byte, error) { |
| 96 | + return merkle_tree.HashTreeRoot(&b.Weight, b.Withdrawal) |
| 97 | +} |
| 98 | + |
| 99 | +func (b *BuilderPendingPayment) EncodingSizeSSZ() int { |
| 100 | + if b.Withdrawal == nil { |
| 101 | + return 8 |
| 102 | + } |
| 103 | + return 8 + b.Withdrawal.EncodingSizeSSZ() |
| 104 | +} |
| 105 | + |
| 106 | +func (b *BuilderPendingPayment) Static() bool { |
| 107 | + return true |
| 108 | +} |
| 109 | + |
| 110 | +func (b *BuilderPendingPayment) EncodeSSZ(buf []byte) ([]byte, error) { |
| 111 | + return ssz2.MarshalSSZ(buf, b.Weight, b.Withdrawal) |
| 112 | +} |
| 113 | + |
| 114 | +func (b *BuilderPendingPayment) DecodeSSZ(buf []byte, version int) error { |
| 115 | + b.Withdrawal = new(BuilderPendingWithdrawal) |
| 116 | + return ssz2.UnmarshalSSZ(buf, version, &b.Weight, b.Withdrawal) |
| 117 | +} |
| 118 | + |
| 119 | +func (b *BuilderPendingPayment) Clone() clonable.Clonable { |
| 120 | + return &BuilderPendingPayment{ |
| 121 | + Weight: b.Weight, |
| 122 | + Withdrawal: b.Withdrawal.Clone().(*BuilderPendingWithdrawal), |
| 123 | + } |
| 124 | +} |
0 commit comments