github.com/edxfund/masterchain@v1.8.16-0.20190112084457-6ad8bdd0f74a/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/EDXFund/MasterChain/common" 11 ) 12 13 // MarshalJSON marshals as JSON. 14 func (t txdata) MarshalJSON() ([]byte, error) { 15 type txdata struct { 16 AccountNonce uint64 `json:"nonce" gencodec:"required"` 17 Price *big.Int `json:"gasPrice" gencodec:"required"` 18 GasLimit uint64 `json:"gas" gencodec:"required"` 19 Recipient *common.Address `json:"to" rlp:"nil"` 20 TokenId uint64 `json:"tokenId" gencodec:"required"` 21 Amount *big.Int `json:"value" gencodec:"required"` 22 Payload []byte `json:"input" gencodec:"required"` 23 V *big.Int `json:"v" gencodec:"required"` 24 R *big.Int `json:"r" gencodec:"required"` 25 S *big.Int `json:"s" gencodec:"required"` 26 Hash *common.Hash `json:"hash" rlp:"-"` 27 } 28 var enc txdata 29 enc.AccountNonce = t.AccountNonce 30 enc.Price = t.Price 31 enc.GasLimit = t.GasLimit 32 enc.Recipient = t.Recipient 33 enc.TokenId = t.TokenId 34 enc.Amount = t.Amount 35 enc.Payload = t.Payload 36 enc.V = t.V 37 enc.R = t.R 38 enc.S = t.S 39 enc.Hash = t.Hash 40 return json.Marshal(&enc) 41 } 42 43 // UnmarshalJSON unmarshals from JSON. 44 func (t *txdata) UnmarshalJSON(input []byte) error { 45 type txdata struct { 46 AccountNonce *uint64 `json:"nonce" gencodec:"required"` 47 Price *big.Int `json:"gasPrice" gencodec:"required"` 48 GasLimit *uint64 `json:"gas" gencodec:"required"` 49 Recipient *common.Address `json:"to" rlp:"nil"` 50 TokenId *uint64 `json:"tokenId" gencodec:"required"` 51 Amount *big.Int `json:"value" gencodec:"required"` 52 Payload []byte `json:"input" gencodec:"required"` 53 V *big.Int `json:"v" gencodec:"required"` 54 R *big.Int `json:"r" gencodec:"required"` 55 S *big.Int `json:"s" gencodec:"required"` 56 Hash *common.Hash `json:"hash" rlp:"-"` 57 } 58 var dec txdata 59 if err := json.Unmarshal(input, &dec); err != nil { 60 return err 61 } 62 if dec.AccountNonce == nil { 63 return errors.New("missing required field 'nonce' for txdata") 64 } 65 t.AccountNonce = *dec.AccountNonce 66 if dec.Price == nil { 67 return errors.New("missing required field 'gasPrice' for txdata") 68 } 69 t.Price = dec.Price 70 if dec.GasLimit == nil { 71 return errors.New("missing required field 'gas' for txdata") 72 } 73 t.GasLimit = *dec.GasLimit 74 if dec.Recipient != nil { 75 t.Recipient = dec.Recipient 76 } 77 if dec.TokenId == nil { 78 return errors.New("missing required field 'tokenId' for txdata") 79 } 80 t.TokenId = *dec.TokenId 81 if dec.Amount == nil { 82 return errors.New("missing required field 'value' for txdata") 83 } 84 t.Amount = dec.Amount 85 if dec.Payload == nil { 86 return errors.New("missing required field 'input' for txdata") 87 } 88 t.Payload = dec.Payload 89 if dec.V == nil { 90 return errors.New("missing required field 'v' for txdata") 91 } 92 t.V = dec.V 93 if dec.R == nil { 94 return errors.New("missing required field 'r' for txdata") 95 } 96 t.R = dec.R 97 if dec.S == nil { 98 return errors.New("missing required field 's' for txdata") 99 } 100 t.S = dec.S 101 if dec.Hash != nil { 102 t.Hash = dec.Hash 103 } 104 return nil 105 }