2016-06-08 13:53:24 +03:00
|
|
|
#include "TransactionHistory.h"
|
|
|
|
#include "TransactionInfo.h"
|
|
|
|
#include <wallet/wallet2_api.h>
|
|
|
|
|
2016-10-04 23:12:58 +03:00
|
|
|
#include <QDebug>
|
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
|
|
|
|
TransactionInfo *TransactionHistory::transaction(int index)
|
|
|
|
{
|
2016-10-07 00:47:28 +03:00
|
|
|
|
|
|
|
if (index < 0 || index >= m_tinfo.size()) {
|
2016-10-04 23:12:58 +03:00
|
|
|
qCritical("%s: no transaction info for index %d", __FUNCTION__, index);
|
|
|
|
qCritical("%s: there's %d transactions in backend", __FUNCTION__, m_pimpl->count());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-10-07 00:47:28 +03:00
|
|
|
return m_tinfo.at(index);
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 00:47:28 +03:00
|
|
|
//// XXX: not sure if this method really needed;
|
|
|
|
//TransactionInfo *TransactionHistory::transaction(const QString &id)
|
|
|
|
//{
|
|
|
|
// return nullptr;
|
|
|
|
//}
|
2016-06-08 13:53:24 +03:00
|
|
|
|
|
|
|
QList<TransactionInfo *> TransactionHistory::getAll() const
|
|
|
|
{
|
2016-10-07 00:47:28 +03:00
|
|
|
// XXX this invalidates previously saved history that might be used by model
|
|
|
|
emit refreshStarted();
|
2016-06-08 13:53:24 +03:00
|
|
|
qDeleteAll(m_tinfo);
|
|
|
|
m_tinfo.clear();
|
2016-10-08 01:22:45 +03:00
|
|
|
|
2016-11-05 17:32:30 +02:00
|
|
|
QDateTime firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
|
|
|
|
QDateTime lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)
|
2016-10-08 01:22:45 +03:00
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
TransactionHistory * parent = const_cast<TransactionHistory*>(this);
|
|
|
|
for (const auto i : m_pimpl->getAll()) {
|
|
|
|
TransactionInfo * ti = new TransactionInfo(i, parent);
|
|
|
|
m_tinfo.append(ti);
|
2016-10-08 01:22:45 +03:00
|
|
|
// looking for transactions timestamp scope
|
|
|
|
if (ti->timestamp() >= lastDateTime) {
|
|
|
|
lastDateTime = ti->timestamp();
|
|
|
|
}
|
|
|
|
if (ti->timestamp() <= firstDateTime) {
|
|
|
|
firstDateTime = ti->timestamp();
|
|
|
|
}
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|
2016-10-07 00:47:28 +03:00
|
|
|
emit refreshFinished();
|
2016-10-08 01:22:45 +03:00
|
|
|
|
|
|
|
if (m_firstDateTime != firstDateTime) {
|
|
|
|
m_firstDateTime = firstDateTime;
|
|
|
|
emit firstDateTimeChanged();
|
|
|
|
}
|
|
|
|
if (m_lastDateTime != lastDateTime) {
|
|
|
|
m_lastDateTime = lastDateTime;
|
|
|
|
emit lastDateTimeChanged();
|
|
|
|
}
|
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
return m_tinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionHistory::refresh()
|
|
|
|
{
|
2016-10-07 00:47:28 +03:00
|
|
|
// rebuilding transaction list in wallet_api;
|
2016-06-08 13:53:24 +03:00
|
|
|
m_pimpl->refresh();
|
2016-10-07 00:47:28 +03:00
|
|
|
// copying list here and keep track on every item to avoid memleaks
|
|
|
|
getAll();
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|
|
|
|
|
2016-10-02 21:40:40 +03:00
|
|
|
quint64 TransactionHistory::count() const
|
|
|
|
{
|
2016-10-07 00:47:28 +03:00
|
|
|
return m_tinfo.count();
|
2016-10-02 21:40:40 +03:00
|
|
|
}
|
|
|
|
|
2016-10-08 01:22:45 +03:00
|
|
|
QDateTime TransactionHistory::firstDateTime() const
|
|
|
|
{
|
|
|
|
return m_firstDateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime TransactionHistory::lastDateTime() const
|
|
|
|
{
|
|
|
|
return m_lastDateTime;
|
|
|
|
}
|
|
|
|
|
2016-10-02 21:40:40 +03:00
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent)
|
|
|
|
: QObject(parent), m_pimpl(pimpl)
|
|
|
|
{
|
2016-10-16 14:30:37 +03:00
|
|
|
m_firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
|
|
|
|
m_lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|