|
|
@ -60,12 +60,24 @@ TransactionHistoryImpl::~TransactionHistoryImpl()
|
|
|
|
|
|
|
|
|
|
|
|
int TransactionHistoryImpl::count() const
|
|
|
|
int TransactionHistoryImpl::count() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
boost::lock_guard<boost::mutex> guarg(m_historyMutex);
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(m_historyMutex);
|
|
|
|
return m_history.size();
|
|
|
|
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
|
|
|
|
TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(m_historyMutex);
|
|
|
|
auto itr = std::find_if(m_history.begin(), m_history.end(),
|
|
|
|
auto itr = std::find_if(m_history.begin(), m_history.end(),
|
|
|
|
[&](const TransactionInfo * ti) {
|
|
|
|
[&](const TransactionInfo * ti) {
|
|
|
|
return ti->hash() == id;
|
|
|
|
return ti->hash() == id;
|
|
|
@ -75,13 +87,16 @@ TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) cons
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<TransactionInfo *> TransactionHistoryImpl::getAll() const
|
|
|
|
std::vector<TransactionInfo *> TransactionHistoryImpl::getAll() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(m_historyMutex);
|
|
|
|
return m_history;
|
|
|
|
return m_history;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TransactionHistoryImpl::refresh()
|
|
|
|
void TransactionHistoryImpl::refresh()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// multithreaded access:
|
|
|
|
// multithreaded access:
|
|
|
|
boost::lock_guard<boost::mutex> guarg(m_historyMutex);
|
|
|
|
// 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;
|
|
|
|
// TODO: configurable values;
|
|
|
|
uint64_t min_height = 0;
|
|
|
|
uint64_t min_height = 0;
|
|
|
@ -190,16 +205,8 @@ void TransactionHistoryImpl::refresh()
|
|
|
|
ti->m_timestamp = pd.m_timestamp;
|
|
|
|
ti->m_timestamp = pd.m_timestamp;
|
|
|
|
m_history.push_back(ti);
|
|
|
|
m_history.push_back(ti);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TransactionInfo *TransactionHistoryImpl::transaction(int index) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
unsigned index_ = static_cast<unsigned>(index);
|
|
|
|
|
|
|
|
return index_ < m_history.size() ? m_history[index_] : nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|