github.com/theQRL/go-zond@v0.1.1/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/theQRL/go-zond/common"
    11  	"github.com/theQRL/go-zond/common/hexutil"
    12  	"github.com/theQRL/go-zond/common/math"
    13  	"github.com/theQRL/go-zond/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  		WithdrawalsHash *common.Hash          `json:"withdrawalsRoot" rlp:"optional"`
    38  	}
    39  	var enc header
    40  	enc.ParentHash = h.ParentHash
    41  	enc.OmmerHash = h.OmmerHash
    42  	enc.Coinbase = h.Coinbase
    43  	enc.Root = h.Root
    44  	enc.TxHash = h.TxHash
    45  	enc.ReceiptHash = h.ReceiptHash
    46  	enc.Bloom = h.Bloom
    47  	enc.Difficulty = (*math.HexOrDecimal256)(h.Difficulty)
    48  	enc.Number = (*math.HexOrDecimal256)(h.Number)
    49  	enc.GasLimit = math.HexOrDecimal64(h.GasLimit)
    50  	enc.GasUsed = math.HexOrDecimal64(h.GasUsed)
    51  	enc.Time = math.HexOrDecimal64(h.Time)
    52  	enc.Extra = h.Extra
    53  	enc.MixDigest = h.MixDigest
    54  	enc.Nonce = h.Nonce
    55  	enc.BaseFee = (*math.HexOrDecimal256)(h.BaseFee)
    56  	enc.WithdrawalsHash = h.WithdrawalsHash
    57  	return json.Marshal(&enc)
    58  }
    59  
    60  // UnmarshalJSON unmarshals from JSON.
    61  func (h *header) UnmarshalJSON(input []byte) error {
    62  	type header struct {
    63  		ParentHash      *common.Hash          `json:"parentHash"`
    64  		OmmerHash       *common.Hash          `json:"sha3Uncles"`
    65  		Coinbase        *common.Address       `json:"miner"`
    66  		Root            *common.Hash          `json:"stateRoot"        gencodec:"required"`
    67  		TxHash          *common.Hash          `json:"transactionsRoot"`
    68  		ReceiptHash     *common.Hash          `json:"receiptsRoot"`
    69  		Bloom           *types.Bloom          `json:"logsBloom"`
    70  		Difficulty      *math.HexOrDecimal256 `json:"difficulty"`
    71  		Number          *math.HexOrDecimal256 `json:"number"           gencodec:"required"`
    72  		GasLimit        *math.HexOrDecimal64  `json:"gasLimit"         gencodec:"required"`
    73  		GasUsed         *math.HexOrDecimal64  `json:"gasUsed"`
    74  		Time            *math.HexOrDecimal64  `json:"timestamp"        gencodec:"required"`
    75  		Extra           *hexutil.Bytes        `json:"extraData"`
    76  		MixDigest       *common.Hash          `json:"mixHash"`
    77  		Nonce           *types.BlockNonce     `json:"nonce"`
    78  		BaseFee         *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"`
    79  		WithdrawalsHash *common.Hash          `json:"withdrawalsRoot" rlp:"optional"`
    80  	}
    81  	var dec header
    82  	if err := json.Unmarshal(input, &dec); err != nil {
    83  		return err
    84  	}
    85  	if dec.ParentHash != nil {
    86  		h.ParentHash = *dec.ParentHash
    87  	}
    88  	if dec.OmmerHash != nil {
    89  		h.OmmerHash = dec.OmmerHash
    90  	}
    91  	if dec.Coinbase != nil {
    92  		h.Coinbase = dec.Coinbase
    93  	}
    94  	if dec.Root == nil {
    95  		return errors.New("missing required field 'stateRoot' for header")
    96  	}
    97  	h.Root = *dec.Root
    98  	if dec.TxHash != nil {
    99  		h.TxHash = dec.TxHash
   100  	}
   101  	if dec.ReceiptHash != nil {
   102  		h.ReceiptHash = dec.ReceiptHash
   103  	}
   104  	if dec.Bloom != nil {
   105  		h.Bloom = *dec.Bloom
   106  	}
   107  	if dec.Difficulty != nil {
   108  		h.Difficulty = (*big.Int)(dec.Difficulty)
   109  	}
   110  	if dec.Number == nil {
   111  		return errors.New("missing required field 'number' for header")
   112  	}
   113  	h.Number = (*big.Int)(dec.Number)
   114  	if dec.GasLimit == nil {
   115  		return errors.New("missing required field 'gasLimit' for header")
   116  	}
   117  	h.GasLimit = uint64(*dec.GasLimit)
   118  	if dec.GasUsed != nil {
   119  		h.GasUsed = uint64(*dec.GasUsed)
   120  	}
   121  	if dec.Time == nil {
   122  		return errors.New("missing required field 'timestamp' for header")
   123  	}
   124  	h.Time = uint64(*dec.Time)
   125  	if dec.Extra != nil {
   126  		h.Extra = *dec.Extra
   127  	}
   128  	if dec.MixDigest != nil {
   129  		h.MixDigest = *dec.MixDigest
   130  	}
   131  	if dec.Nonce != nil {
   132  		h.Nonce = dec.Nonce
   133  	}
   134  	if dec.BaseFee != nil {
   135  		h.BaseFee = (*big.Int)(dec.BaseFee)
   136  	}
   137  	if dec.WithdrawalsHash != nil {
   138  		h.WithdrawalsHash = dec.WithdrawalsHash
   139  	}
   140  	return nil
   141  }