| 88 | |
| 89 | |
| 90 | RPCHelpMan getreceivedbyaddress() |
| 91 | { |
| 92 | return RPCHelpMan{"getreceivedbyaddress", |
| 93 | "\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n", |
| 94 | { |
| 95 | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address for transactions."}, |
| 96 | {"minconf", RPCArg::Type::NUM, RPCArg::Default{1}, "Only include transactions confirmed at least this many times."}, |
| 97 | {"assetlabel", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Hex asset id or asset label for balance."}, |
| 98 | {"include_immature_coinbase", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include immature coinbase transactions."}, |
| 99 | }, |
| 100 | { |
| 101 | RPCResult{RPCResult::Type::OBJ, "amount_map", "The total amount, per asset if none is specified, in " + CURRENCY_UNIT + " received for this wallet.", |
| 102 | { |
| 103 | {RPCResult::Type::ELISION, "", "the amount for each asset"}, |
| 104 | }}, |
| 105 | RPCResult{RPCResult::Type::NUM, "amount", "the total amount for the asset, if one is specified"}, |
| 106 | RPCResult{RPCResult::Type::NONE, "", ""}, // in case the wallet is disabled |
| 107 | }, |
| 108 | RPCExamples{ |
| 109 | "\nThe amount from transactions with at least 1 confirmation\n" |
| 110 | + HelpExampleCli("getreceivedbyaddress", "\"" + EXAMPLE_ADDRESS[0] + "\"") + |
| 111 | "\nThe amount including unconfirmed transactions, zero confirmations\n" |
| 112 | + HelpExampleCli("getreceivedbyaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0") + |
| 113 | "\nThe amount with at least 6 confirmations\n" |
| 114 | + HelpExampleCli("getreceivedbyaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 6") + |
| 115 | "\nThe amount with at least 6 confirmations including immature coinbase outputs\n" |
| 116 | + HelpExampleCli("getreceivedbyaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 6 true") + |
| 117 | "\nAs a JSON-RPC call\n" |
| 118 | + HelpExampleRpc("getreceivedbyaddress", "\"" + EXAMPLE_ADDRESS[0] + "\", 6") |
| 119 | }, |
| 120 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 121 | { |
| 122 | const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request); |
| 123 | if (!pwallet) return NullUniValue; |
| 124 | |
| 125 | // Make sure the results are valid at least up to the most recent block |
| 126 | // the user could have gotten from another RPC command prior to now |
| 127 | pwallet->BlockUntilSyncedToCurrentChain(); |
| 128 | |
| 129 | LOCK(pwallet->cs_wallet); |
| 130 | |
| 131 | std::string asset = ""; |
| 132 | if (request.params.size() > 2 && request.params[2].isStr()) { |
| 133 | asset = request.params[2].get_str(); |
| 134 | } |
| 135 | |
| 136 | return AmountMapToUniv(GetReceived(*pwallet, request.params, /* by_label */ false), asset); |
| 137 | }, |
| 138 | }; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | RPCHelpMan getreceivedbylabel() |
nothing calls this directly
no test coverage detected