From 89306ab0df93bfdf5630910bc20b1eccb7379172 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Sat, 6 Oct 2018 00:48:23 -0400 Subject: [wallet] Restore ability to list incoming transactions by label Backport of PR 14411 to v0.17. This change partially reverts #13075 and #14023. Fixes #14382 --- src/wallet/rpcwallet.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bb7ceb424c..a3de618059 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1805,9 +1805,14 @@ static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, const bool fAllAccounts = (strAccount == std::string("*")); bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY); + bool list_sent = fAllAccounts; + + if (IsDeprecatedRPCEnabled("accounts")) { + list_sent |= strAccount == strSentAccount; + } + // Sent - if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) - { + if (list_sent) { for (const COutputEntry& s : listSent) { UniValue entry(UniValue::VOBJ); @@ -1901,12 +1906,14 @@ UniValue listtransactions(const JSONRPCRequest& request) std::string help_text {}; if (!IsDeprecatedRPCEnabled("accounts")) { - help_text = "listtransactions (dummy count skip include_watchonly)\n" - "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n" + help_text = "listtransactions (label count skip include_watchonly)\n" + "\nIf a label name is provided, this will return only incoming transactions paying to addresses with the specified label.\n" + "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions.\n" "Note that the \"account\" argument and \"otheraccount\" return value have been removed in V0.17. To use this RPC with an \"account\" argument, restart\n" "bitcoind with -deprecatedrpc=accounts\n" "\nArguments:\n" - "1. \"dummy\" (string, optional) If set, should be \"*\" for backwards compatibility.\n" + "1. \"label\" (string, optional) If set, should be a valid label name to return only incoming transactions\n" + " with the specified label, or \"*\" to disable filtering and return all transactions.\n" "2. count (numeric, optional, default=10) The number of transactions to return\n" "3. skip (numeric, optional, default=0) The number of transactions to skip\n" "4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n" @@ -2012,8 +2019,8 @@ UniValue listtransactions(const JSONRPCRequest& request) std::string strAccount = "*"; if (!request.params[0].isNull()) { strAccount = request.params[0].get_str(); - if (!IsDeprecatedRPCEnabled("accounts") && strAccount != "*") { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"*\""); + if (!IsDeprecatedRPCEnabled("accounts") && strAccount.empty()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Label argument must be a valid label name or \"*\"."); } } int nCount = 10; @@ -4801,7 +4808,7 @@ static const CRPCCommand commands[] = { "wallet", "listlockunspent", &listlockunspent, {} }, { "wallet", "listreceivedbyaddress", &listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} }, { "wallet", "listsinceblock", &listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} }, - { "wallet", "listtransactions", &listtransactions, {"account|dummy","count","skip","include_watchonly"} }, + { "wallet", "listtransactions", &listtransactions, {"account|label|dummy","count","skip","include_watchonly"} }, { "wallet", "listunspent", &listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, { "wallet", "listwallets", &listwallets, {} }, { "wallet", "loadwallet", &loadwallet, {"filename"} }, -- cgit v1.2.3