github.com/palisadeinc/bor@v0.0.0-20230615125219-ab7196213d15/tests/gen_stenv.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package tests
     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" gencodec:"optional"`
    21  		Random     *math.HexOrDecimal256    `json:"currentRandom" gencodec:"optional"`
    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  		BaseFee    *math.HexOrDecimal256    `json:"currentBaseFee"  gencodec:"optional"`
    26  	}
    27  	var enc stEnv
    28  	enc.Coinbase = common.UnprefixedAddress(s.Coinbase)
    29  	enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty)
    30  	enc.Random = (*math.HexOrDecimal256)(s.Random)
    31  	enc.GasLimit = math.HexOrDecimal64(s.GasLimit)
    32  	enc.Number = math.HexOrDecimal64(s.Number)
    33  	enc.Timestamp = math.HexOrDecimal64(s.Timestamp)
    34  	enc.BaseFee = (*math.HexOrDecimal256)(s.BaseFee)
    35  	return json.Marshal(&enc)
    36  }
    37  
    38  // UnmarshalJSON unmarshals from JSON.
    39  func (s *stEnv) UnmarshalJSON(input []byte) error {
    40  	type stEnv struct {
    41  		Coinbase   *common.UnprefixedAddress `json:"currentCoinbase"   gencodec:"required"`
    42  		Difficulty *math.HexOrDecimal256     `json:"currentDifficulty" gencodec:"optional"`
    43  		Random     *math.HexOrDecimal256     `json:"currentRandom" gencodec:"optional"`
    44  		GasLimit   *math.HexOrDecimal64      `json:"currentGasLimit"   gencodec:"required"`
    45  		Number     *math.HexOrDecimal64      `json:"currentNumber"     gencodec:"required"`
    46  		Timestamp  *math.HexOrDecimal64      `json:"currentTimestamp"  gencodec:"required"`
    47  		BaseFee    *math.HexOrDecimal256     `json:"currentBaseFee"  gencodec:"optional"`
    48  	}
    49  	var dec stEnv
    50  	if err := json.Unmarshal(input, &dec); err != nil {
    51  		return err
    52  	}
    53  	if dec.Coinbase == nil {
    54  		return errors.New("missing required field 'currentCoinbase' for stEnv")
    55  	}
    56  	s.Coinbase = common.Address(*dec.Coinbase)
    57  	if dec.Difficulty != nil {
    58  		s.Difficulty = (*big.Int)(dec.Difficulty)
    59  	}
    60  	if dec.Random != nil {
    61  		s.Random = (*big.Int)(dec.Random)
    62  	}
    63  	if dec.GasLimit == nil {
    64  		return errors.New("missing required field 'currentGasLimit' for stEnv")
    65  	}
    66  	s.GasLimit = uint64(*dec.GasLimit)
    67  	if dec.Number == nil {
    68  		return errors.New("missing required field 'currentNumber' for stEnv")
    69  	}
    70  	s.Number = uint64(*dec.Number)
    71  	if dec.Timestamp == nil {
    72  		return errors.New("missing required field 'currentTimestamp' for stEnv")
    73  	}
    74  	s.Timestamp = uint64(*dec.Timestamp)
    75  	if dec.BaseFee != nil {
    76  		s.BaseFee = (*big.Int)(dec.BaseFee)
    77  	}
    78  	return nil
    79  }