aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'rpc')
-rw-r--r--rpc/args.go26
-rw-r--r--rpc/args_test.go21
2 files changed, 46 insertions, 1 deletions
diff --git a/rpc/args.go b/rpc/args.go
index 2e4e2c7a9..40f8575b2 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -188,10 +188,34 @@ type GetBalanceArgs struct {
}
func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
- if err = UnmarshalRawMessages(b, &args.Address, &args.BlockNumber); err != nil {
+ var obj []interface{}
+ r := bytes.NewReader(b)
+ if err := json.NewDecoder(r).Decode(&obj); err != nil {
return errDecodeArgs
}
+ if len(obj) < 1 {
+ return errArguments
+ }
+
+ addstr, ok := obj[0].(string)
+ if !ok {
+ return errDecodeArgs
+ }
+ args.Address = addstr
+
+ if len(obj) > 1 {
+ if obj[1].(string) == "latest" {
+ args.BlockNumber = -1
+ } else {
+ args.BlockNumber = ethutil.Big(obj[1].(string)).Int64()
+ }
+ }
+
+ // if err = UnmarshalRawMessages(b, &args.Address, &args.BlockNumber); err != nil {
+ // return errDecodeArgs
+ // }
+
return nil
}
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 6650d8d61..6b6d3c3c0 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -43,6 +43,17 @@ func TestGetBalanceArgs(t *testing.T) {
}
}
+func TestGetBalanceEmptyArgs(t *testing.T) {
+ input := `[]`
+
+ args := new(GetBalanceArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+
+}
+
func TestGetBlockByHashArgs(t *testing.T) {
input := `["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", true]`
expected := new(GetBlockByHashArgs)
@@ -418,6 +429,16 @@ func TestFilterStringArgs(t *testing.T) {
}
}
+func TestFilterStringEmptyArgs(t *testing.T) {
+ input := `[]`
+
+ args := new(FilterStringArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestWhisperIdentityArgs(t *testing.T) {
input := `["0xc931d93e97ab07fe42d923478ba2465f283"]`
expected := new(WhisperIdentityArgs)