github.com/calmw/ethereum@v0.1.1/beacon/engine/gen_blockparams.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package engine 4 5 import ( 6 "encoding/json" 7 "errors" 8 9 "github.com/calmw/ethereum/common" 10 "github.com/calmw/ethereum/common/hexutil" 11 "github.com/calmw/ethereum/core/types" 12 ) 13 14 var _ = (*payloadAttributesMarshaling)(nil) 15 16 // MarshalJSON marshals as JSON. 17 func (p PayloadAttributes) MarshalJSON() ([]byte, error) { 18 type PayloadAttributes struct { 19 Timestamp hexutil.Uint64 `json:"timestamp" gencodec:"required"` 20 Random common.Hash `json:"prevRandao" gencodec:"required"` 21 SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"` 22 Withdrawals []*types.Withdrawal `json:"withdrawals"` 23 } 24 var enc PayloadAttributes 25 enc.Timestamp = hexutil.Uint64(p.Timestamp) 26 enc.Random = p.Random 27 enc.SuggestedFeeRecipient = p.SuggestedFeeRecipient 28 enc.Withdrawals = p.Withdrawals 29 return json.Marshal(&enc) 30 } 31 32 // UnmarshalJSON unmarshals from JSON. 33 func (p *PayloadAttributes) UnmarshalJSON(input []byte) error { 34 type PayloadAttributes struct { 35 Timestamp *hexutil.Uint64 `json:"timestamp" gencodec:"required"` 36 Random *common.Hash `json:"prevRandao" gencodec:"required"` 37 SuggestedFeeRecipient *common.Address `json:"suggestedFeeRecipient" gencodec:"required"` 38 Withdrawals []*types.Withdrawal `json:"withdrawals"` 39 } 40 var dec PayloadAttributes 41 if err := json.Unmarshal(input, &dec); err != nil { 42 return err 43 } 44 if dec.Timestamp == nil { 45 return errors.New("missing required field 'timestamp' for PayloadAttributes") 46 } 47 p.Timestamp = uint64(*dec.Timestamp) 48 if dec.Random == nil { 49 return errors.New("missing required field 'prevRandao' for PayloadAttributes") 50 } 51 p.Random = *dec.Random 52 if dec.SuggestedFeeRecipient == nil { 53 return errors.New("missing required field 'suggestedFeeRecipient' for PayloadAttributes") 54 } 55 p.SuggestedFeeRecipient = *dec.SuggestedFeeRecipient 56 if dec.Withdrawals != nil { 57 p.Withdrawals = dec.Withdrawals 58 } 59 return nil 60 }