@@ -1375,8 +1375,9 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
13751375 * @param fLong Whether to include the JSON version of the transaction.
13761376 * @param ret The UniValue into which the result is stored.
13771377 * @param filter The "is mine" filter bool.
1378+ * @param filter_label Optional label string to filter incoming transactions.
13781379 */
1379- static void ListTransactions (CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong , UniValue& ret, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1380+ static void ListTransactions (CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong , UniValue& ret, const isminefilter& filter, const std::string* filter_label ) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
13801381{
13811382 CAmount nFee;
13821383 std::list<COutputEntry> listReceived;
@@ -1387,7 +1388,7 @@ static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, int n
13871388 bool involvesWatchonly = wtx.IsFromMe (ISMINE_WATCH_ONLY);
13881389
13891390 // Sent
1390- if ((!listSent. empty () || nFee != 0 ) )
1391+ if (!filter_label )
13911392 {
13921393 for (const COutputEntry& s : listSent)
13931394 {
@@ -1419,6 +1420,9 @@ static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, int n
14191420 if (pwallet->mapAddressBook .count (r.destination )) {
14201421 label = pwallet->mapAddressBook [r.destination ].name ;
14211422 }
1423+ if (filter_label && label != *filter_label) {
1424+ continue ;
1425+ }
14221426 UniValue entry (UniValue::VOBJ);
14231427 if (involvesWatchonly || (::IsMine (*pwallet, r.destination ) & ISMINE_WATCH_ONLY)) {
14241428 entry.pushKV (" involvesWatchonly" , true );
@@ -1460,10 +1464,12 @@ UniValue listtransactions(const JSONRPCRequest& request)
14601464
14611465 if (request.fHelp || request.params .size () > 4 )
14621466 throw std::runtime_error (
1463- " listtransactions (dummy count skip include_watchonly)\n "
1467+ " listtransactions ( label count skip include_watchonly )\n "
1468+ " \n If a label name is provided, this will return only incoming transactions paying to addresses with the specified label.\n "
14641469 " \n Returns up to 'count' most recent transactions skipping the first 'from' transactions.\n "
14651470 " \n Arguments:\n "
1466- " 1. \" dummy\" (string, optional) If set, should be \" *\" for backwards compatibility.\n "
1471+ " 1. \" label\" (string, optional) If set, should be a valid label name to return only incoming transactions\n "
1472+ " with the specified label, or \" *\" to disable filtering and return all transactions.\n "
14671473 " 2. count (numeric, optional, default=10) The number of transactions to return\n "
14681474 " 3. skip (numeric, optional, default=0) The number of transactions to skip\n "
14691475 " 4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n "
@@ -1508,8 +1514,12 @@ UniValue listtransactions(const JSONRPCRequest& request)
15081514 // the user could have gotten from another RPC command prior to now
15091515 pwallet->BlockUntilSyncedToCurrentChain ();
15101516
1517+ const std::string* filter_label = nullptr ;
15111518 if (!request.params [0 ].isNull () && request.params [0 ].get_str () != " *" ) {
1512- throw JSONRPCError (RPC_INVALID_PARAMETER, " Dummy value must be set to \" *\" " );
1519+ filter_label = &request.params [0 ].get_str ();
1520+ if (filter_label->empty ()) {
1521+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Label argument must be a valid label name or \" *\" ." );
1522+ }
15131523 }
15141524 int nCount = 10 ;
15151525 if (!request.params [1 ].isNull ())
@@ -1538,7 +1548,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
15381548 for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it)
15391549 {
15401550 CWalletTx *const pwtx = (*it).second ;
1541- ListTransactions (pwallet, *pwtx, 0 , true , ret, filter);
1551+ ListTransactions (pwallet, *pwtx, 0 , true , ret, filter, filter_label );
15421552 if ((int )ret.size () >= (nCount+nFrom)) break ;
15431553 }
15441554 }
@@ -1674,7 +1684,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
16741684 CWalletTx tx = pairWtx.second ;
16751685
16761686 if (depth == -1 || tx.GetDepthInMainChain () < depth) {
1677- ListTransactions (pwallet, tx, 0 , true , transactions, filter);
1687+ ListTransactions (pwallet, tx, 0 , true , transactions, filter, nullptr /* filter_label */ );
16781688 }
16791689 }
16801690
@@ -1691,7 +1701,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
16911701 if (it != pwallet->mapWallet .end ()) {
16921702 // We want all transactions regardless of confirmation count to appear here,
16931703 // even negative confirmation ones, hence the big negative.
1694- ListTransactions (pwallet, it->second , -100000000 , true , removed, filter);
1704+ ListTransactions (pwallet, it->second , -100000000 , true , removed, filter, nullptr /* filter_label */ );
16951705 }
16961706 }
16971707 paltindex = paltindex->pprev ;
@@ -1793,7 +1803,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
17931803 WalletTxToJSON (wtx, entry);
17941804
17951805 UniValue details (UniValue::VARR);
1796- ListTransactions (pwallet, wtx, 0 , false , details, filter);
1806+ ListTransactions (pwallet, wtx, 0 , false , details, filter, nullptr /* filter_label */ );
17971807 entry.pushKV (" details" , details);
17981808
17991809 std::string strHex = EncodeHexTx (*wtx.tx , RPCSerializationFlags ());
@@ -4094,7 +4104,7 @@ static const CRPCCommand commands[] =
40944104 { " wallet" , " listreceivedbyaddress" , &listreceivedbyaddress, {" minconf" ," include_empty" ," include_watchonly" ," address_filter" } },
40954105 { " wallet" , " listreceivedbylabel" , &listreceivedbylabel, {" minconf" ," include_empty" ," include_watchonly" } },
40964106 { " wallet" , " listsinceblock" , &listsinceblock, {" blockhash" ," target_confirmations" ," include_watchonly" ," include_removed" } },
4097- { " wallet" , " listtransactions" , &listtransactions, {" dummy" ," count" ," skip" ," include_watchonly" } },
4107+ { " wallet" , " listtransactions" , &listtransactions, {" label| dummy" ," count" ," skip" ," include_watchonly" } },
40984108 { " wallet" , " listunspent" , &listunspent, {" minconf" ," maxconf" ," addresses" ," include_unsafe" ," query_options" } },
40994109 { " wallet" , " listwallets" , &listwallets, {} },
41004110 { " wallet" , " loadwallet" , &loadwallet, {" filename" } },
0 commit comments