github.com/core-coin/go-core/v2@v2.1.9/tests/gen_vmexec.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/core-coin/go-core/v2/common" 11 "github.com/core-coin/go-core/v2/common/hexutil" 12 "github.com/core-coin/go-core/v2/common/math" 13 ) 14 15 var _ = (*vmExecMarshaling)(nil) 16 17 // MarshalJSON marshals as JSON. 18 func (v vmExec) MarshalJSON() ([]byte, error) { 19 type vmExec struct { 20 Address common.UnprefixedAddress `json:"address" gencodec:"required"` 21 Caller common.UnprefixedAddress `json:"caller" gencodec:"required"` 22 Origin common.UnprefixedAddress `json:"origin" gencodec:"required"` 23 Code hexutil.Bytes `json:"code" gencodec:"required"` 24 Data hexutil.Bytes `json:"data" gencodec:"required"` 25 Value *math.HexOrDecimal256 `json:"value" gencodec:"required"` 26 EnergyLimit math.HexOrDecimal64 `json:"energy" gencodec:"required"` 27 EnergyPrice *math.HexOrDecimal256 `json:"energyPrice" gencodec:"required"` 28 } 29 var enc vmExec 30 enc.Address = common.UnprefixedAddress(v.Address) 31 enc.Caller = common.UnprefixedAddress(v.Caller) 32 enc.Origin = common.UnprefixedAddress(v.Origin) 33 enc.Code = v.Code 34 enc.Data = v.Data 35 enc.Value = (*math.HexOrDecimal256)(v.Value) 36 enc.EnergyLimit = math.HexOrDecimal64(v.EnergyLimit) 37 enc.EnergyPrice = (*math.HexOrDecimal256)(v.EnergyPrice) 38 return json.Marshal(&enc) 39 } 40 41 // UnmarshalJSON unmarshals from JSON. 42 func (v *vmExec) UnmarshalJSON(input []byte) error { 43 type vmExec struct { 44 Address *common.UnprefixedAddress `json:"address" gencodec:"required"` 45 Caller *common.UnprefixedAddress `json:"caller" gencodec:"required"` 46 Origin *common.UnprefixedAddress `json:"origin" gencodec:"required"` 47 Code *hexutil.Bytes `json:"code" gencodec:"required"` 48 Data *hexutil.Bytes `json:"data" gencodec:"required"` 49 Value *math.HexOrDecimal256 `json:"value" gencodec:"required"` 50 EnergyLimit *math.HexOrDecimal64 `json:"energy" gencodec:"required"` 51 EnergyPrice *math.HexOrDecimal256 `json:"energyPrice" gencodec:"required"` 52 } 53 var dec vmExec 54 if err := json.Unmarshal(input, &dec); err != nil { 55 return err 56 } 57 if dec.Address == nil { 58 return errors.New("missing required field 'address' for vmExec") 59 } 60 v.Address = common.Address(*dec.Address) 61 if dec.Caller == nil { 62 return errors.New("missing required field 'caller' for vmExec") 63 } 64 v.Caller = common.Address(*dec.Caller) 65 if dec.Origin == nil { 66 return errors.New("missing required field 'origin' for vmExec") 67 } 68 v.Origin = common.Address(*dec.Origin) 69 if dec.Code == nil { 70 return errors.New("missing required field 'code' for vmExec") 71 } 72 v.Code = *dec.Code 73 if dec.Data == nil { 74 return errors.New("missing required field 'data' for vmExec") 75 } 76 v.Data = *dec.Data 77 if dec.Value == nil { 78 return errors.New("missing required field 'value' for vmExec") 79 } 80 v.Value = (*big.Int)(dec.Value) 81 if dec.EnergyLimit == nil { 82 return errors.New("missing required field 'energy' for vmExec") 83 } 84 v.EnergyLimit = uint64(*dec.EnergyLimit) 85 if dec.EnergyPrice == nil { 86 return errors.New("missing required field 'energyPrice' for vmExec") 87 } 88 v.EnergyPrice = (*big.Int)(dec.EnergyPrice) 89 return nil 90 }