github.com/shrimpyuk/bor@v0.2.15-0.20220224151350-fb4ec6020bae/cmd/evm/internal/t8ntool/gen_stenv.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/math"
    12  )
    13  
    14  var _ = (*stEnvMarshaling)(nil)
    15  
    16  // MarshalJSON marshals as JSON.
    17  func (s stEnv) MarshalJSON() ([]byte, error) {
    18  	type stEnv struct {
    19  		Coinbase         common.UnprefixedAddress            `json:"currentCoinbase"   gencodec:"required"`
    20  		Difficulty       *math.HexOrDecimal256               `json:"currentDifficulty"`
    21  		ParentDifficulty *math.HexOrDecimal256               `json:"parentDifficulty"`
    22  		GasLimit         math.HexOrDecimal64                 `json:"currentGasLimit"   gencodec:"required"`
    23  		Number           math.HexOrDecimal64                 `json:"currentNumber"     gencodec:"required"`
    24  		Timestamp        math.HexOrDecimal64                 `json:"currentTimestamp"  gencodec:"required"`
    25  		ParentTimestamp  math.HexOrDecimal64                 `json:"parentTimestamp,omitempty"`
    26  		BlockHashes      map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
    27  		Ommers           []ommer                             `json:"ommers,omitempty"`
    28  		BaseFee          *math.HexOrDecimal256               `json:"currentBaseFee,omitempty"`
    29  		ParentUncleHash  common.Hash                         `json:"parentUncleHash"`
    30  	}
    31  	var enc stEnv
    32  	enc.Coinbase = common.UnprefixedAddress(s.Coinbase)
    33  	enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty)
    34  	enc.ParentDifficulty = (*math.HexOrDecimal256)(s.ParentDifficulty)
    35  	enc.GasLimit = math.HexOrDecimal64(s.GasLimit)
    36  	enc.Number = math.HexOrDecimal64(s.Number)
    37  	enc.Timestamp = math.HexOrDecimal64(s.Timestamp)
    38  	enc.ParentTimestamp = math.HexOrDecimal64(s.ParentTimestamp)
    39  	enc.BlockHashes = s.BlockHashes
    40  	enc.Ommers = s.Ommers
    41  	enc.BaseFee = (*math.HexOrDecimal256)(s.BaseFee)
    42  	enc.ParentUncleHash = s.ParentUncleHash
    43  	return json.Marshal(&enc)
    44  }
    45  
    46  // UnmarshalJSON unmarshals from JSON.
    47  func (s *stEnv) UnmarshalJSON(input []byte) error {
    48  	type stEnv struct {
    49  		Coinbase         *common.UnprefixedAddress           `json:"currentCoinbase"   gencodec:"required"`
    50  		Difficulty       *math.HexOrDecimal256               `json:"currentDifficulty"`
    51  		ParentDifficulty *math.HexOrDecimal256               `json:"parentDifficulty"`
    52  		GasLimit         *math.HexOrDecimal64                `json:"currentGasLimit"   gencodec:"required"`
    53  		Number           *math.HexOrDecimal64                `json:"currentNumber"     gencodec:"required"`
    54  		Timestamp        *math.HexOrDecimal64                `json:"currentTimestamp"  gencodec:"required"`
    55  		ParentTimestamp  *math.HexOrDecimal64                `json:"parentTimestamp,omitempty"`
    56  		BlockHashes      map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
    57  		Ommers           []ommer                             `json:"ommers,omitempty"`
    58  		BaseFee          *math.HexOrDecimal256               `json:"currentBaseFee,omitempty"`
    59  		ParentUncleHash  *common.Hash                        `json:"parentUncleHash"`
    60  	}
    61  	var dec stEnv
    62  	if err := json.Unmarshal(input, &dec); err != nil {
    63  		return err
    64  	}
    65  	if dec.Coinbase == nil {
    66  		return errors.New("missing required field 'currentCoinbase' for stEnv")
    67  	}
    68  	s.Coinbase = common.Address(*dec.Coinbase)
    69  	if dec.Difficulty != nil {
    70  		s.Difficulty = (*big.Int)(dec.Difficulty)
    71  	}
    72  	if dec.ParentDifficulty != nil {
    73  		s.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
    74  	}
    75  	if dec.GasLimit == nil {
    76  		return errors.New("missing required field 'currentGasLimit' for stEnv")
    77  	}
    78  	s.GasLimit = uint64(*dec.GasLimit)
    79  	if dec.Number == nil {
    80  		return errors.New("missing required field 'currentNumber' for stEnv")
    81  	}
    82  	s.Number = uint64(*dec.Number)
    83  	if dec.Timestamp == nil {
    84  		return errors.New("missing required field 'currentTimestamp' for stEnv")
    85  	}
    86  	s.Timestamp = uint64(*dec.Timestamp)
    87  	if dec.ParentTimestamp != nil {
    88  		s.ParentTimestamp = uint64(*dec.ParentTimestamp)
    89  	}
    90  	if dec.BlockHashes != nil {
    91  		s.BlockHashes = dec.BlockHashes
    92  	}
    93  	if dec.Ommers != nil {
    94  		s.Ommers = dec.Ommers
    95  	}
    96  	if dec.BaseFee != nil {
    97  		s.BaseFee = (*big.Int)(dec.BaseFee)
    98  	}
    99  	if dec.ParentUncleHash != nil {
   100  		s.ParentUncleHash = *dec.ParentUncleHash
   101  	}
   102  	return nil
   103  }