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();
|
|
|
|
TransactionHistory * parent = const_cast<TransactionHistory*>(this);
|
|
|
|
for (const auto i : m_pimpl->getAll()) {
|
|
|
|
TransactionInfo * ti = new TransactionInfo(i, parent);
|
2016-10-07 00:47:28 +03:00
|
|
|
qDebug() << ti->hash();
|
2016-06-08 13:53:24 +03:00
|
|
|
m_tinfo.append(ti);
|
|
|
|
}
|
2016-10-07 00:47:28 +03:00
|
|
|
emit refreshFinished();
|
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-06-08 13:53:24 +03:00
|
|
|
TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent)
|
|
|
|
: QObject(parent), m_pimpl(pimpl)
|
|
|
|
{
|
2016-10-07 00:47:28 +03:00
|
|
|
// this->refresh();
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|