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