From d3dea375c6b2def201bb7070cb577bbeeb7ad6d6 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 12 Nov 2013 11:24:33 -0500 Subject: [PATCH] Fix SendManyCmd unmarshaling. This change fixes an incorrect parameter length check, as well as correcting the type assertions for the address to amount pairs. --- jsoncmd.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/jsoncmd.go b/jsoncmd.go index d3d0650b..276ec907 100644 --- a/jsoncmd.go +++ b/jsoncmd.go @@ -5101,7 +5101,7 @@ func (cmd *SendManyCmd) UnmarshalJSON(b []byte) error { return err } - if len(r.Params) > 6 || len(r.Params) < 3 { + if len(r.Params) > 4 || len(r.Params) < 2 { return ErrWrongNumberOfParams } @@ -5110,15 +5110,19 @@ func (cmd *SendManyCmd) UnmarshalJSON(b []byte) error { return errors.New("first parameter fromaccount must be a string") } - famounts, ok := r.Params[1].(map[string]float64) + iamounts, ok := r.Params[1].(map[string]interface{}) if !ok { - return errors.New("second parameter toaccount must be a string to number map") + return errors.New("second parameter toaccount must be a JSON object") } amounts := make(map[string]int64) - for k, v := range famounts { + for k, v := range iamounts { + famount, ok := v.(float64) + if !ok { + return errors.New("second parameter toaccount must be a string to number map") + } var err error - amounts[k], err = JSONToAmount(v) + amounts[k], err = JSONToAmount(famount) if err != nil { return err }