aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/api/transaction_history.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/api/transaction_history.cpp')
-rw-r--r--src/wallet/api/transaction_history.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp
index 95aafb04f..e4a003b02 100644
--- a/src/wallet/api/transaction_history.cpp
+++ b/src/wallet/api/transaction_history.cpp
@@ -60,21 +60,44 @@ TransactionHistoryImpl::~TransactionHistoryImpl()
int TransactionHistoryImpl::count() const
{
- return m_history.size();
+ boost::shared_lock<boost::shared_mutex> lock(m_historyMutex);
+ int result = m_history.size();
+ return result;
+}
+
+TransactionInfo *TransactionHistoryImpl::transaction(int index) const
+{
+ boost::shared_lock<boost::shared_mutex> lock(m_historyMutex);
+ // sanity check
+ if (index < 0)
+ return nullptr;
+ unsigned index_ = static_cast<unsigned>(index);
+ return index_ < m_history.size() ? m_history[index_] : nullptr;
}
TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) const
{
- return nullptr;
+ boost::shared_lock<boost::shared_mutex> lock(m_historyMutex);
+ auto itr = std::find_if(m_history.begin(), m_history.end(),
+ [&](const TransactionInfo * ti) {
+ return ti->hash() == id;
+ });
+ return itr != m_history.end() ? *itr : nullptr;
}
std::vector<TransactionInfo *> TransactionHistoryImpl::getAll() const
{
+ boost::shared_lock<boost::shared_mutex> lock(m_historyMutex);
return m_history;
}
void TransactionHistoryImpl::refresh()
{
+ // multithreaded access:
+ // boost::lock_guard<boost::mutex> guarg(m_historyMutex);
+ // for "write" access, locking exclusively
+ boost::unique_lock<boost::shared_mutex> lock(m_historyMutex);
+
// TODO: configurable values;
uint64_t min_height = 0;
uint64_t max_height = (uint64_t)-1;
@@ -84,8 +107,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
@@ -109,7 +130,7 @@ void TransactionHistoryImpl::refresh()
ti->m_hash = string_tools::pod_to_hex(pd.m_tx_hash);
ti->m_blockheight = pd.m_block_height;
// TODO:
- // ti->m_timestamp = pd.m_timestamp;
+ ti->m_timestamp = pd.m_timestamp;
m_history.push_back(ti);
/* output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%20.20s %s %s %s")
@@ -151,6 +172,7 @@ void TransactionHistoryImpl::refresh()
ti->m_direction = TransactionInfo::Direction_Out;
ti->m_hash = string_tools::pod_to_hex(hash);
ti->m_blockheight = pd.m_block_height;
+ ti->m_timestamp = pd.m_timestamp;
// single output transaction might contain multiple transfers
for (const auto &d: pd.m_dests) {
@@ -180,14 +202,9 @@ void TransactionHistoryImpl::refresh()
ti->m_failed = is_failed;
ti->m_pending = true;
ti->m_hash = string_tools::pod_to_hex(hash);
+ ti->m_timestamp = pd.m_timestamp;
m_history.push_back(ti);
}
-
-}
-
-TransactionInfo *TransactionHistoryImpl::transaction(int index) const
-{
- return nullptr;
}
-}
+} // namespace