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)
|
2017-01-14 00:21:58 +02:00
|
|
|
quint64 lastTxHeight = 0;
|
|
|
|
m_locked = false;
|
|
|
|
m_minutesToUnlock = 0;
|
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();
|
|
|
|
}
|
2017-10-23 22:24:50 +03:00
|
|
|
quint64 requiredConfirmations = (ti->blockHeight() < ti->unlockTime()) ? ti->unlockTime() - ti->blockHeight() : 10;
|
2017-01-14 00:21:58 +02:00
|
|
|
// store last tx height
|
2017-08-03 22:43:01 +03:00
|
|
|
if (ti->confirmations() < requiredConfirmations && ti->blockHeight() >= lastTxHeight) {
|
2017-01-14 00:21:58 +02:00
|
|
|
lastTxHeight = ti->blockHeight();
|
|
|
|
// TODO: Fetch block time and confirmations needed from wallet2?
|
2017-08-03 22:43:01 +03:00
|
|
|
m_minutesToUnlock = (requiredConfirmations - ti->confirmations()) * 2;
|
2017-01-14 00:21:58 +02:00
|
|
|
m_locked = true;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:21:58 +02:00
|
|
|
quint64 TransactionHistory::minutesToUnlock() const
|
|
|
|
{
|
|
|
|
return m_minutesToUnlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TransactionHistory::TransactionHistory::locked() const
|
|
|
|
{
|
|
|
|
return m_locked;
|
|
|
|
}
|
|
|
|
|
2016-10-02 21:40:40 +03:00
|
|
|
|
2016-12-13 20:51:07 +02:00
|
|
|
TransactionHistory::TransactionHistory(Monero::TransactionHistory *pimpl, QObject *parent)
|
2017-01-14 00:21:58 +02:00
|
|
|
: QObject(parent), m_pimpl(pimpl), m_minutesToUnlock(0), m_locked(false)
|
2016-06-08 13:53:24 +03:00
|
|
|
{
|
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
|
|
|
}
|