| 192 | |
| 193 | |
| 194 | RPCHelpMan getbalance() |
| 195 | { |
| 196 | return RPCHelpMan{"getbalance", |
| 197 | "\nReturns the total available balance.\n" |
| 198 | "The available balance is what the wallet considers currently spendable, and is\n" |
| 199 | "thus affected by options which limit spendability such as -spendzeroconfchange.\n", |
| 200 | { |
| 201 | {"dummy", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Remains for backward compatibility. Must be excluded or set to \"*\"."}, |
| 202 | {"minconf", RPCArg::Type::NUM, RPCArg::Default{0}, "Only include transactions confirmed at least this many times."}, |
| 203 | {"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also include balance in watch-only addresses (see 'importaddress')"}, |
| 204 | {"avoid_reuse", RPCArg::Type::BOOL, RPCArg::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."}, |
| 205 | {"assetlabel", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Hex asset id or asset label for balance."}, |
| 206 | }, |
| 207 | { |
| 208 | RPCResult{RPCResult::Type::OBJ, "amount_map", "The total amount, per asset if none is specified, in " + CURRENCY_UNIT + " received for this wallet.", |
| 209 | { |
| 210 | {RPCResult::Type::ELISION, "", "the amount for each asset"}, |
| 211 | }}, |
| 212 | RPCResult{RPCResult::Type::NUM, "amount", "the total amount for the asset, if one is specified"}, |
| 213 | RPCResult{RPCResult::Type::NONE, "", ""}, // in case the wallet is disabled |
| 214 | }, |
| 215 | RPCExamples{ |
| 216 | "\nThe total amount in the wallet with 0 or more confirmations\n" |
| 217 | + HelpExampleCli("getbalance", "") + |
| 218 | "\nThe total amount in the wallet with at least 6 confirmations\n" |
| 219 | + HelpExampleCli("getbalance", "\"*\" 6") + |
| 220 | "\nAs a JSON-RPC call\n" |
| 221 | + HelpExampleRpc("getbalance", "\"*\", 6") |
| 222 | }, |
| 223 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 224 | { |
| 225 | const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request); |
| 226 | if (!pwallet) return NullUniValue; |
| 227 | |
| 228 | // Make sure the results are valid at least up to the most recent block |
| 229 | // the user could have gotten from another RPC command prior to now |
| 230 | pwallet->BlockUntilSyncedToCurrentChain(); |
| 231 | |
| 232 | LOCK(pwallet->cs_wallet); |
| 233 | |
| 234 | const UniValue& dummy_value = request.params[0]; |
| 235 | if (!dummy_value.isNull() && dummy_value.get_str() != "*") { |
| 236 | throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\"."); |
| 237 | } |
| 238 | |
| 239 | int min_depth = 0; |
| 240 | if (!request.params[1].isNull()) { |
| 241 | min_depth = request.params[1].get_int(); |
| 242 | } |
| 243 | |
| 244 | bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet); |
| 245 | |
| 246 | bool avoid_reuse = GetAvoidReuseFlag(*pwallet, request.params[3]); |
| 247 | |
| 248 | std::string asset = ""; |
| 249 | if (!request.params[4].isNull() && request.params[4].isStr()) { |
| 250 | asset = request.params[4].get_str(); |
| 251 | } |
nothing calls this directly
no test coverage detected