github.com/theQRL/go-zond@v0.2.1/cmd/zvm/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  		Coinbase        *common.Address       `json:"miner"`
    23  		Root            common.Hash           `json:"stateRoot"        gencodec:"required"`
    24  		TxHash          *common.Hash          `json:"transactionsRoot"`
    25  		ReceiptHash     *common.Hash          `json:"receiptsRoot"`
    26  		Bloom           types.Bloom           `json:"logsBloom"`
    27  		Number          *math.HexOrDecimal256 `json:"number"           gencodec:"required"`
    28  		GasLimit        math.HexOrDecimal64   `json:"gasLimit"         gencodec:"required"`
    29  		GasUsed         math.HexOrDecimal64   `json:"gasUsed"`
    30  		Time            math.HexOrDecimal64   `json:"timestamp"        gencodec:"required"`
    31  		Extra           hexutil.Bytes         `json:"extraData"`
    32  		Random       common.Hash           `json:"prevRandao"`
    33  		BaseFee         *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"`
    34  		WithdrawalsHash *common.Hash          `json:"withdrawalsRoot" rlp:"optional"`
    35  	}
    36  	var enc header
    37  	enc.ParentHash = h.ParentHash
    38  	enc.Coinbase = h.Coinbase
    39  	enc.Root = h.Root
    40  	enc.TxHash = h.TxHash
    41  	enc.ReceiptHash = h.ReceiptHash
    42  	enc.Bloom = h.Bloom
    43  	enc.Number = (*math.HexOrDecimal256)(h.Number)
    44  	enc.GasLimit = math.HexOrDecimal64(h.GasLimit)
    45  	enc.GasUsed = math.HexOrDecimal64(h.GasUsed)
    46  	enc.Time = math.HexOrDecimal64(h.Time)
    47  	enc.Extra = h.Extra
    48  	enc.Random = h.Random
    49  	enc.BaseFee = (*math.HexOrDecimal256)(h.BaseFee)
    50  	enc.WithdrawalsHash = h.WithdrawalsHash
    51  	return json.Marshal(&enc)
    52  }
    53  
    54  // UnmarshalJSON unmarshals from JSON.
    55  func (h *header) UnmarshalJSON(input []byte) error {
    56  	type header struct {
    57  		ParentHash      *common.Hash          `json:"parentHash"`
    58  		Coinbase        *common.Address       `json:"miner"`
    59  		Root            *common.Hash          `json:"stateRoot"        gencodec:"required"`
    60  		TxHash          *common.Hash          `json:"transactionsRoot"`
    61  		ReceiptHash     *common.Hash          `json:"receiptsRoot"`
    62  		Bloom           *types.Bloom          `json:"logsBloom"`
    63  		Number          *math.HexOrDecimal256 `json:"number"           gencodec:"required"`
    64  		GasLimit        *math.HexOrDecimal64  `json:"gasLimit"         gencodec:"required"`
    65  		GasUsed         *math.HexOrDecimal64  `json:"gasUsed"`
    66  		Time            *math.HexOrDecimal64  `json:"timestamp"        gencodec:"required"`
    67  		Extra           *hexutil.Bytes        `json:"extraData"`
    68  		Random       *common.Hash          `json:"prevRandao"`
    69  		BaseFee         *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"`
    70  		WithdrawalsHash *common.Hash          `json:"withdrawalsRoot" rlp:"optional"`
    71  	}
    72  	var dec header
    73  	if err := json.Unmarshal(input, &dec); err != nil {
    74  		return err
    75  	}
    76  	if dec.ParentHash != nil {
    77  		h.ParentHash = *dec.ParentHash
    78  	}
    79  	if dec.Coinbase != nil {
    80  		h.Coinbase = dec.Coinbase
    81  	}
    82  	if dec.Root == nil {
    83  		return errors.New("missing required field 'stateRoot' for header")
    84  	}
    85  	h.Root = *dec.Root
    86  	if dec.TxHash != nil {
    87  		h.TxHash = dec.TxHash
    88  	}
    89  	if dec.ReceiptHash != nil {
    90  		h.ReceiptHash = dec.ReceiptHash
    91  	}
    92  	if dec.Bloom != nil {
    93  		h.Bloom = *dec.Bloom
    94  	}
    95  	if dec.Number == nil {
    96  		return errors.New("missing required field 'number' for header")
    97  	}
    98  	h.Number = (*big.Int)(dec.Number)
    99  	if dec.GasLimit == nil {
   100  		return errors.New("missing required field 'gasLimit' for header")
   101  	}
   102  	h.GasLimit = uint64(*dec.GasLimit)
   103  	if dec.GasUsed != nil {
   104  		h.GasUsed = uint64(*dec.GasUsed)
   105  	}
   106  	if dec.Time == nil {
   107  		return errors.New("missing required field 'timestamp' for header")
   108  	}
   109  	h.Time = uint64(*dec.Time)
   110  	if dec.Extra != nil {
   111  		h.Extra = *dec.Extra
   112  	}
   113  	if dec.Random != nil {
   114  		h.Random = *dec.Random
   115  	}
   116  	if dec.BaseFee != nil {
   117  		h.BaseFee = (*big.Int)(dec.BaseFee)
   118  	}
   119  	if dec.WithdrawalsHash != nil {
   120  		h.WithdrawalsHash = dec.WithdrawalsHash
   121  	}
   122  	return nil
   123  }