From cbd3d730a91fa92a851aa4aa97053a0dc628e8c4 Mon Sep 17 00:00:00 2001 From: "John C. Vernaleo" Date: Tue, 22 Oct 2013 15:11:01 -0400 Subject: [PATCH] Add initial support for submitblock command. Closes #7 --- jsonapi.go | 19 +++++++++++++++++++ jsonapi_test.go | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/jsonapi.go b/jsonapi.go index d3bab377b..5ab57f2c6 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -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 { diff --git a/jsonapi_test.go b/jsonapi_test.go index 2e7b1c73d..dc35de58b 100644 --- a/jsonapi_test.go +++ b/jsonapi_test.go @@ -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}, }