From 5865d41f889d326b51fb0b68be9a41c46d6cad83 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 25 Sep 2016 20:29:26 +0200 Subject: [PATCH 01/13] authproxy: Add support for RPC named arguments --- qa/rpc-tests/test_framework/authproxy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/test_framework/authproxy.py b/qa/rpc-tests/test_framework/authproxy.py index 9bee1962e..09ed61129 100644 --- a/qa/rpc-tests/test_framework/authproxy.py +++ b/qa/rpc-tests/test_framework/authproxy.py @@ -138,14 +138,16 @@ class AuthServiceProxy(object): self.__conn.request(method, path, postdata, headers) return self._get_response() - def __call__(self, *args): + def __call__(self, *args, **argsn): AuthServiceProxy.__id_count += 1 log.debug("-%s-> %s %s"%(AuthServiceProxy.__id_count, self._service_name, json.dumps(args, default=EncodeDecimal, ensure_ascii=self.ensure_ascii))) + if args and argsn: + raise ValueError('Cannot handle both named and positional arguments') postdata = json.dumps({'version': '1.1', 'method': self._service_name, - 'params': args, + 'params': args or argsn, 'id': AuthServiceProxy.__id_count}, default=EncodeDecimal, ensure_ascii=self.ensure_ascii) response = self._request('POST', self.__url.path, postdata.encode('utf-8')) if response['error'] is not None: From 6f1c76ae14c884c919db9ed720c7776aa0748244 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 25 Sep 2016 20:42:49 +0200 Subject: [PATCH 02/13] rpc: Support named arguments The [JSON-RPC specification](http://www.jsonrpc.org/specification) allows passing parameters as an Array, for by-position arguments, or an Object, for by-name arguments. This implements by-name arguments, but preserves full backwards compatibility. API using by-name arguments are easier to extend, and easier to use (no need to guess which argument goes where). Named are mapped to positions by a per-call structure, provided through the RPC command table. Missing arguments will be replaced by null, except if at the end, then the argument is left out completely. Currently calls fail (though not crash) on intermediate nulls, but this should be improved on a per-call basis later. --- src/rpc/server.cpp | 65 +++++++++++++++++++++++++++++++++++++++------- src/rpc/server.h | 1 + 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 8a223d8aa..1b94e1007 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -26,6 +26,7 @@ #include // for to_upper() #include // for unique_ptr +#include using namespace RPCServer; using namespace std; @@ -268,11 +269,11 @@ UniValue stop(const JSONRPCRequest& jsonRequest) * Call Table */ static const CRPCCommand vRPCCommands[] = -{ // category name actor (function) okSafeMode - // --------------------- ------------------------ ----------------------- ---------- +{ // category name actor (function) okSafe argNames + // --------------------- ------------------------ ----------------------- ------ ---------- /* Overall control/query calls */ - { "control", "help", &help, true }, - { "control", "stop", &stop, true }, + { "control", "help", &help, true, {"command"} }, + { "control", "stop", &stop, true, {} }, }; CRPCTable::CRPCTable() @@ -379,12 +380,12 @@ void JSONRPCRequest::parse(const UniValue& valRequest) // Parse params UniValue valParams = find_value(request, "params"); - if (valParams.isArray()) - params = valParams.get_array(); + if (valParams.isArray() || valParams.isObject()) + params = valParams; else if (valParams.isNull()) params = UniValue(UniValue::VARR); else - throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array"); + throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object"); } static UniValue JSONRPCExecOne(const UniValue& req) @@ -420,6 +421,48 @@ std::string JSONRPCExecBatch(const UniValue& vReq) return ret.write() + "\n"; } +/** + * Process named arguments into a vector of positional arguments, based on the + * passed-in specification for the RPC call's arguments. + */ +static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, const std::vector& argNames) +{ + JSONRPCRequest out = in; + out.params = UniValue(UniValue::VARR); + // Build a map of parameters, and remove ones that have been processed, so that we can throw a focused error if + // there is an unknown one. + const std::vector& keys = in.params.getKeys(); + const std::vector& values = in.params.getValues(); + std::unordered_map argsIn; + for (size_t i=0; isecond); + argsIn.erase(fr); + } else { + hole += 1; + } + } + // If there are still arguments in the argsIn map, this is an error. + if (!argsIn.empty()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown named parameter " + argsIn.begin()->first); + } + // Return request with named arguments transformed to positional arguments + return out; +} + UniValue CRPCTable::execute(const JSONRPCRequest &request) const { // Return immediately if in warmup @@ -438,8 +481,12 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const try { - // Execute - return pcmd->actor(request); + // Execute, convert arguments to array if necessary + if (request.params.isObject()) { + return pcmd->actor(transformNamedArguments(request, pcmd->argNames)); + } else { + return pcmd->actor(request); + } } catch (const std::exception& e) { diff --git a/src/rpc/server.h b/src/rpc/server.h index f3cdf3c60..fed3d8c90 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -136,6 +136,7 @@ public: std::string name; rpcfn_type actor; bool okSafeMode; + std::vector argNames; }; /** From 495eb44a4f8461c799d2b1ad70e54d087a0b3098 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 25 Sep 2016 20:44:06 +0200 Subject: [PATCH 03/13] rpc: Named arguments for blockchain calls --- src/rpc/blockchain.cpp | 60 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index a127f10b8..e38636aa7 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -232,11 +232,11 @@ UniValue waitforblock(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) throw runtime_error( - "waitforblock (timeout)\n" + "waitforblock (timeout)\n" "\nWaits for a specific new block and returns useful info about it.\n" "\nReturns the current block on timeout or exit.\n" "\nArguments:\n" - "1. blockhash to wait for (string)\n" + "1. hash (string) Block hash to wait for.\n" "2. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n" "\nResult:\n" "{ (json object)\n" @@ -858,12 +858,12 @@ UniValue gettxout(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) throw runtime_error( - "gettxout \"txid\" n ( includemempool )\n" + "gettxout \"txid\" n ( include_mempool )\n" "\nReturns details about an unspent transaction output.\n" "\nArguments:\n" "1. \"txid\" (string, required) The transaction id\n" "2. n (numeric, required) vout number\n" - "3. includemempool (boolean, optional) Whether to include the mempool\n" + "3. include_mempool (boolean, optional) Whether to include the mempool\n" "\nResult:\n" "{\n" " \"bestblock\" : \"hash\", (string) the block hash\n" @@ -940,11 +940,11 @@ UniValue verifychain(const JSONRPCRequest& request) int nCheckDepth = GetArg("-checkblocks", DEFAULT_CHECKBLOCKS); if (request.fHelp || request.params.size() > 2) throw runtime_error( - "verifychain ( checklevel numblocks )\n" + "verifychain ( checklevel nblocks )\n" "\nVerifies blockchain database.\n" "\nArguments:\n" "1. checklevel (numeric, optional, 0-4, default=" + strprintf("%d", nCheckLevel) + ") How thorough the block verification is.\n" - "2. numblocks (numeric, optional, default=" + strprintf("%d", nCheckDepth) + ", 0=all) The number of blocks to check.\n" + "2. nblocks (numeric, optional, default=" + strprintf("%d", nCheckDepth) + ", 0=all) The number of blocks to check.\n" "\nResult:\n" "true|false (boolean) Verified or not\n" "\nExamples:\n" @@ -1367,33 +1367,33 @@ UniValue reconsiderblock(const JSONRPCRequest& request) } static const CRPCCommand commands[] = -{ // category name actor (function) okSafeMode - // --------------------- ------------------------ ----------------------- ---------- - { "blockchain", "getblockchaininfo", &getblockchaininfo, true }, - { "blockchain", "getbestblockhash", &getbestblockhash, true }, - { "blockchain", "getblockcount", &getblockcount, true }, - { "blockchain", "getblock", &getblock, true }, - { "blockchain", "getblockhash", &getblockhash, true }, - { "blockchain", "getblockheader", &getblockheader, true }, - { "blockchain", "getchaintips", &getchaintips, true }, - { "blockchain", "getdifficulty", &getdifficulty, true }, - { "blockchain", "getmempoolancestors", &getmempoolancestors, true }, - { "blockchain", "getmempooldescendants", &getmempooldescendants, true }, - { "blockchain", "getmempoolentry", &getmempoolentry, true }, - { "blockchain", "getmempoolinfo", &getmempoolinfo, true }, - { "blockchain", "getrawmempool", &getrawmempool, true }, - { "blockchain", "gettxout", &gettxout, true }, - { "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true }, - { "blockchain", "verifychain", &verifychain, true }, +{ // category name actor (function) okSafe argNames + // --------------------- ------------------------ ----------------------- ------ ---------- + { "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} }, + { "blockchain", "getbestblockhash", &getbestblockhash, true, {} }, + { "blockchain", "getblockcount", &getblockcount, true, {} }, + { "blockchain", "getblock", &getblock, true, {"hash","verbose"} }, + { "blockchain", "getblockhash", &getblockhash, true, {"index"} }, + { "blockchain", "getblockheader", &getblockheader, true, {"hash","verbose"} }, + { "blockchain", "getchaintips", &getchaintips, true, {} }, + { "blockchain", "getdifficulty", &getdifficulty, true, {} }, + { "blockchain", "getmempoolancestors", &getmempoolancestors, true, {"txid","verbose"} }, + { "blockchain", "getmempooldescendants", &getmempooldescendants, true, {"txid","verbose"} }, + { "blockchain", "getmempoolentry", &getmempoolentry, true, {"txid"} }, + { "blockchain", "getmempoolinfo", &getmempoolinfo, true, {} }, + { "blockchain", "getrawmempool", &getrawmempool, true, {"verbose"} }, + { "blockchain", "gettxout", &gettxout, true, {"txid","n","include_mempool"} }, + { "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true, {} }, + { "blockchain", "verifychain", &verifychain, true, {"checklevel","nblocks"} }, - { "blockchain", "preciousblock", &preciousblock, true }, + { "blockchain", "preciousblock", &preciousblock, true, {"hash"} }, /* Not shown in help */ - { "hidden", "invalidateblock", &invalidateblock, true }, - { "hidden", "reconsiderblock", &reconsiderblock, true }, - { "hidden", "waitfornewblock", &waitfornewblock, true }, - { "hidden", "waitforblock", &waitforblock, true }, - { "hidden", "waitforblockheight", &waitforblockheight, true }, + { "hidden", "invalidateblock", &invalidateblock, true, {"hash"} }, + { "hidden", "reconsiderblock", &reconsiderblock, true, {"hash"} }, + { "hidden", "waitfornewblock", &waitfornewblock, true, {"timeout"} }, + { "hidden", "waitforblock", &waitforblock, true, {"hash","timeout"} }, + { "hidden", "waitforblockheight", &waitforblockheight, true, {"height","timeout"} }, }; void RegisterBlockchainRPCCommands(CRPCTable &t) From 286ec08cb0e5611bb062bc45d4b86df6d6ea801f Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 25 Sep 2016 20:55:24 +0200 Subject: [PATCH 04/13] rpc: Add 'echo' call for testing This hidden call simply returns what is passed in. --- src/rpc/misc.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index f7c4ecc20..13befb108 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -492,6 +492,17 @@ UniValue getmemoryinfo(const JSONRPCRequest& request) return obj; } +UniValue echo(const JSONRPCRequest& request) +{ + if (request.fHelp) + throw runtime_error( + "echo \"message\" ...\n" + "\nSimply echo back the input arguments\n" + ); + + return request.params; +} + static const CRPCCommand commands[] = { // category name actor (function) okSafeMode // --------------------- ------------------------ ----------------------- ---------- @@ -504,6 +515,7 @@ static const CRPCCommand commands[] = /* Not shown in help */ { "hidden", "setmocktime", &setmocktime, true }, + { "hidden", "echo", &echo, true, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, }; void RegisterMiscRPCCommands(CRPCTable &t) From fba1a6150c1f7f9e3b407faefba4ccc710fe075e Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 25 Sep 2016 20:58:30 +0200 Subject: [PATCH 05/13] rpc: Named arguments for misc calls --- src/rpc/misc.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 13befb108..4029e5e67 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -506,16 +506,16 @@ UniValue echo(const JSONRPCRequest& request) static const CRPCCommand commands[] = { // category name actor (function) okSafeMode // --------------------- ------------------------ ----------------------- ---------- - { "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */ - { "control", "getmemoryinfo", &getmemoryinfo, true }, - { "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */ - { "util", "createmultisig", &createmultisig, true }, - { "util", "verifymessage", &verifymessage, true }, - { "util", "signmessagewithprivkey", &signmessagewithprivkey, true }, + { "control", "getinfo", &getinfo, true, {} }, /* uses wallet if enabled */ + { "control", "getmemoryinfo", &getmemoryinfo, true, {} }, + { "util", "validateaddress", &validateaddress, true, {"bitcoinaddress"} }, /* uses wallet if enabled */ + { "util", "createmultisig", &createmultisig, true, {"nrequired","keys"} }, + { "util", "verifymessage", &verifymessage, true, {"bitcoinaddress","signature","message"} }, + { "util", "signmessagewithprivkey", &signmessagewithprivkey, true, {"privkey","message"} }, /* Not shown in help */ - { "hidden", "setmocktime", &setmocktime, true }, - { "hidden", "echo", &echo, true, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, + { "hidden", "setmocktime", &setmocktime, true, {"timestamp"}}, + { "hidden", "echo", &echo, true, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, }; void RegisterMiscRPCCommands(CRPCTable &t) From 2ca9dcd5b934bb85088415e44b967e2b93c00227 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 25 Sep 2016 21:09:13 +0200 Subject: [PATCH 06/13] test: Add test for RPC named arguments Add RPC testcase for RPC named arguments. --- qa/pull-tester/rpc-tests.py | 1 + qa/rpc-tests/rpcnamedargs.py | 52 +++++++++++++++++++++++++++++ qa/rpc-tests/test_framework/util.py | 12 +++++++ 3 files changed, 65 insertions(+) create mode 100755 qa/rpc-tests/rpcnamedargs.py diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py index be31cbbdd..83b6bdfe4 100755 --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -151,6 +151,7 @@ testScripts = [ 'signmessages.py', 'nulldummy.py', 'import-rescan.py', + 'rpcnamedargs.py', ] if ENABLE_ZMQ: testScripts.append('zmq_test.py') diff --git a/qa/rpc-tests/rpcnamedargs.py b/qa/rpc-tests/rpcnamedargs.py new file mode 100755 index 000000000..b526b1f51 --- /dev/null +++ b/qa/rpc-tests/rpcnamedargs.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# Copyright (c) 2016 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from decimal import Decimal + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.authproxy import JSONRPCException +from test_framework.util import ( + assert_equal, + assert_raises_jsonrpc, + assert_is_hex_string, + assert_is_hash_string, + start_nodes, + connect_nodes_bi, +) + + +class NamedArgumentTest(BitcoinTestFramework): + """ + Test named arguments on RPC calls. + """ + + def __init__(self): + super().__init__() + self.setup_clean_chain = False + self.num_nodes = 1 + + def setup_network(self, split=False): + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) + self.is_network_split = False + self.sync_all() + + def run_test(self): + node = self.nodes[0] + h = node.help(command='getinfo') + assert(h.startswith('getinfo\n')) + + assert_raises_jsonrpc(-8, node.help, random='getinfo') + + h = node.getblockhash(index=0) + node.getblock(hash=h) + + assert_equal(node.echo(), []) + assert_equal(node.echo(arg0=0,arg9=9), [0] + [None]*8 + [9]) + assert_equal(node.echo(arg1=1), [None, 1]) + assert_equal(node.echo(arg9=None), [None]*10) + assert_equal(node.echo(arg0=0,arg3=3,arg9=9), [0] + [None]*2 + [3] + [None]*5 + [9]) + +if __name__ == '__main__': + NamedArgumentTest().main() diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 85898d9f3..c29033595 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -546,6 +546,18 @@ def assert_raises_message(exc, message, fun, *args, **kwds): else: raise AssertionError("No exception raised") +def assert_raises_jsonrpc(code, fun, *args, **kwds): + '''Check for specific JSONRPC exception code''' + try: + fun(*args, **kwds) + except JSONRPCException as e: + if e.error["code"] != code: + raise AssertionError("Unexpected JSONRPC error code %i" % e.error["code"]) + except Exception as e: + raise AssertionError("Unexpected exception raised: "+type(e).__name__) + else: + raise AssertionError("No exception raised") + def assert_is_hex_string(string): try: int(string, 16) From b8ebc595bbd18e9239f132fb90b5513ae4759ebc Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 21 Nov 2016 13:55:35 +0100 Subject: [PATCH 07/13] rpc: Named arguments for net calls Also add a more descriptive message for `setnetworkactive`. --- src/rpc/net.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 632514fc8..8e64ace9f 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -468,10 +468,10 @@ UniValue setban(const JSONRPCRequest& request) if (request.fHelp || request.params.size() < 2 || (strCommand != "add" && strCommand != "remove")) throw runtime_error( - "setban \"ip(/netmask)\" \"add|remove\" (bantime) (absolute)\n" + "setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" "\nAttempts add or remove a IP/Subnet from the banned list.\n" "\nArguments:\n" - "1. \"ip(/netmask)\" (string, required) The IP/Subnet (see getpeerinfo for nodes ip) with a optional netmask (default is /32 = single ip)\n" + "1. \"subnet\" (string, required) The IP/Subnet (see getpeerinfo for nodes ip) with a optional netmask (default is /32 = single ip)\n" "2. \"command\" (string, required) 'add' to add a IP/Subnet to the list, 'remove' to remove a IP/Subnet from the list\n" "3. \"bantime\" (numeric, optional) time in seconds how long (or until when if [absolute] is set) the ip is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)\n" "4. \"absolute\" (boolean, optional) If set, the bantime must be a absolute timestamp in seconds since epoch (Jan 1 1970 GMT)\n" @@ -580,7 +580,9 @@ UniValue setnetworkactive(const JSONRPCRequest& request) if (request.fHelp || request.params.size() != 1) { throw runtime_error( "setnetworkactive true|false\n" - "Disable/enable all p2p network activity." + "\nDisable/enable all p2p network activity.\n" + "\nArguments:\n" + "1. \"state\" (boolean, required) true to enable networking, false to disable\n" ); } @@ -596,18 +598,18 @@ UniValue setnetworkactive(const JSONRPCRequest& request) static const CRPCCommand commands[] = { // category name actor (function) okSafeMode // --------------------- ------------------------ ----------------------- ---------- - { "network", "getconnectioncount", &getconnectioncount, true }, - { "network", "ping", &ping, true }, - { "network", "getpeerinfo", &getpeerinfo, true }, - { "network", "addnode", &addnode, true }, - { "network", "disconnectnode", &disconnectnode, true }, - { "network", "getaddednodeinfo", &getaddednodeinfo, true }, - { "network", "getnettotals", &getnettotals, true }, - { "network", "getnetworkinfo", &getnetworkinfo, true }, - { "network", "setban", &setban, true }, - { "network", "listbanned", &listbanned, true }, - { "network", "clearbanned", &clearbanned, true }, - { "network", "setnetworkactive", &setnetworkactive, true, }, + { "network", "getconnectioncount", &getconnectioncount, true, {} }, + { "network", "ping", &ping, true, {} }, + { "network", "getpeerinfo", &getpeerinfo, true, {} }, + { "network", "addnode", &addnode, true, {"node","command"} }, + { "network", "disconnectnode", &disconnectnode, true, {"node"} }, + { "network", "getaddednodeinfo", &getaddednodeinfo, true, {"node"} }, + { "network", "getnettotals", &getnettotals, true, {} }, + { "network", "getnetworkinfo", &getnetworkinfo, true, {} }, + { "network", "setban", &setban, true, {"subnet", "command", "bantime", "absolute"} }, + { "network", "listbanned", &listbanned, true, {} }, + { "network", "clearbanned", &clearbanned, true, {} }, + { "network", "setnetworkactive", &setnetworkactive, true, {"state"} }, }; void RegisterNetRPCCommands(CRPCTable &t) From 78b684f2ac9a81026239417bc6d3b76ec9a410c7 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 21 Nov 2016 14:03:09 +0100 Subject: [PATCH 08/13] rpc: Named arguments for mining calls --- src/rpc/mining.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index fa79d2073..3143916c8 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -78,12 +78,12 @@ UniValue getnetworkhashps(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 2) throw runtime_error( - "getnetworkhashps ( blocks height )\n" + "getnetworkhashps ( nblocks height )\n" "\nReturns the estimated network hashes per second based on the last n blocks.\n" "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n" "Pass in [height] to estimate the network speed at the time when a certain block was found.\n" "\nArguments:\n" - "1. blocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.\n" + "1. nblocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.\n" "2. height (numeric, optional, default=-1) To estimate at the time of the given height.\n" "\nResult:\n" "x (numeric) Hashes per second estimated\n" @@ -150,10 +150,10 @@ UniValue generate(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) throw runtime_error( - "generate numblocks ( maxtries )\n" - "\nMine up to numblocks blocks immediately (before the RPC call returns)\n" + "generate nblocks ( maxtries )\n" + "\nMine up to nblocks blocks immediately (before the RPC call returns)\n" "\nArguments:\n" - "1. numblocks (numeric, required) How many blocks are generated immediately.\n" + "1. nblocks (numeric, required) How many blocks are generated immediately.\n" "2. maxtries (numeric, optional) How many iterations to try (default = 1000000).\n" "\nResult:\n" "[ blockhashes ] (array) hashes of blocks generated\n" @@ -186,10 +186,10 @@ UniValue generatetoaddress(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) throw runtime_error( - "generatetoaddress numblocks address (maxtries)\n" + "generatetoaddress nblocks address (maxtries)\n" "\nMine blocks immediately to a specified address (before the RPC call returns)\n" "\nArguments:\n" - "1. numblocks (numeric, required) How many blocks are generated immediately.\n" + "1. nblocks (numeric, required) How many blocks are generated immediately.\n" "2. address (string, required) The address to send the newly generated bitcoin to.\n" "3. maxtries (numeric, optional) How many iterations to try (default = 1000000).\n" "\nResult:\n" @@ -329,7 +329,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) " https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n" "\nArguments:\n" - "1. TemplateRequest (json object, optional) A json object in the following spec\n" + "1. template_request (json object, optional) A json object in the following spec\n" " {\n" " \"mode\":\"template\" (string, optional) This must be set to \"template\", \"proposal\" (see BIP 23), or omitted\n" " \"capabilities\":[ (array, optional) A list of strings\n" @@ -719,7 +719,7 @@ UniValue submitblock(const JSONRPCRequest& request) "\nArguments:\n" "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n" - "2. \"jsonparametersobject\" (string, optional) object of optional parameters\n" + "2. \"parameters\" (string, optional) object of optional parameters\n" " {\n" " \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with submissions\n" " }\n" @@ -908,19 +908,19 @@ UniValue estimatesmartpriority(const JSONRPCRequest& request) static const CRPCCommand commands[] = { // category name actor (function) okSafeMode // --------------------- ------------------------ ----------------------- ---------- - { "mining", "getnetworkhashps", &getnetworkhashps, true }, - { "mining", "getmininginfo", &getmininginfo, true }, - { "mining", "prioritisetransaction", &prioritisetransaction, true }, - { "mining", "getblocktemplate", &getblocktemplate, true }, - { "mining", "submitblock", &submitblock, true }, + { "mining", "getnetworkhashps", &getnetworkhashps, true, {"nblocks","height"} }, + { "mining", "getmininginfo", &getmininginfo, true, {} }, + { "mining", "prioritisetransaction", &prioritisetransaction, true, {"txid","priority_delta","fee_delta"} }, + { "mining", "getblocktemplate", &getblocktemplate, true, {"template_request"} }, + { "mining", "submitblock", &submitblock, true, {"hexdata","parameters"} }, - { "generating", "generate", &generate, true }, - { "generating", "generatetoaddress", &generatetoaddress, true }, + { "generating", "generate", &generate, true, {"nblocks","maxtries"} }, + { "generating", "generatetoaddress", &generatetoaddress, true, {"nblocks","address","maxtries"} }, - { "util", "estimatefee", &estimatefee, true }, - { "util", "estimatepriority", &estimatepriority, true }, - { "util", "estimatesmartfee", &estimatesmartfee, true }, - { "util", "estimatesmartpriority", &estimatesmartpriority, true }, + { "util", "estimatefee", &estimatefee, true, {"nblocks"} }, + { "util", "estimatepriority", &estimatepriority, true, {"nblocks"} }, + { "util", "estimatesmartfee", &estimatesmartfee, true, {"nblocks"} }, + { "util", "estimatesmartpriority", &estimatesmartpriority, true, {"nblocks"} }, }; void RegisterMiningRPCCommands(CRPCTable &t) From 37a166f1465c91be3e700c0175f34dd0c3698df8 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 21 Nov 2016 14:32:36 +0100 Subject: [PATCH 09/13] rpc: Named arguments for wallet calls --- src/wallet/rpcdump.cpp | 8 +-- src/wallet/rpcwallet.cpp | 142 +++++++++++++++++++-------------------- 2 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 34443a825..228064c98 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -82,7 +82,7 @@ UniValue importprivkey(const JSONRPCRequest& request) if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) throw runtime_error( - "importprivkey \"bitcoinprivkey\" ( \"label\" rescan )\n" + "importprivkey \"bitcoinprivkey\" ( \"label\" ) ( rescan )\n" "\nAdds a private key (as returned by dumpprivkey) to your wallet.\n" "\nArguments:\n" "1. \"bitcoinprivkey\" (string, required) The private key (see dumpprivkey)\n" @@ -963,10 +963,10 @@ UniValue importmulti(const JSONRPCRequest& mainRequest) // clang-format off if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) throw runtime_error( - "importmulti '[]' '' \n\n" + "importmulti \"requests\" \"options\"\n\n" "Import addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options).\n\n" "Arguments:\n" - "1. request array (array, required) Data to be imported\n" + "1. requests (array, required) Data to be imported\n" " [ (array of json objects)\n" " {\n" " \"scriptPubKey\": \"