Skip to content

Commit

Permalink
Further RPC help output cleanups
Browse files Browse the repository at this point in the history
- Make sure we're indicating when a command requires the wallet to be
unlocked.
- Add whitespace lines to improve readability between description,
arguments, results, and examples
- Remove duplicate/errant Result lines in `getsaplingnotescount`

Github-Pull: #2097
Rebased-From: 58e64b1
  • Loading branch information
Fuzzbawls committed Dec 27, 2020
1 parent 2c315a3 commit 85d83b1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,19 @@ UniValue importsaplingkey(const JSONRPCRequest& request)
throw std::runtime_error(
"importsaplingkey \"key\" ( rescan startHeight )\n"
"\nAdds a key (as returned by exportsaplingkey) to your wallet.\n"
+ HelpRequiringPassphrase() + "\n"

"\nArguments:\n"
"1. \"key\" (string, required) The zkey (see exportsaplingkey)\n"
"2. rescan (string, optional, default=\"whenkeyisnew\") Rescan the wallet for transactions - can be \"yes\", \"no\" or \"whenkeyisnew\"\n"
"3. startHeight (numeric, optional, default=0) Block height to start rescan from\n"
"\nNote: This call can take minutes to complete if rescan is true.\n"

"\nResult:\n"
"{\n"
" \"address\" : \"address|DefaultAddress\", (string) The address corresponding to the spending key (the default address).\n"
"}\n"

"\nExamples:\n"
"\nExport a zkey\n"
+ HelpExampleCli("exportsaplingkey", "\"myaddress\"") +
Expand Down Expand Up @@ -790,15 +794,19 @@ UniValue importsaplingviewingkey(const JSONRPCRequest& request)
throw std::runtime_error(
"importsaplingviewingkey \"vkey\" ( rescan startHeight )\n"
"\nAdds a viewing key (as returned by exportsaplingviewingkey) to your wallet.\n"
+ HelpRequiringPassphrase() + "\n"

"\nArguments:\n"
"1. \"vkey\" (string, required) The viewing key (see exportsaplingviewingkey)\n"
"2. rescan (string, optional, default=\"whenkeyisnew\") Rescan the wallet for transactions - can be \"yes\", \"no\" or \"whenkeyisnew\"\n"
"3. startHeight (numeric, optional, default=0) Block height to start rescan from\n"
"\nNote: This call can take minutes to complete if rescan is true.\n"

"\nResult:\n"
"{\n"
" \"address\" : \"address|DefaultAddress\", (string) The address corresponding to the viewing key (for Sapling, this is the default address).\n"
"}\n"

"\nExamples:\n"
"\nImport a viewing key\n"
+ HelpExampleCli("importsaplingviewingkey", "\"vkey\"") +
Expand Down Expand Up @@ -880,10 +888,14 @@ UniValue exportsaplingviewingkey(const JSONRPCRequest& request)
"exportsaplingviewingkey \"shielded_addr\"\n"
"\nReveals the viewing key corresponding to 'shielded addr'.\n"
"Then the importsaplingviewingkey can be used with this output\n"
+ HelpRequiringPassphrase() + "\n"

"\nArguments:\n"
"1. \"shielded_addr\" (string, required) The shielded addr for the viewing key\n"

"\nResult:\n"
"\"vkey\" (string) The viewing key\n"

"\nExamples:\n"
+ HelpExampleCli("exportsaplingviewingkey", "\"myaddress\"")
+ HelpExampleRpc("exportsaplingviewingkey", "\"myaddress\"")
Expand Down Expand Up @@ -915,10 +927,14 @@ UniValue exportsaplingkey(const JSONRPCRequest& request)
"exportsaplingkey \"shielded addr\"\n"
"\nReveals the key corresponding to the 'shielded addr'.\n"
"Then the importsaplingkey can be used with this output\n"
+ HelpRequiringPassphrase() + "\n"

"\nArguments:\n"
"1. \"addr\" (string, required) The shielded addr for the private key\n"

"\nResult:\n"
"\"key\" (string) The private key\n"

"\nExamples:\n"
+ HelpExampleCli("exportsaplingkey", "\"myaddress\"")
+ HelpExampleRpc("exportsaplingkey", "\"myaddress\"")
Expand Down
30 changes: 23 additions & 7 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,11 @@ UniValue getnewshieldaddress(const JSONRPCRequest& request)
throw std::runtime_error(
"getnewshieldaddress\n"
"\nReturns a new shield address for receiving payments.\n"
"\nArguments:\n"
+ HelpRequiringPassphrase() + "\n"

"\nResult:\n"
"\"address\" (string) The new shield address.\n"

"\nExamples:\n"
+ HelpExampleCli("getnewshieldaddress", "")
+ HelpExampleRpc("getnewshieldaddress", "")
Expand All @@ -532,6 +534,7 @@ UniValue listshieldunspent(const JSONRPCRequest& request)
"\nReturns array of unspent shield notes with between minconf and maxconf (inclusive) confirmations.\n"
"Optionally filter to only include notes sent to specified addresses.\n"
"When minconf is 0, unspent notes with zero confirmations are returned, even though they are not immediately spendable.\n"

"\nArguments:\n"
"1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n"
"2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
Expand All @@ -541,6 +544,7 @@ UniValue listshieldunspent(const JSONRPCRequest& request)
" \"address\" (string) shield addr\n"
" ,...\n"
" ]\n"

"\nResult:\n"
"[ (array of json object)\n"
" {\n"
Expand Down Expand Up @@ -808,13 +812,16 @@ UniValue listshieldaddresses(const JSONRPCRequest& request)
throw std::runtime_error(
"listshieldaddresses ( includeWatchonly )\n"
"\nReturns the list of shield addresses belonging to the wallet.\n"

"\nArguments:\n"
"1. includeWatchonly (bool, optional, default=false) Also include watchonly addresses (see 'importviewingkey')\n"

"\nResult:\n"
"[ (json array of string)\n"
" \"addr\" (string) a shield address belonging to the wallet\n"
" ,...\n"
"]\n"

"\nExamples:\n"
+ HelpExampleCli("listshieldaddresses", "")
+ HelpExampleRpc("listshieldaddresses", "")
Expand Down Expand Up @@ -1308,12 +1315,15 @@ UniValue getshieldbalance(const JSONRPCRequest& request)
"\nCAUTION: If the wallet contains any addresses for which it only has incoming viewing keys,"
"\nthe returned private balance may be larger than the actual balance, because spends cannot"
"\nbe detected with incoming viewing keys.\n"

"\nArguments:\n"
"1. \"address\" (string, optional) The selected address. If non empty nor \"*\", it must be a Sapling address\n"
"2. minconf (numeric, optional, default=1) Only include private and transparent transactions confirmed at least this many times.\n"
"3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress' and 'importsaplingviewingkey')\n"

"\nResult:\n"
"amount (numeric) the total balance of shield funds (in Sapling addresses)\n"

"\nExamples:\n"
"\nThe total amount in the wallet\n"
+ HelpExampleCli("getshieldbalance", "")
Expand Down Expand Up @@ -1352,7 +1362,7 @@ UniValue viewshieldtransaction(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"viewshieldtransaction \"txid\"\n"
"\nGet detailed shield information about in-wallet transaction <txid>\n"
"\nGet detailed shield information about in-wallet transaction \"txid\"\n"
+ HelpRequiringPassphrase() + "\n"
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction id\n"
Expand Down Expand Up @@ -2170,6 +2180,8 @@ UniValue sendmany(const JSONRPCRequest& request)
HelpExampleRpc("sendmany", "\"\", \"{\\\"DMJRSsuU9zfyrvxVaAEFQqK4MxZg6vgeS6\\\":0.01,\\\"DAD3Y6ivr8nPQLT1NEPX84DxGCw9jz9Jvg\\\":0.02}\", 6, \"testing\"")
);

EnsureWalletIsUnlocked();

// Read Params
if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
Expand Down Expand Up @@ -2439,9 +2451,11 @@ UniValue listreceivedbyshieldaddress(const JSONRPCRequest& request)
throw std::runtime_error(
"listreceivedbyshieldaddress \"address\" ( minconf )\n"
"\nReturn a list of amounts received by a shield addr belonging to the node's wallet.\n"

"\nArguments:\n"
"1. \"address\" (string) The private address.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"

"\nResult:\n"
"{\n"
" \"txid\": \"txid\", (string) the transaction id\n"
Expand All @@ -2454,6 +2468,7 @@ UniValue listreceivedbyshieldaddress(const JSONRPCRequest& request)
" \"outindex\" (sapling) : n, (numeric) the output index\n"
" \"change\": true|false, (boolean) true if the address that received the note is also one of the sending addresses\n"
"}\n"

"\nExamples:\n"
+ HelpExampleCli("listreceivedbyshieldaddress", "\"ps1ra969yfhvhp73rw5ak2xvtcm9fkuqsnmad7qln79mphhdrst3lwu9vvv03yuyqlh42p42st47qd\"")
+ HelpExampleRpc("listreceivedbyshieldaddress", "\"ps1ra969yfhvhp73rw5ak2xvtcm9fkuqsnmad7qln79mphhdrst3lwu9vvv03yuyqlh42p42st47qd\"")
Expand Down Expand Up @@ -2904,7 +2919,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"gettransaction \"txid\" ( includeWatchonly )\n"
"\nGet detailed information about in-wallet transaction <txid>\n"
"\nGet detailed information about in-wallet transaction \"txid\"\n"

"\nArguments:\n"
"1. \"txid\" (string, required) The transaction id\n"
Expand Down Expand Up @@ -2980,7 +2995,7 @@ UniValue abandontransaction(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"abandontransaction \"txid\"\n"
"\nMark in-wallet transaction <txid> as abandoned\n"
"\nMark in-wallet transaction \"txid\" as abandoned\n"
"This will mark this transaction and all its in-wallet descendants as abandoned which will allow\n"
"for their inputs to be respent. It can be used to replace \"stuck\" or evicted transactions.\n"
"It only works on transactions which are not included in a block and are not currently in the mempool.\n"
Expand Down Expand Up @@ -4050,20 +4065,21 @@ UniValue getsaplingnotescount(const JSONRPCRequest& request)
throw std::runtime_error(
"getsaplingnotescount ( minconf )\n"
"Returns the number of sapling notes available in the wallet.\n"

"\nArguments:\n"
"1. minconf (numeric, optional, default=1) Only include notes in transactions confirmed at least this many times.\n"
"\nResult:\n"

"\nResult:\n"
"num (numeric) the number of sapling notes in the wallet\n"
"}\n"

"\nExamples:\n"
+ HelpExampleCli("getsaplingnotescount", "0")
+ HelpExampleRpc("getsaplingnotescount", "0")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

int nMinDepth = request.params.size() > 0 ? request.params[0].get_int() : 1;
int nMinDepth = !request.params.empty() ? request.params[0].get_int() : 1;
int count = 0;
for (const auto& wtx : pwalletMain->mapWallet) {
if (wtx.second.GetDepthInMainChain() >= nMinDepth) {
Expand Down

0 comments on commit 85d83b1

Please sign in to comment.