From 272356024db978c92112167f8d8e4cc62adad63d Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 17 Sep 2019 19:44:19 -0400 Subject: [PATCH] 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. --- src/interfaces/wallet.h | 4 +++- src/wallet/interfaces.cpp | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index e29fefae565..4ab416f451f 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -183,7 +183,7 @@ public: virtual WalletTx getWalletTx(const uint256& txid) = 0; //! Get list of all wallet transactions. - virtual std::vector getWalletTxs() = 0; + virtual std::set getWalletTxs() = 0; //! Try to get updated status for a particular transaction, if possible without blocking. virtual bool tryGetTxStatus(const uint256& txid, @@ -395,6 +395,8 @@ struct WalletTx int64_t time; std::map value_map; bool is_coinbase; + + bool operator<(const WalletTx& a) const { return tx->GetHash() < a.tx->GetHash(); } }; //! Updated transaction status. diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 23f91d9b3a4..5add1287172 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -318,13 +318,12 @@ public: } return {}; } - std::vector getWalletTxs() override + std::set getWalletTxs() override { LOCK(m_wallet->cs_wallet); - std::vector result; - result.reserve(m_wallet->mapWallet.size()); + std::set result; for (const auto& entry : m_wallet->mapWallet) { - result.emplace_back(MakeWalletTx(*m_wallet, entry.second)); + result.emplace(MakeWalletTx(*m_wallet, entry.second)); } return result; }