From 85f5e73d9cb30b59c131fd4297e188fdf0225283 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 4 Oct 2016 23:11:19 +0300 Subject: libwallet_api: fixes for transaction history --- src/wallet/api/transaction_history.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index 95aafb04f..86dff85a4 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -65,7 +65,11 @@ int TransactionHistoryImpl::count() const TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) const { - return nullptr; + 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 TransactionHistoryImpl::getAll() const @@ -109,7 +113,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 +155,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,6 +185,7 @@ 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); } @@ -187,7 +193,11 @@ void TransactionHistoryImpl::refresh() TransactionInfo *TransactionHistoryImpl::transaction(int index) const { - return nullptr; + // sanity check + if (index < 0) + return nullptr; + unsigned index_ = static_cast(index); + return index_ < m_history.size() ? m_history[index_] : nullptr; } } -- cgit v1.2.3