MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / getreceivedbylabel

Function getreceivedbylabel

src/wallet/rpcwallet.cpp:784–853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782
783
784static UniValue getreceivedbylabel(const JSONRPCRequest& request)
785{
786 std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
787 CWallet* const pwallet = wallet.get();
788
789 if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
790 return NullUniValue;
791 }
792
793 if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "getreceivedbyaccount") {
794 if (request.fHelp) {
795 throw std::runtime_error("getreceivedbyaccount (Deprecated, will be removed in V0.18. To use this command, start bgoldd with -deprecatedrpc=accounts)");
796 }
797 throw JSONRPCError(RPC_METHOD_DEPRECATED, "getreceivedbyaccount is deprecated and will be removed in V0.18. To use this command, start bgoldd with -deprecatedrpc=accounts.");
798 }
799
800 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
801 throw std::runtime_error(
802 "getreceivedbylabel \"label\" ( minconf )\n"
803 "\nReturns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.\n"
804 "\nArguments:\n"
805 "1. \"label\" (string, required) The selected label, may be the default label using \"\".\n"
806 "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
807 "\nResult:\n"
808 "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this label.\n"
809 "\nExamples:\n"
810 "\nAmount received by the default label with at least 1 confirmation\n"
811 + HelpExampleCli("getreceivedbylabel", "\"\"") +
812 "\nAmount received at the tabby label including unconfirmed amounts with zero confirmations\n"
813 + HelpExampleCli("getreceivedbylabel", "\"tabby\" 0") +
814 "\nThe amount with at least 6 confirmations\n"
815 + HelpExampleCli("getreceivedbylabel", "\"tabby\" 6") +
816 "\nAs a json rpc call\n"
817 + HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6")
818 );
819
820 // Make sure the results are valid at least up to the most recent block
821 // the user could have gotten from another RPC command prior to now
822 pwallet->BlockUntilSyncedToCurrentChain();
823
824 LOCK2(cs_main, pwallet->cs_wallet);
825
826 // Minimum confirmations
827 int nMinDepth = 1;
828 if (!request.params[1].isNull())
829 nMinDepth = request.params[1].get_int();
830
831 // Get the set of pub keys assigned to label
832 std::string label = LabelFromValue(request.params[0]);
833 std::set<CTxDestination> setAddress = pwallet->GetLabelAddresses(label);
834
835 // Tally
836 CAmount nAmount = 0;
837 for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
838 const CWalletTx& wtx = pairWtx.second;
839 if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
840 continue;
841

Callers

nothing calls this directly

Calls 15

EnsureWalletIsAvailableFunction · 0.85
IsDeprecatedRPCEnabledFunction · 0.85
JSONRPCErrorFunction · 0.85
HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
LabelFromValueFunction · 0.85
CheckFinalTxFunction · 0.85
ExtractDestinationFunction · 0.85
IsMineFunction · 0.85
ValueFromAmountFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected