aboutsummaryrefslogtreecommitdiff
path: root/src/libwalletqt/TransactionHistory.cpp
blob: e94816f2db95c2ae7364e8b8ec9ec3a41966193c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "TransactionHistory.h"
#include "TransactionInfo.h"
#include <wallet/wallet2_api.h>

#include <QDebug>


TransactionInfo *TransactionHistory::transaction(int index)
{

    if (index < 0 || index >= m_tinfo.size()) {
        qCritical("%s: no transaction info for index %d", __FUNCTION__, index);
        qCritical("%s: there's %d transactions in backend", __FUNCTION__, m_pimpl->count());
        return nullptr;
    }
    return m_tinfo.at(index);
}

//// XXX: not sure if this method really needed;
//TransactionInfo *TransactionHistory::transaction(const QString &id)
//{
//    return nullptr;
//}

QList<TransactionInfo *> TransactionHistory::getAll() const
{
    // XXX this invalidates previously saved history that might be used by model
    emit refreshStarted();
    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);
        qDebug() << ti->hash();
        m_tinfo.append(ti);
    }
    emit refreshFinished();
    return m_tinfo;
}

void TransactionHistory::refresh()
{
    // rebuilding transaction list in wallet_api;
    m_pimpl->refresh();
    // copying list here and keep track on every item to avoid memleaks
    getAll();
}

quint64 TransactionHistory::count() const
{
    return m_tinfo.count();
}


TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent)
    : QObject(parent), m_pimpl(pimpl)
{
    // this->refresh();
}