From 1661c8244933ff2fcf0d1ad2141e444070570ff7 Mon Sep 17 00:00:00 2001 From: xiphon Date: Thu, 12 Dec 2019 15:10:39 +0000 Subject: TransactionInfo: parse Wallet API provided data on initialization --- src/libwalletqt/TransactionInfo.cpp | 79 +++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 38 deletions(-) (limited to 'src/libwalletqt/TransactionInfo.cpp') diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp index 9200ec11..9c5094bb 100644 --- a/src/libwalletqt/TransactionInfo.cpp +++ b/src/libwalletqt/TransactionInfo.cpp @@ -34,85 +34,81 @@ TransactionInfo::Direction TransactionInfo::direction() const { - return static_cast(m_pimpl->direction()); + return m_direction; } bool TransactionInfo::isPending() const { - return m_pimpl->isPending(); + return m_pending; } bool TransactionInfo::isFailed() const { - return m_pimpl->isFailed(); + return m_failed; } double TransactionInfo::amount() const { // there's no unsigned uint64 for JS, so better use double - return WalletManager::instance()->displayAmount(m_pimpl->amount()).toDouble(); + return displayAmount().toDouble(); } quint64 TransactionInfo::atomicAmount() const { - return m_pimpl->amount(); + return m_amount; } QString TransactionInfo::displayAmount() const { - return WalletManager::instance()->displayAmount(m_pimpl->amount()); + return WalletManager::instance()->displayAmount(m_amount); } QString TransactionInfo::fee() const { - if(m_pimpl->fee() == 0) + if(m_fee == 0) return ""; - return WalletManager::instance()->displayAmount(m_pimpl->fee()); + return WalletManager::instance()->displayAmount(m_fee); } quint64 TransactionInfo::blockHeight() const { - return m_pimpl->blockHeight(); + return m_blockHeight; } QSet TransactionInfo::subaddrIndex() const { - QSet result; - for (uint32_t i : m_pimpl->subaddrIndex()) - result.insert(i); - return result; + return m_subaddrIndex; } quint32 TransactionInfo::subaddrAccount() const { - return m_pimpl->subaddrAccount(); + return m_subaddrAccount; } QString TransactionInfo::label() const { - return QString::fromStdString(m_pimpl->label()); + return m_label; } quint64 TransactionInfo::confirmations() const { - return m_pimpl->confirmations(); + return m_confirmations; } quint64 TransactionInfo::unlockTime() const { - return m_pimpl->unlockTime(); + return m_unlockTime; } QString TransactionInfo::hash() const { - return QString::fromStdString(m_pimpl->hash()); + return m_hash; } QDateTime TransactionInfo::timestamp() const { - QDateTime result = QDateTime::fromTime_t(m_pimpl->timestamp()); - return result; + return m_timestamp; } QString TransactionInfo::date() const @@ -127,13 +123,13 @@ QString TransactionInfo::time() const QString TransactionInfo::paymentId() const { - return QString::fromStdString(m_pimpl->paymentId()); + return m_paymentId; } QString TransactionInfo::destinations_formatted() const { QString destinations; - for (auto const& t: transfers()) { + for (auto const& t: m_transfers) { if (!destinations.isEmpty()) destinations += "
"; destinations += WalletManager::instance()->displayAmount(t->amount()) + ": " + t->address(); @@ -141,22 +137,29 @@ QString TransactionInfo::destinations_formatted() const return destinations; } -QList TransactionInfo::transfers() const -{ - if (!m_transfers.isEmpty()) { - return m_transfers; - } - - for(auto const& t: m_pimpl->transfers()) { - TransactionInfo * parent = const_cast(this); - Transfer * transfer = new Transfer(t.amount, QString::fromStdString(t.address), parent); +TransactionInfo::TransactionInfo(const Monero::TransactionInfo *pimpl, QObject *parent) + : QObject(parent) + , m_amount(pimpl->amount()) + , m_blockHeight(pimpl->blockHeight()) + , m_confirmations(pimpl->confirmations()) + , m_direction(static_cast(pimpl->direction())) + , m_failed(pimpl->isFailed()) + , m_fee(pimpl->fee()) + , m_hash(QString::fromStdString(pimpl->hash())) + , m_label(QString::fromStdString(pimpl->label())) + , m_paymentId(QString::fromStdString(pimpl->paymentId())) + , m_pending(pimpl->isPending()) + , m_subaddrAccount(pimpl->subaddrAccount()) + , m_timestamp(QDateTime::fromTime_t(pimpl->timestamp())) + , m_unlockTime(pimpl->unlockTime()) +{ + for (auto const &t: pimpl->transfers()) + { + Transfer *transfer = new Transfer(t.amount, QString::fromStdString(t.address), this); m_transfers.append(transfer); } - return m_transfers; -} - -TransactionInfo::TransactionInfo(Monero::TransactionInfo *pimpl, QObject *parent) - : QObject(parent), m_pimpl(pimpl) -{ - + for (uint32_t i : pimpl->subaddrIndex()) + { + m_subaddrIndex.insert(i); + } } -- cgit v1.2.3