gen_header.go 4.4 KB

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