| 140 | |
| 141 | |
| 142 | RPCHelpMan getreceivedbylabel() |
| 143 | { |
| 144 | return RPCHelpMan{"getreceivedbylabel", |
| 145 | "\nReturns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.\n", |
| 146 | { |
| 147 | {"label", RPCArg::Type::STR, RPCArg::Optional::NO, "The selected label, may be the default label using \"\"."}, |
| 148 | {"minconf", RPCArg::Type::NUM, RPCArg::Default{1}, "Only include transactions confirmed at least this many times."}, |
| 149 | {"assetlabel", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Hex asset id or asset label for balance."}, |
| 150 | {"include_immature_coinbase", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include immature coinbase transactions."}, |
| 151 | }, |
| 152 | { |
| 153 | RPCResult{RPCResult::Type::OBJ, "amount_map", "The total amount, per asset if none is specified, in " + CURRENCY_UNIT + " received for this wallet.", |
| 154 | { |
| 155 | {RPCResult::Type::ELISION, "", "the amount for each asset"}, |
| 156 | }}, |
| 157 | RPCResult{RPCResult::Type::NUM, "amount", "the total amount for the asset, if one is specified"}, |
| 158 | RPCResult{RPCResult::Type::NONE, "", ""}, // in case the wallet is disabled |
| 159 | }, |
| 160 | RPCExamples{ |
| 161 | "\nAmount received by the default label with at least 1 confirmation\n" |
| 162 | + HelpExampleCli("getreceivedbylabel", "\"\"") + |
| 163 | "\nAmount received at the tabby label including unconfirmed amounts with zero confirmations\n" |
| 164 | + HelpExampleCli("getreceivedbylabel", "\"tabby\" 0") + |
| 165 | "\nThe amount with at least 6 confirmations\n" |
| 166 | + HelpExampleCli("getreceivedbylabel", "\"tabby\" 6") + |
| 167 | "\nThe amount with at least 6 confirmations including immature coinbase outputs\n" |
| 168 | + HelpExampleCli("getreceivedbylabel", "\"tabby\" 6 true") + |
| 169 | "\nAs a JSON-RPC call\n" |
| 170 | + HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6, true") |
| 171 | }, |
| 172 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 173 | { |
| 174 | const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request); |
| 175 | if (!pwallet) return NullUniValue; |
| 176 | |
| 177 | // Make sure the results are valid at least up to the most recent block |
| 178 | // the user could have gotten from another RPC command prior to now |
| 179 | pwallet->BlockUntilSyncedToCurrentChain(); |
| 180 | |
| 181 | LOCK(pwallet->cs_wallet); |
| 182 | |
| 183 | std::string asset = ""; |
| 184 | if (request.params.size() > 2 && request.params[2].isStr()) { |
| 185 | asset = request.params[2].get_str(); |
| 186 | } |
| 187 | |
| 188 | return AmountMapToUniv(GetReceived(*pwallet, request.params, /* by_label */ true), asset); |
| 189 | }, |
| 190 | }; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | RPCHelpMan getbalance() |
nothing calls this directly
no test coverage detected