From c12f8487fb3f1c3a4494e3b0d68c12d1f0504929 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 7 Apr 2020 14:28:57 +0300 Subject: [PATCH] wallet2: enumerate_transfers_history() and enumerate_unconfirmed_transfers() implemented --- src/wallet/wallet2.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 2cc41907..aa866008 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -614,6 +614,14 @@ namespace tools // Returns all payments by given id in unspecified order void get_payments(const std::string& payment_id, std::list& payments, uint64_t min_height = 0) const; + // callback: (const wallet_public::wallet_transfer_info& wti) -> bool, true -- continue, false -- stop + template + void enumerate_transfers_history(callback_t cb, bool enumerate_forward) const; + + // callback: (const wallet_public::wallet_transfer_info& wti) -> bool, true -- continue, false -- stop + template + void enumerate_unconfirmed_transfers(callback_t cb) const; + bool is_watch_only() const { return m_watch_only; } void sign_transfer(const std::string& tx_sources_blob, std::string& signed_tx_blob, currency::transaction& tx); void sign_transfer_files(const std::string& tx_sources_file, const std::string& signed_tx_file, currency::transaction& tx); @@ -1143,6 +1151,31 @@ namespace tools return false; } + template + void wallet2::enumerate_transfers_history(callback_t cb, bool enumerate_forward) const + { + if (enumerate_forward) + { + for(auto it = m_transfer_history.begin(); it != m_transfer_history.end(); ++it) + if (!cb(*it)) + break; + } + else + { + for(auto it = m_transfer_history.rbegin(); it != m_transfer_history.rend(); ++it) + if (!cb(*it)) + break; + } + } + + template + void wallet2::enumerate_unconfirmed_transfers(callback_t cb) const + { + for (auto& el : m_unconfirmed_txs) + if (!cb(el.second)) + break; + } + } // namespace tools #if !defined(KEEP_WALLET_LOG_MACROS)