Skip to content

Commit 852891f

Browse files
committed
refactor, wallet: use optional for label in ListTransactions
1 parent 0abb5b2 commit 852891f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/wallet/rpc/transactions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
316316
*/
317317
template <class Vec>
318318
static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong,
319-
Vec& ret, const isminefilter& filter_ismine, const std::string* filter_label,
319+
Vec& ret, const isminefilter& filter_ismine, const std::optional<std::string>& filter_label,
320320
bool include_change = false)
321321
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
322322
{
@@ -329,7 +329,7 @@ static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nM
329329
bool involvesWatchonly = CachedTxIsFromMe(wallet, wtx, ISMINE_WATCH_ONLY);
330330

331331
// Sent
332-
if (!filter_label)
332+
if (!filter_label.has_value())
333333
{
334334
for (const COutputEntry& s : listSent)
335335
{
@@ -362,7 +362,7 @@ static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nM
362362
if (address_book_entry) {
363363
label = address_book_entry->GetLabel();
364364
}
365-
if (filter_label && label != *filter_label) {
365+
if (filter_label.has_value() && label != filter_label.value()) {
366366
continue;
367367
}
368368
UniValue entry(UniValue::VOBJ);
@@ -485,10 +485,10 @@ RPCHelpMan listtransactions()
485485
// the user could have gotten from another RPC command prior to now
486486
pwallet->BlockUntilSyncedToCurrentChain();
487487

488-
const std::string* filter_label = nullptr;
488+
std::optional<std::string> filter_label;
489489
if (!request.params[0].isNull() && request.params[0].get_str() != "*") {
490-
filter_label = &request.params[0].get_str();
491-
if (filter_label->empty()) {
490+
filter_label = request.params[0].get_str();
491+
if (filter_label.value().empty()) {
492492
throw JSONRPCError(RPC_INVALID_PARAMETER, "Label argument must be a valid label name or \"*\".");
493493
}
494494
}
@@ -642,7 +642,7 @@ RPCHelpMan listsinceblock()
642642
const CWalletTx& tx = pairWtx.second;
643643

644644
if (depth == -1 || abs(wallet.GetTxDepthInMainChain(tx)) < depth) {
645-
ListTransactions(wallet, tx, 0, true, transactions, filter, /*filter_label=*/nullptr, /*include_change=*/include_change);
645+
ListTransactions(wallet, tx, 0, true, transactions, filter, std::nullopt/* filter_label */, /*include_change=*/include_change);
646646
}
647647
}
648648

@@ -659,7 +659,7 @@ RPCHelpMan listsinceblock()
659659
if (it != wallet.mapWallet.end()) {
660660
// We want all transactions regardless of confirmation count to appear here,
661661
// even negative confirmation ones, hence the big negative.
662-
ListTransactions(wallet, it->second, -100000000, true, removed, filter, /*filter_label=*/nullptr, /*include_change=*/include_change);
662+
ListTransactions(wallet, it->second, -100000000, true, removed, filter, std::nullopt/* filter_label */, /*include_change=*/include_change);
663663
}
664664
}
665665
blockId = block.hashPrevBlock;
@@ -777,7 +777,7 @@ RPCHelpMan gettransaction()
777777
WalletTxToJSON(*pwallet, wtx, entry);
778778

779779
UniValue details(UniValue::VARR);
780-
ListTransactions(*pwallet, wtx, 0, false, details, filter, /*filter_label=*/nullptr);
780+
ListTransactions(*pwallet, wtx, 0, false, details, filter, std::nullopt /* filter_label */);
781781
entry.pushKV("details", details);
782782

783783
std::string strHex = EncodeHexTx(*wtx.tx, pwallet->chain().rpcSerializationFlags());

0 commit comments

Comments
 (0)