Skip to content

Commit

Permalink
Merge bitcoin#14720: rpc: Correctly name arguments
Browse files Browse the repository at this point in the history
fa0815c rpc: Correctly name arguments (Jon Layton)

Pull request description:

  Consistently use the same name to describe arguments in the documentation and add a test that uses the name.

  By splitting it up, the changes are easier to potentially backport and also make review easier when we switch to `RPCHelpMan`.

  The tests should pass with or without the changes in `src`.

  Partly stolen from bitcoin#14459 (More RPC help description fixes by ch4ot1c)

Tree-SHA512: 1072992b1e93ac41006613523e54a0a8004f529fcb101eb9d74d91474abb0945a5a7539f249905151b904b87448f9efc0cacbd9e052fbe2ea9111e62f3e7249c
  • Loading branch information
MarcoFalke authored and Munkybooty committed Aug 5, 2021
1 parent 858f924 commit cb2d124
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 31 deletions.
14 changes: 7 additions & 7 deletions src/rpc/blockchain.cpp
Expand Up @@ -344,12 +344,12 @@ static UniValue waitforblockheight(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"waitforblockheight <height> (timeout)\n"
"waitforblockheight height ( timeout )\n"
"\nWaits for (at least) block height and returns the height and hash\n"
"of the current tip.\n"
"\nReturns the current block on timeout or exit.\n"
"\nArguments:\n"
"1. height (required, int) Block height to wait for (int)\n"
"1. height (int, required) Block height 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"
Expand Down Expand Up @@ -776,11 +776,11 @@ static UniValue getblockheader(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"getblockheader \"hash\" ( verbose )\n"
"getblockheader \"blockhash\" ( verbose )\n"
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n"
"If verbose is true, returns an Object with information about blockheader <hash>.\n"
"\nArguments:\n"
"1. \"hash\" (string, required) The block hash\n"
"1. \"blockhash\" (string, required) The block hash\n"
"2. verbose (boolean, optional, default=true) true for a json object, false for the hex-encoded data\n"
"\nResult (for verbose = true):\n"
"{\n"
Expand Down Expand Up @@ -1107,7 +1107,7 @@ static UniValue pruneblockchain(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"pruneblockchain\n"
"pruneblockchain height\n"
"\nArguments:\n"
"1. \"height\" (numeric, required) The block height to prune up to. May be set to a discrete height, or a unix timestamp\n"
" to prune blocks whose block time is at least 2 hours older than the provided timestamp.\n"
Expand Down Expand Up @@ -1782,7 +1782,7 @@ static UniValue getchaintxstats(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() > 2)
throw std::runtime_error(
"getchaintxstats ( nblocks blockhash )\n"
"getchaintxstats ( nblocks \"blockhash\" )\n"
"\nCompute statistics about the total number and rate of transactions in the chain.\n"
"\nArguments:\n"
"1. nblocks (numeric, optional) Size of the window in number of blocks (default: one month).\n"
Expand Down Expand Up @@ -2342,7 +2342,7 @@ UniValue scantxoutset(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"scantxoutset <action> ( <scanobjects> )\n"
"scantxoutset \"action\" [scanobjects,...]\n"
"\nEXPERIMENTAL warning: this call may be removed or changed in future releases.\n"
"\nScans the unspent transaction output set for entries that match certain output descriptors.\n"
"Examples of output descriptors are:\n"
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/mining.cpp
Expand Up @@ -244,7 +244,7 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 2)
throw std::runtime_error(
"prioritisetransaction <txid> <fee delta>\n"
"prioritisetransaction \"txid\" fee_delta\n"
"Accepts the transaction into mined blocks at a higher (or lower) priority\n"
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction id.\n"
Expand Down Expand Up @@ -301,7 +301,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() > 1)
throw std::runtime_error(
"getblocktemplate ( TemplateRequest )\n"
"getblocktemplate ( \"template_request\" )\n"
"\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
"It returns data needed to construct a block to work on.\n"
"For full specification, see BIPs 22, 23, and 9:\n"
Expand Down
10 changes: 5 additions & 5 deletions src/rpc/net.cpp
Expand Up @@ -224,7 +224,7 @@ static UniValue addnode(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 2 ||
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
throw std::runtime_error(
"addnode \"node\" \"add|remove|onetry\"\n"
"addnode \"node\" \"command\"\n"
"\nAttempts to add or remove a node from the addnode list.\n"
"Or try a connection to a node once.\n"
"Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n"
Expand Down Expand Up @@ -267,13 +267,13 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() == 0 || request.params.size() >= 3)
throw std::runtime_error(
"disconnectnode \"[address]\" [nodeid]\n"
"disconnectnode ( \"address\" nodeid )\n"
"\nImmediately disconnects from the specified peer node.\n"
"\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n"
"\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n"
"\nArguments:\n"
"1. \"address\" (string, optional) The IP address/port of the node\n"
"2. \"nodeid\" (number, optional) The node ID (see getpeerinfo for node IDs)\n"
"2. nodeid (number, optional) The node ID (see getpeerinfo for node IDs)\n"
"\nExamples:\n"
+ HelpExampleCli("disconnectnode", "\"192.168.0.6:9999\"")
+ HelpExampleCli("disconnectnode", "\"\" 1")
Expand Down Expand Up @@ -545,7 +545,7 @@ static UniValue setban(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() < 2 ||
(strCommand != "add" && strCommand != "remove"))
throw std::runtime_error(
"setban \"subnet\" \"add|remove\" (bantime) (absolute)\n"
"setban \"subnet\" \"command\" ( bantime absolute )\n"
"\nAttempts to add or remove an IP/Subnet from the banned list.\n"
"\nArguments:\n"
"1. \"subnet\" (string, required) The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)\n"
Expand Down Expand Up @@ -671,7 +671,7 @@ static UniValue setnetworkactive(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 1) {
throw std::runtime_error(
"setnetworkactive true|false\n"
"setnetworkactive state\n"
"\nDisable/enable all p2p network activity.\n"
"\nArguments:\n"
"1. \"state\" (boolean, required) true to enable networking, false to disable\n"
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.cpp
Expand Up @@ -316,7 +316,7 @@ UniValue stop(const JSONRPCRequest& jsonRequest)

static UniValue uptime(const JSONRPCRequest& jsonRequest)
{
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
if (jsonRequest.fHelp || jsonRequest.params.size() > 0)
throw std::runtime_error(
"uptime\n"
"\nReturns the total uptime of the server.\n"
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/rpcdump.cpp
Expand Up @@ -314,7 +314,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)

if (request.fHelp || request.params.size() != 2)
throw std::runtime_error(
"importprunedfunds\n"
"importprunedfunds \"rawtransaction\" \"txoutproof\"\n"
"\nImports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n"
"\nArguments:\n"
"1. \"rawtransaction\" (string, required) A raw transaction in hex funding an already-existing address in wallet\n"
Expand Down Expand Up @@ -1293,8 +1293,8 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
// clang-format off
if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2)
throw std::runtime_error(
"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). Requires a new wallet backup.\n\n"
"importmulti \"requests\" ( \"options\" )\n"
"\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options). Requires a new wallet backup.\n\n"
"Arguments:\n"
"1. requests (array, required) Data to be imported\n"
" [ (array of json objects)\n"
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Expand Up @@ -924,7 +924,7 @@ static UniValue getbalance(const JSONRPCRequest& request)
"2. minconf (numeric, optional) Only include transactions confirmed at least this many times.\n"
" The default is 1 if an account is provided or 0 if no account is provided\n")
: std::string(
"getbalance ( \"(dummy)\" minconf addlocked include_watchonly )\n"
"getbalance ( \"dummy\" minconf addlocked include_watchonly )\n"
"\nReturns the total available balance.\n"
"The available balance is what the wallet considers currently spendable, and is\n"
"thus affected by options which limit spendability such as -spendzeroconfchange.\n"
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_pruning.py
Expand Up @@ -246,7 +246,7 @@ def height(index):
return index

def prune(index, expected_ret=None):
ret = node.pruneblockchain(height(index))
ret = node.pruneblockchain(height=height(index))
# Check the return value. When use_timestamp is True, just check
# that the return value is less than or equal to the expected
# value, because when more than one block is generated per second,
Expand Down
3 changes: 2 additions & 1 deletion test/functional/mining_basic.py
Expand Up @@ -23,9 +23,10 @@ def b2x(b):
def assert_template(node, block, expect, rehash=True):
if rehash:
block.hashMerkleRoot = block.calc_merkle_root()
rsp = node.getblocktemplate({'data': b2x(block.serialize()), 'mode': 'proposal'})
rsp = node.getblocktemplate(template_request={'data': b2x(block.serialize()), 'mode': 'proposal'})
assert_equal(rsp, expect)


class MiningTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p_disconnect_ban.py
Expand Up @@ -21,7 +21,7 @@ def run_test(self):

self.log.info("setban: successfully ban single IP address")
assert_equal(len(self.nodes[1].getpeerinfo()), 2) # node1 should have 2 connections to node0 at this point
self.nodes[1].setban("127.0.0.1", "add")
self.nodes[1].setban(subnet="127.0.0.1", command="add")
wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 0, timeout=10)
assert_equal(len(self.nodes[1].getpeerinfo()), 0) # all nodes must be disconnected at this point
assert_equal(len(self.nodes[1].listbanned()), 1)
Expand Down
6 changes: 3 additions & 3 deletions test/functional/rpc_blockchain.py
Expand Up @@ -142,7 +142,7 @@ def _test_getchaintxstats(self):
assert_raises_rpc_error(-8, "Block is not in main chain", self.nodes[0].getchaintxstats, blockhash=blockhash)
self.nodes[0].reconsiderblock(blockhash)

chaintxstats = self.nodes[0].getchaintxstats(1)
chaintxstats = self.nodes[0].getchaintxstats(nblocks=1)
# 200 txs plus genesis tx
assert_equal(chaintxstats['txcount'], 201)
# tx rate should be 1 per ~2.6 minutes (156 seconds), or 1/156
Expand Down Expand Up @@ -219,7 +219,7 @@ def _test_getblockheader(self):

besthash = node.getbestblockhash()
secondbesthash = node.getblockhash(199)
header = node.getblockheader(besthash)
header = node.getblockheader(blockhash=besthash)

assert_equal(header['hash'], besthash)
assert_equal(header['height'], 200)
Expand Down Expand Up @@ -303,7 +303,7 @@ def solve_and_send_block(prevhash, height, time):

def assert_waitforheight(height, timeout=2):
assert_equal(
node.waitforblockheight(height, timeout)['height'],
node.waitforblockheight(height=height, timeout=timeout)['height'],
current_height)

assert_waitforheight(0)
Expand Down
6 changes: 3 additions & 3 deletions test/functional/rpc_net.py
Expand Up @@ -72,13 +72,13 @@ def _test_getnetworkinginfo(self):
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)

self.nodes[0].setnetworkactive(False)
self.nodes[0].setnetworkactive(state=False)
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False)
# Wait a bit for all sockets to close
wait_until(lambda: self.nodes[0].getnetworkinfo()['connections'] == 0, timeout=3)
wait_until(lambda: self.nodes[1].getnetworkinfo()['connections'] == 0, timeout=3)

self.nodes[0].setnetworkactive(True)
self.nodes[0].setnetworkactive(state=True)
connect_nodes_bi(self.nodes, 0, 1)
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
Expand All @@ -87,7 +87,7 @@ def _test_getaddednodeinfo(self):
assert_equal(self.nodes[0].getaddednodeinfo(), [])
# add a node (node2) to node0
ip_port = "127.0.0.1:{}".format(p2p_port(2))
self.nodes[0].addnode(ip_port, 'add')
self.nodes[0].addnode(node=ip_port, command='add')
# check that the node has indeed been added
added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
assert_equal(len(added_nodes), 1)
Expand Down
4 changes: 2 additions & 2 deletions test/functional/wallet_importmulti.py
Expand Up @@ -129,7 +129,7 @@ def run_test (self):
"pubkeys": [ address['pubkey'] ],
"internal": True
}]
result = self.nodes[1].importmulti(request)
result = self.nodes[1].importmulti(requests=request)
assert_equal(result[0]['success'], True)
address_assert = self.nodes[1].getaddressinfo(address['address'])
assert_equal(address_assert['iswatchonly'], True)
Expand All @@ -144,7 +144,7 @@ def run_test (self):
"timestamp": "now",
"pubkeys": [ address['pubkey'] ]
}]
result = self.nodes[1].importmulti(request)
result = self.nodes[1].importmulti(requests=request)
assert_equal(result[0]['success'], False)
assert_equal(result[0]['error']['code'], -8)
assert_equal(result[0]['error']['message'], 'Internal must be set to true for nonstandard scriptPubKey imports.')
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_importprunedfunds.py
Expand Up @@ -78,7 +78,7 @@ def run_test(self):

# Import with affiliated address with no rescan
self.nodes[1].importaddress(address=address2, rescan=False)
self.nodes[1].importprunedfunds(rawtxn2, proof2)
self.nodes[1].importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2)
assert [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid2]

# Import with private key with no rescan
Expand Down

0 comments on commit cb2d124

Please sign in to comment.