Return the correct error for `z_getbalance` if a UA does not correspond to an account in the wallet..

Also, update the help text for z_getbalance to suggest that the user
prefer z_getbalanceforviewingkey.

Co-authored-by: str4d <thestr4d@gmail.com>
This commit is contained in:
Kris Nuttycombe 2022-03-15 16:17:46 -06:00 committed by Kris Nuttycombe
parent 1cd92e579c
commit 482f0e7e44
1 changed files with 6 additions and 2 deletions

View File

@ -3649,11 +3649,10 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
if (fHelp || params.size() == 0 || params.size() > 3)
throw runtime_error(
"z_getbalance \"address\" ( minconf inZat )\n"
"\nDEPRECATED\n"
"\nDEPRECATED; please use z_getbalanceforviewingkey instead.`\n"
"\nReturns the balance of a taddr or zaddr belonging to the node's wallet.\n"
"\nCAUTION: If the wallet has only an incoming viewing key for this address, then spends cannot be"
"\ndetected, and so the returned balance may be larger than the actual balance."
"\nThe argument address may not be a Unified Address; please use z_getbalanceforviewingkey instead.\n"
"\nArguments:\n"
"1. \"address\" (string) The selected address. It may be a transparent or shielded address.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
@ -3707,6 +3706,11 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
},
[&](const libzcash::UnifiedAddress& addr) {
auto selector = pwalletMain->ZTXOSelectorForAddress(addr, true);
if (!selector.has_value()) {
throw JSONRPCError(
RPC_INVALID_ADDRESS_OR_KEY,
"Unified address does not correspond to an account in the wallet");
}
auto spendableInputs = pwalletMain->FindSpendableInputs(selector.value(), true, nMinDepth);
for (const auto& t : spendableInputs.utxos) {