github.com/waltonchain/waltonchain_gwtc_src@v1.1.4-0.20201225072101-8a298c95a819/core/types/gen_tx_json.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package types 4 5 import ( 6 "encoding/json" 7 "errors" 8 "math/big" 9 10 "github.com/wtc/go-wtc/common" 11 "github.com/wtc/go-wtc/common/hexutil" 12 ) 13 14 func (t txdata) MarshalJSON() ([]byte, error) { 15 type txdata struct { 16 AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"` 17 Price *hexutil.Big `json:"gasPrice" gencodec:"required"` 18 GasLimit *hexutil.Big `json:"gas" gencodec:"required"` 19 Recipient *common.Address `json:"to" rlp:"nil"` 20 Amount *hexutil.Big `json:"value" gencodec:"required"` 21 Payload hexutil.Bytes `json:"input" gencodec:"required"` 22 V *hexutil.Big `json:"v" gencodec:"required"` 23 R *hexutil.Big `json:"r" gencodec:"required"` 24 S *hexutil.Big `json:"s" gencodec:"required"` 25 Hash *common.Hash `json:"hash" rlp:"-"` 26 } 27 var enc txdata 28 enc.AccountNonce = hexutil.Uint64(t.AccountNonce) 29 enc.Price = (*hexutil.Big)(t.Price) 30 enc.GasLimit = (*hexutil.Big)(t.GasLimit) 31 enc.Recipient = t.Recipient 32 enc.Amount = (*hexutil.Big)(t.Amount) 33 enc.Payload = t.Payload 34 enc.V = (*hexutil.Big)(t.V) 35 enc.R = (*hexutil.Big)(t.R) 36 enc.S = (*hexutil.Big)(t.S) 37 enc.Hash = t.Hash 38 return json.Marshal(&enc) 39 } 40 41 func (t *txdata) UnmarshalJSON(input []byte) error { 42 type txdata struct { 43 AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` 44 Price *hexutil.Big `json:"gasPrice" gencodec:"required"` 45 GasLimit *hexutil.Big `json:"gas" gencodec:"required"` 46 Recipient *common.Address `json:"to" rlp:"nil"` 47 Amount *hexutil.Big `json:"value" gencodec:"required"` 48 Payload hexutil.Bytes `json:"input" gencodec:"required"` 49 V *hexutil.Big `json:"v" gencodec:"required"` 50 R *hexutil.Big `json:"r" gencodec:"required"` 51 S *hexutil.Big `json:"s" gencodec:"required"` 52 Hash *common.Hash `json:"hash" rlp:"-"` 53 } 54 var dec txdata 55 if err := json.Unmarshal(input, &dec); err != nil { 56 return err 57 } 58 if dec.AccountNonce == nil { 59 return errors.New("missing required field 'nonce' for txdata") 60 } 61 t.AccountNonce = uint64(*dec.AccountNonce) 62 if dec.Price == nil { 63 return errors.New("missing required field 'gasPrice' for txdata") 64 } 65 t.Price = (*big.Int)(dec.Price) 66 if dec.GasLimit == nil { 67 return errors.New("missing required field 'gas' for txdata") 68 } 69 t.GasLimit = (*big.Int)(dec.GasLimit) 70 if dec.Recipient != nil { 71 t.Recipient = dec.Recipient 72 } 73 if dec.Amount == nil { 74 return errors.New("missing required field 'value' for txdata") 75 } 76 t.Amount = (*big.Int)(dec.Amount) 77 if dec.Payload == nil { 78 return errors.New("missing required field 'input' for txdata") 79 } 80 t.Payload = dec.Payload 81 if dec.V == nil { 82 return errors.New("missing required field 'v' for txdata") 83 } 84 t.V = (*big.Int)(dec.V) 85 if dec.R == nil { 86 return errors.New("missing required field 'r' for txdata") 87 } 88 t.R = (*big.Int)(dec.R) 89 if dec.S == nil { 90 return errors.New("missing required field 's' for txdata") 91 } 92 t.S = (*big.Int)(dec.S) 93 if dec.Hash != nil { 94 t.Hash = dec.Hash 95 } 96 return nil 97 }