@@ -1267,8 +1267,9 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
12671267 * @param fLong Whether to include the JSON version of the transaction.
12681268 * @param ret The UniValue into which the result is stored.
12691269 * @param filter The "is mine" filter bool.
1270+ * @param filter_label Optional label string to filter incoming transactions.
12701271 */
1271- static void ListTransactions (interfaces::Chain::Lock& locked_chain, CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong , UniValue& ret, const isminefilter& filter)
1272+ static void ListTransactions (interfaces::Chain::Lock& locked_chain, CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong , UniValue& ret, const isminefilter& filter, const std::string* filter_label )
12721273{
12731274 CAmount nFee;
12741275 std::list<COutputEntry> listReceived;
@@ -1279,7 +1280,7 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* con
12791280 bool involvesWatchonly = wtx.IsFromMe (ISMINE_WATCH_ONLY);
12801281
12811282 // Sent
1282- if ((!listSent. empty () || nFee != 0 ) )
1283+ if (!filter_label )
12831284 {
12841285 for (const COutputEntry& s : listSent)
12851286 {
@@ -1311,6 +1312,9 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* con
13111312 if (pwallet->mapAddressBook .count (r.destination )) {
13121313 label = pwallet->mapAddressBook [r.destination ].name ;
13131314 }
1315+ if (filter_label && label != *filter_label) {
1316+ continue ;
1317+ }
13141318 UniValue entry (UniValue::VOBJ);
13151319 if (involvesWatchonly || (::IsMine (*pwallet, r.destination ) & ISMINE_WATCH_ONLY)) {
13161320 entry.pushKV (" involvesWatchonly" , true );
@@ -1352,10 +1356,12 @@ UniValue listtransactions(const JSONRPCRequest& request)
13521356
13531357 if (request.fHelp || request.params .size () > 4 )
13541358 throw std::runtime_error (
1355- " listtransactions ( \" dummy\" count skip include_watchonly)\n "
1359+ " listtransactions ( \" label\" count skip include_watchonly )\n "
1360+ " \n If a label name is provided, this will return only incoming transactions paying to addresses with the specified label.\n "
13561361 " \n Returns up to 'count' most recent transactions skipping the first 'from' transactions.\n "
13571362 " \n Arguments:\n "
1358- " 1. \" dummy\" (string, optional) If set, should be \" *\" for backwards compatibility.\n "
1363+ " 1. \" label\" (string, optional) If set, should be a valid label name to return only incoming transactions\n "
1364+ " with the specified label, or \" *\" to disable filtering and return all transactions.\n "
13591365 " 2. count (numeric, optional, default=10) The number of transactions to return\n "
13601366 " 3. skip (numeric, optional, default=0) The number of transactions to skip\n "
13611367 " 4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n "
@@ -1400,8 +1406,12 @@ UniValue listtransactions(const JSONRPCRequest& request)
14001406 // the user could have gotten from another RPC command prior to now
14011407 pwallet->BlockUntilSyncedToCurrentChain ();
14021408
1409+ const std::string* filter_label = nullptr ;
14031410 if (!request.params [0 ].isNull () && request.params [0 ].get_str () != " *" ) {
1404- throw JSONRPCError (RPC_INVALID_PARAMETER, " Dummy value must be set to \" *\" " );
1411+ filter_label = &request.params [0 ].get_str ();
1412+ if (filter_label->empty ()) {
1413+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Label argument must be a valid label name or \" *\" ." );
1414+ }
14051415 }
14061416 int nCount = 10 ;
14071417 if (!request.params [1 ].isNull ())
@@ -1431,7 +1441,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
14311441 for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it)
14321442 {
14331443 CWalletTx *const pwtx = (*it).second ;
1434- ListTransactions (*locked_chain, pwallet, *pwtx, 0 , true , ret, filter);
1444+ ListTransactions (*locked_chain, pwallet, *pwtx, 0 , true , ret, filter, filter_label );
14351445 if ((int )ret.size () >= (nCount+nFrom)) break ;
14361446 }
14371447 }
@@ -1568,7 +1578,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
15681578 CWalletTx tx = pairWtx.second ;
15691579
15701580 if (depth == -1 || tx.GetDepthInMainChain (*locked_chain) < depth) {
1571- ListTransactions (*locked_chain, pwallet, tx, 0 , true , transactions, filter);
1581+ ListTransactions (*locked_chain, pwallet, tx, 0 , true , transactions, filter, nullptr /* filter_label */ );
15721582 }
15731583 }
15741584
@@ -1585,7 +1595,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
15851595 if (it != pwallet->mapWallet .end ()) {
15861596 // We want all transactions regardless of confirmation count to appear here,
15871597 // even negative confirmation ones, hence the big negative.
1588- ListTransactions (*locked_chain, pwallet, it->second , -100000000 , true , removed, filter);
1598+ ListTransactions (*locked_chain, pwallet, it->second , -100000000 , true , removed, filter, nullptr /* filter_label */ );
15891599 }
15901600 }
15911601 paltindex = paltindex->pprev ;
@@ -1688,7 +1698,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
16881698 WalletTxToJSON (pwallet->chain (), *locked_chain, wtx, entry);
16891699
16901700 UniValue details (UniValue::VARR);
1691- ListTransactions (*locked_chain, pwallet, wtx, 0 , false , details, filter);
1701+ ListTransactions (*locked_chain, pwallet, wtx, 0 , false , details, filter, nullptr /* filter_label */ );
16921702 entry.pushKV (" details" , details);
16931703
16941704 std::string strHex = EncodeHexTx (*wtx.tx , RPCSerializationFlags ());
@@ -4143,7 +4153,7 @@ static const CRPCCommand commands[] =
41434153 { " wallet" , " listreceivedbyaddress" , &listreceivedbyaddress, {" minconf" ," include_empty" ," include_watchonly" ," address_filter" } },
41444154 { " wallet" , " listreceivedbylabel" , &listreceivedbylabel, {" minconf" ," include_empty" ," include_watchonly" } },
41454155 { " wallet" , " listsinceblock" , &listsinceblock, {" blockhash" ," target_confirmations" ," include_watchonly" ," include_removed" } },
4146- { " wallet" , " listtransactions" , &listtransactions, {" dummy" ," count" ," skip" ," include_watchonly" } },
4156+ { " wallet" , " listtransactions" , &listtransactions, {" label| dummy" ," count" ," skip" ," include_watchonly" } },
41474157 { " wallet" , " listunspent" , &listunspent, {" minconf" ," maxconf" ," addresses" ," include_unsafe" ," query_options" } },
41484158 { " wallet" , " listwalletdir" , &listwalletdir, {} },
41494159 { " wallet" , " listwallets" , &listwallets, {} },
0 commit comments