Add initial support for submitblock command.

Closes #7
This commit is contained in:
John C. Vernaleo 2013-10-22 15:11:01 -04:00
parent 9ddb768c47
commit cbd3d730a9
2 changed files with 24 additions and 0 deletions

View file

@ -388,6 +388,25 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
return finalMessage, err
}
finalMessage, err = jsonWithArgs(message, id, args)
// One required string, one optional string
// Strictly, the optional arg for submit block is an object, but
// bitcoind ignores it for now, so best to just allow string until
// support for it is complete.
case "submitblock":
if len(args) > 2 || len(args) == 0 {
err = fmt.Errorf("Wrong number of argument for %s", message)
return finalMessage, err
}
_, ok1 := args[0].(string)
ok2 := true
if len(args) == 2 {
_, ok2 = args[1].(string)
}
if !ok1 || !ok2 {
err = fmt.Errorf("Arguments must be string and optionally string for %s", message)
return finalMessage, err
}
finalMessage, err = jsonWithArgs(message, id, args)
// One optional int, one optional bool
case "listreceivedbyaccount", "listreceivedbyaddress":
if len(args) > 2 {

View file

@ -176,6 +176,11 @@ var cmdtests = []struct {
{"getrawchangeaddress", []interface{}{"something", "test"}, false},
{"getbestblockhash", []interface{}{}, true},
{"getbestblockhash", []interface{}{"something"}, false},
{"submitblock", []interface{}{}, false},
{"submitblock", []interface{}{"something"}, true},
{"submitblock", []interface{}{"something", "something else"}, true},
{"submitblock", []interface{}{"something", "something else", "more"}, false},
{"submitblock", []interface{}{"something", 1}, false},
{"fakecommand", nil, false},
}