github.com/jimmyx0x/go-ethereum@v1.10.28/cmd/evm/internal/t8ntool/gen_header.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package t8ntool
     4  
     5  import (
     6  	"encoding/json"
     7  	"errors"
     8  	"math/big"
     9  
    10  	"github.com/ethereum/go-ethereum/common"
    11  	"github.com/ethereum/go-ethereum/common/hexutil"
    12  	"github.com/ethereum/go-ethereum/common/math"
    13  	"github.com/ethereum/go-ethereum/core/types"
    14  )
    15  
    16  var _ = (*headerMarshaling)(nil)
    17  
    18  // MarshalJSON marshals as JSON.
    19  func (h header) MarshalJSON() ([]byte, error) {
    20  	type header struct {
    21  		ParentHash  common.Hash           `json:"parentHash"`
    22  		OmmerHash   *common.Hash          `json:"sha3Uncles"`
    23  		Coinbase    *common.Address       `json:"miner"`
    24  		Root        common.Hash           `json:"stateRoot"        gencodec:"required"`
    25  		TxHash      *common.Hash          `json:"transactionsRoot"`
    26  		ReceiptHash *common.Hash          `json:"receiptsRoot"`
    27  		Bloom       types.Bloom           `json:"logsBloom"`
    28  		Difficulty  *math.HexOrDecimal256 `json:"difficulty"`
    29  		Number      *math.HexOrDecimal256 `json:"number"           gencodec:"required"`
    30  		GasLimit    math.HexOrDecimal64   `json:"gasLimit"         gencodec:"required"`
    31  		GasUsed     math.HexOrDecimal64   `json:"gasUsed"`
    32  		Time        math.HexOrDecimal64   `json:"timestamp"        gencodec:"required"`
    33  		Extra       hexutil.Bytes         `json:"extraData"`
    34  		MixDigest   common.Hash           `json:"mixHash"`
    35  		Nonce       *types.BlockNonce     `json:"nonce"`
    36  		BaseFee     *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"`
    37  	}
    38  	var enc header
    39  	enc.ParentHash = h.ParentHash
    40  	enc.OmmerHash = h.OmmerHash
    41  	enc.Coinbase = h.Coinbase
    42  	enc.Root = h.Root
    43  	enc.TxHash = h.TxHash
    44  	enc.ReceiptHash = h.ReceiptHash
    45  	enc.Bloom = h.Bloom
    46  	enc.Difficulty = (*math.HexOrDecimal256)(h.Difficulty)
    47  	enc.Number = (*math.HexOrDecimal256)(h.Number)
    48  	enc.GasLimit = math.HexOrDecimal64(h.GasLimit)
    49  	enc.GasUsed = math.HexOrDecimal64(h.GasUsed)
    50  	enc.Time = math.HexOrDecimal64(h.Time)
    51  	enc.Extra = h.Extra
    52  	enc.MixDigest = h.MixDigest
    53  	enc.Nonce = h.Nonce
    54  	enc.BaseFee = (*math.HexOrDecimal256)(h.BaseFee)
    55  	return json.Marshal(&enc)
    56  }
    57  
    58  // UnmarshalJSON unmarshals from JSON.
    59  func (h *header) UnmarshalJSON(input []byte) error {
    60  	type header struct {
    61  		ParentHash  *common.Hash          `json:"parentHash"`
    62  		OmmerHash   *common.Hash          `json:"sha3Uncles"`
    63  		Coinbase    *common.Address       `json:"miner"`
    64  		Root        *common.Hash          `json:"stateRoot"        gencodec:"required"`
    65  		TxHash      *common.Hash          `json:"transactionsRoot"`
    66  		ReceiptHash *common.Hash          `json:"receiptsRoot"`
    67  		Bloom       *types.Bloom          `json:"logsBloom"`
    68  		Difficulty  *math.HexOrDecimal256 `json:"difficulty"`
    69  		Number      *math.HexOrDecimal256 `json:"number"           gencodec:"required"`
    70  		GasLimit    *math.HexOrDecimal64  `json:"gasLimit"         gencodec:"required"`
    71  		GasUsed     *math.HexOrDecimal64  `json:"gasUsed"`
    72  		Time        *math.HexOrDecimal64  `json:"timestamp"        gencodec:"required"`
    73  		Extra       *hexutil.Bytes        `json:"extraData"`
    74  		MixDigest   *common.Hash          `json:"mixHash"`
    75  		Nonce       *types.BlockNonce     `json:"nonce"`
    76  		BaseFee     *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"`
    77  	}
    78  	var dec header
    79  	if err := json.Unmarshal(input, &dec); err != nil {
    80  		return err
    81  	}
    82  	if dec.ParentHash != nil {
    83  		h.ParentHash = *dec.ParentHash
    84  	}
    85  	if dec.OmmerHash != nil {
    86  		h.OmmerHash = dec.OmmerHash
    87  	}
    88  	if dec.Coinbase != nil {
    89  		h.Coinbase = dec.Coinbase
    90  	}
    91  	if dec.Root == nil {
    92  		return errors.New("missing required field 'stateRoot' for header")
    93  	}
    94  	h.Root = *dec.Root
    95  	if dec.TxHash != nil {
    96  		h.TxHash = dec.TxHash
    97  	}
    98  	if dec.ReceiptHash != nil {
    99  		h.ReceiptHash = dec.ReceiptHash
   100  	}
   101  	if dec.Bloom != nil {
   102  		h.Bloom = *dec.Bloom
   103  	}
   104  	if dec.Difficulty != nil {
   105  		h.Difficulty = (*big.Int)(dec.Difficulty)
   106  	}
   107  	if dec.Number == nil {
   108  		return errors.New("missing required field 'number' for header")
   109  	}
   110  	h.Number = (*big.Int)(dec.Number)
   111  	if dec.GasLimit == nil {
   112  		return errors.New("missing required field 'gasLimit' for header")
   113  	}
   114  	h.GasLimit = uint64(*dec.GasLimit)
   115  	if dec.GasUsed != nil {
   116  		h.GasUsed = uint64(*dec.GasUsed)
   117  	}
   118  	if dec.Time == nil {
   119  		return errors.New("missing required field 'timestamp' for header")
   120  	}
   121  	h.Time = uint64(*dec.Time)
   122  	if dec.Extra != nil {
   123  		h.Extra = *dec.Extra
   124  	}
   125  	if dec.MixDigest != nil {
   126  		h.MixDigest = *dec.MixDigest
   127  	}
   128  	if dec.Nonce != nil {
   129  		h.Nonce = dec.Nonce
   130  	}
   131  	if dec.BaseFee != nil {
   132  		h.BaseFee = (*big.Int)(dec.BaseFee)
   133  	}
   134  	return nil
   135  }