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