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