@@ -1261,25 +1261,26 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
1261
1261
/* *
1262
1262
* List transactions based on the given criteria.
1263
1263
*
1264
- * @param pwallet The wallet.
1265
- * @param wtx The wallet transaction.
1266
- * @param nMinDepth The minimum confirmation depth.
1267
- * @param fLong Whether to include the JSON version of the transaction.
1268
- * @param ret The UniValue into which the result is stored.
1269
- * @param filter The "is mine" filter bool.
1264
+ * @param pwallet The wallet.
1265
+ * @param wtx The wallet transaction.
1266
+ * @param nMinDepth The minimum confirmation depth.
1267
+ * @param fLong Whether to include the JSON version of the transaction.
1268
+ * @param ret The UniValue into which the result is stored.
1269
+ * @param filter_ismine The "is mine" filter flags.
1270
+ * @param filter_label Optional label string to filter incoming transactions.
1270
1271
*/
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_ismine, const std::string* filter_label )
1272
1273
{
1273
1274
CAmount nFee;
1274
1275
std::list<COutputEntry> listReceived;
1275
1276
std::list<COutputEntry> listSent;
1276
1277
1277
- wtx.GetAmounts (listReceived, listSent, nFee, filter );
1278
+ wtx.GetAmounts (listReceived, listSent, nFee, filter_ismine );
1278
1279
1279
1280
bool involvesWatchonly = wtx.IsFromMe (ISMINE_WATCH_ONLY);
1280
1281
1281
1282
// Sent
1282
- if ((!listSent. empty () || nFee != 0 ) )
1283
+ if (!filter_label )
1283
1284
{
1284
1285
for (const COutputEntry& s : listSent)
1285
1286
{
@@ -1311,6 +1312,9 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* con
1311
1312
if (pwallet->mapAddressBook .count (r.destination )) {
1312
1313
label = pwallet->mapAddressBook [r.destination ].name ;
1313
1314
}
1315
+ if (filter_label && label != *filter_label) {
1316
+ continue ;
1317
+ }
1314
1318
UniValue entry (UniValue::VOBJ);
1315
1319
if (involvesWatchonly || (::IsMine (*pwallet, r.destination ) & ISMINE_WATCH_ONLY)) {
1316
1320
entry.pushKV (" involvesWatchonly" , true );
@@ -1352,10 +1356,12 @@ UniValue listtransactions(const JSONRPCRequest& request)
1352
1356
1353
1357
if (request.fHelp || request.params .size () > 4 )
1354
1358
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 "
1356
1361
" \n Returns up to 'count' most recent transactions skipping the first 'from' transactions.\n "
1357
1362
" \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 "
1359
1365
" 2. count (numeric, optional, default=10) The number of transactions to return\n "
1360
1366
" 3. skip (numeric, optional, default=0) The number of transactions to skip\n "
1361
1367
" 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)
1400
1406
// the user could have gotten from another RPC command prior to now
1401
1407
pwallet->BlockUntilSyncedToCurrentChain ();
1402
1408
1409
+ const std::string* filter_label = nullptr ;
1403
1410
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
+ }
1405
1415
}
1406
1416
int nCount = 10 ;
1407
1417
if (!request.params [1 ].isNull ())
@@ -1431,7 +1441,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
1431
1441
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it)
1432
1442
{
1433
1443
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 );
1435
1445
if ((int )ret.size () >= (nCount+nFrom)) break ;
1436
1446
}
1437
1447
}
@@ -1568,7 +1578,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
1568
1578
CWalletTx tx = pairWtx.second ;
1569
1579
1570
1580
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 */ );
1572
1582
}
1573
1583
}
1574
1584
@@ -1585,7 +1595,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
1585
1595
if (it != pwallet->mapWallet .end ()) {
1586
1596
// We want all transactions regardless of confirmation count to appear here,
1587
1597
// 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 */ );
1589
1599
}
1590
1600
}
1591
1601
paltindex = paltindex->pprev ;
@@ -1688,7 +1698,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
1688
1698
WalletTxToJSON (pwallet->chain (), *locked_chain, wtx, entry);
1689
1699
1690
1700
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 */ );
1692
1702
entry.pushKV (" details" , details);
1693
1703
1694
1704
std::string strHex = EncodeHexTx (*wtx.tx , RPCSerializationFlags ());
@@ -4143,7 +4153,7 @@ static const CRPCCommand commands[] =
4143
4153
{ " wallet" , " listreceivedbyaddress" , &listreceivedbyaddress, {" minconf" ," include_empty" ," include_watchonly" ," address_filter" } },
4144
4154
{ " wallet" , " listreceivedbylabel" , &listreceivedbylabel, {" minconf" ," include_empty" ," include_watchonly" } },
4145
4155
{ " 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" } },
4147
4157
{ " wallet" , " listunspent" , &listunspent, {" minconf" ," maxconf" ," addresses" ," include_unsafe" ," query_options" } },
4148
4158
{ " wallet" , " listwalletdir" , &listwalletdir, {} },
4149
4159
{ " wallet" , " listwallets" , &listwallets, {} },
0 commit comments