diff options
author | Bas van Kervel <bas@ethdev.com> | 2015-06-29 18:42:47 +0800 |
---|---|---|
committer | Bas van Kervel <bas@ethdev.com> | 2015-06-30 17:20:31 +0800 |
commit | 57dff6f1d7e8402d2849205cb44daaffcc40cc23 (patch) | |
tree | 044ad57de3335315cb8d8181c36e6ec9f5ac2b33 /rpc | |
parent | 7ffabf1d399989618470794600e25764bdd9954b (diff) | |
download | dexon-57dff6f1d7e8402d2849205cb44daaffcc40cc23.tar dexon-57dff6f1d7e8402d2849205cb44daaffcc40cc23.tar.gz dexon-57dff6f1d7e8402d2849205cb44daaffcc40cc23.tar.bz2 dexon-57dff6f1d7e8402d2849205cb44daaffcc40cc23.tar.lz dexon-57dff6f1d7e8402d2849205cb44daaffcc40cc23.tar.xz dexon-57dff6f1d7e8402d2849205cb44daaffcc40cc23.tar.zst dexon-57dff6f1d7e8402d2849205cb44daaffcc40cc23.zip |
initialize fields to prevent nil pointer exception
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/api/eth_args.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index 203171d58..b5507832d 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -906,6 +906,9 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { } trans := new(types.Transaction) + trans.Amount = new(big.Int) + trans.GasLimit = new(big.Int) + trans.Price = new(big.Int) if val, found := fields["To"]; found { if strVal, ok := val.(string); ok && len(strVal) > 0 { @@ -928,13 +931,15 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Nonce - %v", err)) } } + } else { + return shared.NewDecodeParamError("tx.Nonce not found") } var parseOk bool if val, found := fields["Value"]; found { if strVal, ok := val.(string); ok { tx.Value = strVal - if trans.Amount, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + if _, parseOk = trans.Amount.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Amount - %v", err)) } } @@ -954,7 +959,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["GasLimit"]; found { if strVal, ok := val.(string); ok { tx.GasLimit = strVal - if trans.GasLimit, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + if _, parseOk = trans.GasLimit.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasLimit - %v", err)) } } @@ -963,7 +968,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["GasPrice"]; found { if strVal, ok := val.(string); ok { tx.GasPrice = strVal - if trans.Price, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + if _, parseOk = trans.Price.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasPrice - %v", err)) } } |