diff options
-rw-r--r-- | src/wallet/api/transaction_history.cpp | 5 | ||||
-rw-r--r-- | src/wallet/api/transaction_history.h | 2 | ||||
-rw-r--r-- | src/wallet/api/wallet.cpp | 6 |
3 files changed, 11 insertions, 2 deletions
diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index 86dff85a4..190aa67c5 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -79,6 +79,9 @@ std::vector<TransactionInfo *> TransactionHistoryImpl::getAll() const void TransactionHistoryImpl::refresh() { + // multithreaded access: + boost::lock_guard<boost::mutex> guarg(m_refreshMutex); + // TODO: configurable values; uint64_t min_height = 0; uint64_t max_height = (uint64_t)-1; @@ -88,8 +91,6 @@ void TransactionHistoryImpl::refresh() delete t; m_history.clear(); - - // transactions are stored in wallet2: // - confirmed_transfer_details - out transfers // - unconfirmed_transfer_details - pending out transfers diff --git a/src/wallet/api/transaction_history.h b/src/wallet/api/transaction_history.h index 171fd2210..0b7e079b9 100644 --- a/src/wallet/api/transaction_history.h +++ b/src/wallet/api/transaction_history.h @@ -29,6 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "wallet/wallet2_api.h" +#include <boost/thread/mutex.hpp> namespace Bitmonero { @@ -51,6 +52,7 @@ private: // TransactionHistory is responsible of memory management std::vector<TransactionInfo*> m_history; WalletImpl *m_wallet; + boost::mutex m_refreshMutex; }; } diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 4d35bc404..eb6fe5db2 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -723,6 +723,12 @@ void WalletImpl::doRefresh() boost::lock_guard<boost::mutex> guarg(m_refreshMutex2); try { m_wallet->refresh(); + // assuming if we have empty history, it wasn't initialized yet + // for futher history changes client need to update history in + // "on_money_received" and "on_money_sent" callbacks + if (m_history->count() == 0) { + m_history->refresh(); + } } catch (const std::exception &e) { m_status = Status_Error; m_errorString = e.what(); |