From c8a9a4e76d00483280a51bb6c0f9517d6c531589 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 29 May 2015 14:27:15 -0500 Subject: Differentiate between 0 and unspecified gas/gasprice --- rpc/args.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'rpc/args.go') diff --git a/rpc/args.go b/rpc/args.go index 686872a59..50b0f5826 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -261,22 +261,22 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { args.Value = num num = nil - if ext.Gas == nil { - num = big.NewInt(0) - } else { + if ext.Gas != nil { if num, err = numString(ext.Gas); err != nil { return err } + } else { + num = nil } args.Gas = num num = nil - if ext.GasPrice == nil { - num = big.NewInt(0) - } else { + if ext.GasPrice != nil { if num, err = numString(ext.GasPrice); err != nil { return err } + } else { + num = nil } args.GasPrice = num @@ -346,21 +346,21 @@ func (args *CallArgs) UnmarshalJSON(b []byte) (err error) { } args.Value = num - if ext.Gas == nil { - num = big.NewInt(0) - } else { + if ext.Gas != nil { if num, err = numString(ext.Gas); err != nil { return err } + } else { + num = nil } args.Gas = num - if ext.GasPrice == nil { - num = big.NewInt(0) - } else { + if ext.GasPrice != nil { if num, err = numString(ext.GasPrice); err != nil { return err } + } else { + num = nil } args.GasPrice = num -- cgit v1.2.3 From 046411866b257f6242a37b561b8e417199f7e52b Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 9 Jun 2015 08:47:20 -0400 Subject: Fixed signing + tests --- rpc/args.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'rpc/args.go') diff --git a/rpc/args.go b/rpc/args.go index 686872a59..11d9a2a70 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -172,13 +172,8 @@ type NewSigArgs struct { } func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { - var obj []json.RawMessage - var ext struct { - From string - Data string - } + var obj []interface{} - // Decode byte slice to array of RawMessages if err := json.Unmarshal(b, &obj); err != nil { return NewDecodeParamError(err.Error()) } @@ -188,21 +183,26 @@ func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { return NewInsufficientParamsError(len(obj), 1) } - // Decode 0th RawMessage to temporary struct - if err := json.Unmarshal(obj[0], &ext); err != nil { - return NewDecodeParamError(err.Error()) + from, ok := obj[0].(string) + if !ok { + return NewInvalidTypeError("from", "not a string") } + args.From = from - if len(ext.From) == 0 { + if len(args.From) == 0 { return NewValidationError("from", "is required") } - if len(ext.Data) == 0 { + data, ok := obj[1].(string) + if !ok { + return NewInvalidTypeError("data", "not a string") + } + args.Data = data + + if len(args.Data) == 0 { return NewValidationError("data", "is required") } - args.From = ext.From - args.Data = ext.Data return nil } -- cgit v1.2.3