github.com/ethereum/go-ethereum@v1.14.3/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/ethereum/go-ethereum/common"
    10  	"github.com/ethereum/go-ethereum/common/hexutil"
    11  	"github.com/ethereum/go-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  		BeaconRoot            *common.Hash        `json:"parentBeaconBlockRoot"`
    24  	}
    25  	var enc PayloadAttributes
    26  	enc.Timestamp = hexutil.Uint64(p.Timestamp)
    27  	enc.Random = p.Random
    28  	enc.SuggestedFeeRecipient = p.SuggestedFeeRecipient
    29  	enc.Withdrawals = p.Withdrawals
    30  	enc.BeaconRoot = p.BeaconRoot
    31  	return json.Marshal(&enc)
    32  }
    33  
    34  // UnmarshalJSON unmarshals from JSON.
    35  func (p *PayloadAttributes) UnmarshalJSON(input []byte) error {
    36  	type PayloadAttributes struct {
    37  		Timestamp             *hexutil.Uint64     `json:"timestamp"             gencodec:"required"`
    38  		Random                *common.Hash        `json:"prevRandao"            gencodec:"required"`
    39  		SuggestedFeeRecipient *common.Address     `json:"suggestedFeeRecipient" gencodec:"required"`
    40  		Withdrawals           []*types.Withdrawal `json:"withdrawals"`
    41  		BeaconRoot            *common.Hash        `json:"parentBeaconBlockRoot"`
    42  	}
    43  	var dec PayloadAttributes
    44  	if err := json.Unmarshal(input, &dec); err != nil {
    45  		return err
    46  	}
    47  	if dec.Timestamp == nil {
    48  		return errors.New("missing required field 'timestamp' for PayloadAttributes")
    49  	}
    50  	p.Timestamp = uint64(*dec.Timestamp)
    51  	if dec.Random == nil {
    52  		return errors.New("missing required field 'prevRandao' for PayloadAttributes")
    53  	}
    54  	p.Random = *dec.Random
    55  	if dec.SuggestedFeeRecipient == nil {
    56  		return errors.New("missing required field 'suggestedFeeRecipient' for PayloadAttributes")
    57  	}
    58  	p.SuggestedFeeRecipient = *dec.SuggestedFeeRecipient
    59  	if dec.Withdrawals != nil {
    60  		p.Withdrawals = dec.Withdrawals
    61  	}
    62  	if dec.BeaconRoot != nil {
    63  		p.BeaconRoot = dec.BeaconRoot
    64  	}
    65  	return nil
    66  }