Skip to content

Commit 3d2ff37

Browse files
committed
wallet/rpc: use static help text
Always show the same help topic regardless of wallet flags, and explain that something is not always available, rather than runtime-modifying the help output.
1 parent 53c3c1e commit 3d2ff37

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
383383
" \"UNSET\"\n"
384384
" \"ECONOMICAL\"\n"
385385
" \"CONSERVATIVE\""},
386-
{"avoid_reuse", RPCArg::Type::BOOL, /* default */ pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) ? "true" : "unavailable", "Avoid spending from dirty addresses; addresses are considered\n"
386+
{"avoid_reuse", RPCArg::Type::BOOL, /* default */ "true", "(only available if avoid_reuse wallet flag is set) Avoid spending from dirty addresses; addresses are considered\n"
387387
" dirty if they have previously been used in a transaction."},
388388
},
389389
RPCResult{
@@ -743,7 +743,7 @@ static UniValue getbalance(const JSONRPCRequest& request)
743743
{"dummy", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Remains for backward compatibility. Must be excluded or set to \"*\"."},
744744
{"minconf", RPCArg::Type::NUM, /* default */ "0", "Only include transactions confirmed at least this many times."},
745745
{"include_watchonly", RPCArg::Type::BOOL, /* default */ "false", "Also include balance in watch-only addresses (see 'importaddress')"},
746-
{"avoid_reuse", RPCArg::Type::BOOL, /* default */ pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) ? "true" : "unavailable", "Do not include balance in dirty outputs; addresses are considered dirty if they have previously been used in a transaction."},
746+
{"avoid_reuse", RPCArg::Type::BOOL, /* default */ "true", "(only available if avoid_reuse wallet flag is set) Do not include balance in dirty outputs; addresses are considered dirty if they have previously been used in a transaction."},
747747
},
748748
RPCResult{
749749
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this wallet.\n"
@@ -2892,11 +2892,8 @@ static UniValue listunspent(const JSONRPCRequest& request)
28922892
return NullUniValue;
28932893
}
28942894

2895-
bool avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE);
2896-
2897-
if (request.fHelp || request.params.size() > 5)
2898-
throw std::runtime_error(
2899-
RPCHelpMan{"listunspent",
2895+
const RPCHelpMan help{
2896+
"listunspent",
29002897
"\nReturns array of unspent transaction outputs\n"
29012898
"with between minconf and maxconf (inclusive) confirmations.\n"
29022899
"Optionally filter to only include txouts paid to specified addresses.\n",
@@ -2933,9 +2930,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
29332930
" \"witnessScript\" : \"script\" (string) witnessScript if the scriptPubKey is P2WSH or P2SH-P2WSH\n"
29342931
" \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
29352932
" \"solvable\" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
2936-
+ (avoid_reuse ?
2937-
" \"reused\" : xxx, (bool) Whether this output is reused/dirty (sent to an address that was previously spent from)\n" :
2938-
"") +
2933+
" \"reused\" : xxx, (bool) (only present if avoid_reuse is set) Whether this output is reused/dirty (sent to an address that was previously spent from)\n"
29392934
" \"desc\" : xxx, (string, only when solvable) A descriptor for spending this output\n"
29402935
" \"safe\" : xxx (bool) Whether this output is considered safe to spend. Unconfirmed transactions\n"
29412936
" from outside keys and unconfirmed replacement transactions are considered unsafe\n"
@@ -2951,7 +2946,11 @@ static UniValue listunspent(const JSONRPCRequest& request)
29512946
+ HelpExampleCli("listunspent", "6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'")
29522947
+ HelpExampleRpc("listunspent", "6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")
29532948
},
2954-
}.ToString());
2949+
};
2950+
2951+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
2952+
throw std::runtime_error(help.ToString());
2953+
}
29552954

29562955
int nMinDepth = 1;
29572956
if (!request.params[0].isNull()) {
@@ -3024,6 +3023,8 @@ static UniValue listunspent(const JSONRPCRequest& request)
30243023

30253024
LOCK(pwallet->cs_wallet);
30263025

3026+
const bool avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE);
3027+
30273028
for (const COutput& out : vecOutputs) {
30283029
CTxDestination address;
30293030
const CScript& scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;

0 commit comments

Comments
 (0)