diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-27 07:07:28 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-27 07:07:28 +0800 |
commit | e0781c2548aec596e6ce1140c5b871555a75f3cb (patch) | |
tree | e2f6475deb6da039d0d8b10c3a1db947f95b0b2d /rpc/args.go | |
parent | 3fcef54f9b81b49f7af2f06a231cd7e44ea851ba (diff) | |
download | dexon-e0781c2548aec596e6ce1140c5b871555a75f3cb.tar.gz dexon-e0781c2548aec596e6ce1140c5b871555a75f3cb.tar.zst dexon-e0781c2548aec596e6ce1140c5b871555a75f3cb.zip |
NewTxArgs accept numbers or strings for value/gas/gasprice
Diffstat (limited to 'rpc/args.go')
-rw-r--r-- | rpc/args.go | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/rpc/args.go b/rpc/args.go index 806efb9cc..78cbca5a9 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -166,7 +166,14 @@ type NewTxArgs struct { func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { var obj []json.RawMessage - var ext struct{ From, To, Value, Gas, GasPrice, Data string } + var ext struct { + From string + To string + Value interface{} + Gas interface{} + GasPrice interface{} + Data string + } // Decode byte slice to array of RawMessages if err := json.Unmarshal(b, &obj); err != nil { @@ -189,11 +196,36 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { args.From = ext.From args.To = ext.To - args.Value = common.String2Big(ext.Value) - args.Gas = common.String2Big(ext.Gas) - args.GasPrice = common.String2Big(ext.GasPrice) args.Data = ext.Data + var num int64 + if ext.Value == nil { + return NewValidationError("value", "is required") + } else { + if err := numString(ext.Value, &num); err != nil { + return err + } + } + args.Value = big.NewInt(num) + + if ext.Gas == nil { + return NewValidationError("gas", "is required") + } else { + if err := numString(ext.Gas, &num); err != nil { + return err + } + } + args.Gas = big.NewInt(num) + + if ext.GasPrice == nil { + return NewValidationError("gasprice", "is required") + } else { + if err := numString(ext.GasPrice, &num); err != nil { + return err + } + } + args.GasPrice = big.NewInt(num) + // Check for optional BlockNumber param if len(obj) > 1 { if err := blockHeightFromJson(obj[1], &args.BlockNumber); err != nil { |