Correct optional parameters for listsinceblock.

Fixes #3
This commit is contained in:
John C. Vernaleo 2013-08-12 13:46:03 -04:00
parent dc2fe40a3d
commit c8bb6b304e
2 changed files with 26 additions and 1 deletions

View file

@ -262,7 +262,7 @@ func CreateMessage(message string, args ...interface{}) ([]byte, error) {
} }
finalMessage, err = jsonWithArgs(message, args) finalMessage, err = jsonWithArgs(message, args)
// Two required strings // Two required strings
case "listsinceblock", "setaccount", "signmessage", "walletpassphrase", case "setaccount", "signmessage", "walletpassphrase",
"walletpassphrasechange": "walletpassphrasechange":
if len(args) != 2 { if len(args) != 2 {
err = fmt.Errorf("Missing arguments for %s", message) err = fmt.Errorf("Missing arguments for %s", message)
@ -437,6 +437,26 @@ func CreateMessage(message string, args ...interface{}) ([]byte, error) {
return finalMessage, err return finalMessage, err
} }
finalMessage, err = jsonWithArgs(message, args) finalMessage, err = jsonWithArgs(message, args)
// Two optional strings
case "listsinceblock":
if len(args) > 2 {
err = fmt.Errorf("Wrong number of arguments for %s", message)
return finalMessage, err
}
ok1 := true
ok2 := true
if len(args) >= 1 {
_, ok1 = args[0].(string)
}
if len(args) == 2 {
_, ok2 = args[1].(string)
}
if !ok1 || !ok2 {
err = fmt.Errorf("Optional arguments must be strings for %s", message)
return finalMessage, err
}
finalMessage, err = jsonWithArgs(message, args)
// Two required strings, one required float, one optional int, // Two required strings, one required float, one optional int,
// two optional strings. // two optional strings.
case "sendfrom": case "sendfrom":

View file

@ -162,6 +162,11 @@ var cmdtests = []struct {
{"signrawtransaction", []interface{}{"hexstring", 1, "test2", "test3", "test4"}, false}, {"signrawtransaction", []interface{}{"hexstring", 1, "test2", "test3", "test4"}, false},
{"signrawtransaction", []interface{}{"hexstring", "test", 2, "test3", "test4"}, false}, {"signrawtransaction", []interface{}{"hexstring", "test", 2, "test3", "test4"}, false},
{"signrawtransaction", []interface{}{"hexstring", "test", "test2", 3, "test4"}, false}, {"signrawtransaction", []interface{}{"hexstring", "test", "test2", 3, "test4"}, false},
{"listsinceblock", []interface{}{"test", "test"}, true},
{"listsinceblock", []interface{}{"test", "test", "test"}, false},
{"listsinceblock", []interface{}{"test"}, true},
{"listsinceblock", []interface{}{}, true},
{"listsinceblock", []interface{}{1, "test"}, false},
{"fakecommand", nil, false}, {"fakecommand", nil, false},
} }