github.com/core-coin/go-core/v2@v2.1.9/cmd/cvm/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/core-coin/go-core/v2/common" 11 "github.com/core-coin/go-core/v2/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:"required"` 21 EnergyLimit math.HexOrDecimal64 `json:"currentEnergyLimit" gencodec:"required"` 22 Number math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 23 Timestamp math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 24 BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"` 25 Ommers []ommer `json:"ommers,omitempty"` 26 } 27 var enc stEnv 28 enc.Coinbase = common.UnprefixedAddress(s.Coinbase) 29 enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty) 30 enc.EnergyLimit = math.HexOrDecimal64(s.EnergyLimit) 31 enc.Number = math.HexOrDecimal64(s.Number) 32 enc.Timestamp = math.HexOrDecimal64(s.Timestamp) 33 enc.BlockHashes = s.BlockHashes 34 enc.Ommers = s.Ommers 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:"required"` 43 EnergyLimit *math.HexOrDecimal64 `json:"currentEnergyLimit" gencodec:"required"` 44 Number *math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 45 Timestamp *math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 46 BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"` 47 Ommers []ommer `json:"ommers,omitempty"` 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 return errors.New("missing required field 'currentDifficulty' for stEnv") 59 } 60 s.Difficulty = (*big.Int)(dec.Difficulty) 61 if dec.EnergyLimit == nil { 62 return errors.New("missing required field 'currentEnergyLimit' for stEnv") 63 } 64 s.EnergyLimit = uint64(*dec.EnergyLimit) 65 if dec.Number == nil { 66 return errors.New("missing required field 'currentNumber' for stEnv") 67 } 68 s.Number = uint64(*dec.Number) 69 if dec.Timestamp == nil { 70 return errors.New("missing required field 'currentTimestamp' for stEnv") 71 } 72 s.Timestamp = uint64(*dec.Timestamp) 73 if dec.BlockHashes != nil { 74 s.BlockHashes = dec.BlockHashes 75 } 76 if dec.Ommers != nil { 77 s.Ommers = dec.Ommers 78 } 79 return nil 80 }