Skip to content

Commit 2723560

Browse files
committed
Change getWalletTxs to return a set instead of a vector
For some reason, the primary consumer of getWalletTxs requires the transactions to be in hash order when it is processing them. std::map will iterate in hash order so the transactions end up in that order when placed into the vector. To ensure this order when mapWallet is no longer ordered, the vector is replaced with a set which will maintain the hash order.
1 parent 9753286 commit 2723560

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/interfaces/wallet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Wallet
183183
virtual WalletTx getWalletTx(const uint256& txid) = 0;
184184

185185
//! Get list of all wallet transactions.
186-
virtual std::vector<WalletTx> getWalletTxs() = 0;
186+
virtual std::set<WalletTx> getWalletTxs() = 0;
187187

188188
//! Try to get updated status for a particular transaction, if possible without blocking.
189189
virtual bool tryGetTxStatus(const uint256& txid,
@@ -395,6 +395,8 @@ struct WalletTx
395395
int64_t time;
396396
std::map<std::string, std::string> value_map;
397397
bool is_coinbase;
398+
399+
bool operator<(const WalletTx& a) const { return tx->GetHash() < a.tx->GetHash(); }
398400
};
399401

400402
//! Updated transaction status.

src/wallet/interfaces.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,12 @@ class WalletImpl : public Wallet
318318
}
319319
return {};
320320
}
321-
std::vector<WalletTx> getWalletTxs() override
321+
std::set<WalletTx> getWalletTxs() override
322322
{
323323
LOCK(m_wallet->cs_wallet);
324-
std::vector<WalletTx> result;
325-
result.reserve(m_wallet->mapWallet.size());
324+
std::set<WalletTx> result;
326325
for (const auto& entry : m_wallet->mapWallet) {
327-
result.emplace_back(MakeWalletTx(*m_wallet, entry.second));
326+
result.emplace(MakeWalletTx(*m_wallet, entry.second));
328327
}
329328
return result;
330329
}

0 commit comments

Comments
 (0)