github.com/VietJr/bor@v1.0.3/core/beacon/gen_blockparams.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package beacon
     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  )
    12  
    13  var _ = (*payloadAttributesMarshaling)(nil)
    14  
    15  // MarshalJSON marshals as JSON.
    16  func (p PayloadAttributesV1) MarshalJSON() ([]byte, error) {
    17  	type PayloadAttributesV1 struct {
    18  		Timestamp             hexutil.Uint64 `json:"timestamp"     gencodec:"required"`
    19  		Random                common.Hash    `json:"prevRandao"        gencodec:"required"`
    20  		SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient"  gencodec:"required"`
    21  	}
    22  	var enc PayloadAttributesV1
    23  	enc.Timestamp = hexutil.Uint64(p.Timestamp)
    24  	enc.Random = p.Random
    25  	enc.SuggestedFeeRecipient = p.SuggestedFeeRecipient
    26  	return json.Marshal(&enc)
    27  }
    28  
    29  // UnmarshalJSON unmarshals from JSON.
    30  func (p *PayloadAttributesV1) UnmarshalJSON(input []byte) error {
    31  	type PayloadAttributesV1 struct {
    32  		Timestamp             *hexutil.Uint64 `json:"timestamp"     gencodec:"required"`
    33  		Random                *common.Hash    `json:"prevRandao"        gencodec:"required"`
    34  		SuggestedFeeRecipient *common.Address `json:"suggestedFeeRecipient"  gencodec:"required"`
    35  	}
    36  	var dec PayloadAttributesV1
    37  	if err := json.Unmarshal(input, &dec); err != nil {
    38  		return err
    39  	}
    40  	if dec.Timestamp == nil {
    41  		return errors.New("missing required field 'timestamp' for PayloadAttributesV1")
    42  	}
    43  	p.Timestamp = uint64(*dec.Timestamp)
    44  	if dec.Random == nil {
    45  		return errors.New("missing required field 'prevRandao' for PayloadAttributesV1")
    46  	}
    47  	p.Random = *dec.Random
    48  	if dec.SuggestedFeeRecipient == nil {
    49  		return errors.New("missing required field 'suggestedFeeRecipient' for PayloadAttributesV1")
    50  	}
    51  	p.SuggestedFeeRecipient = *dec.SuggestedFeeRecipient
    52  	return nil
    53  }