From 42a1e160cce8f2980ba7759510ce1e8f87d772eb Mon Sep 17 00:00:00 2001 From: FornaxA Date: Fri, 28 Dec 2018 10:11:14 +0100 Subject: [PATCH] Move Transaction-Record from Qt section to Wallet section Signed-off-by: cevap --- src/Makefile.am | 2 ++ src/Makefile.qt.include | 2 -- src/qt/transactiondesc.cpp | 2 +- src/qt/transactionrecord.cpp | 33 ++++++++++++++++---------------- src/qt/transactionrecord.h | 17 +++++++--------- src/qt/transactiontablemodel.cpp | 20 +++++++++++++------ 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 5e7f9380ef04d..b69d37b7ef60f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -173,6 +173,7 @@ BITCOIN_CORE_H = \ timedata.h \ tinyformat.h \ torcontrol.h \ + qt/transactionrecord.h \ txdb.h \ txmempool.h \ ui_interface.h \ @@ -274,6 +275,7 @@ libbitcoin_wallet_a_SOURCES = \ primitives/zerocoin.cpp \ rpcwallet.cpp \ kernel.cpp \ + qt/transactionrecord.cpp \ wallet.cpp \ wallet_ismine.cpp \ walletdb.cpp \ diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 38d2d3bf7cff3..56136107abeb3 100755 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -199,7 +199,6 @@ BITCOIN_QT_H = \ qt/transactiondesc.h \ qt/transactiondescdialog.h \ qt/transactionfilterproxy.h \ - qt/transactionrecord.h \ qt/transactiontablemodel.h \ qt/transactionview.h \ qt/utilitydialog.h \ @@ -334,7 +333,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/transactiondesc.cpp \ qt/transactiondescdialog.cpp \ qt/transactionfilterproxy.cpp \ - qt/transactionrecord.cpp \ qt/transactiontablemodel.cpp \ qt/transactionview.cpp \ qt/walletframe.cpp \ diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 08ce9184a5a97..492fa0d8d41bd 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -251,7 +251,7 @@ QString TransactionDesc::toHTML(CWallet* wallet, CWalletTx& wtx, TransactionReco if (wtx.mapValue.count("comment") && !wtx.mapValue["comment"].empty()) strHTML += "
" + tr("Comment") + ":
" + GUIUtil::HtmlEscape(wtx.mapValue["comment"], true) + "
"; - strHTML += "" + tr("Transaction ID") + ": " + rec->getTxID() + "
"; + strHTML += "" + tr("Transaction ID") + ": " + QString::fromStdString(rec->getTxID()) + "
"; strHTML += "" + tr("Output index") + ": " + QString::number(rec->getOutputIndex()) + "
"; // Message from normal ion:URI (ion:XyZ...?message=example) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index b6db2fa24b540..9521b7013ce3a 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -32,9 +32,9 @@ bool TransactionRecord::showTransaction(const CWalletTx& wtx) /* * Decompose CWallet transaction to model transaction records. */ -QList TransactionRecord::decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx) +std::vector TransactionRecord::decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx) { - QList parts; + std::vector parts; int64_t nTime = wtx.GetComputedTxTime(); CAmount nCredit = wtx.GetCredit(ISMINE_ALL); CAmount nDebit = wtx.GetDebit(ISMINE_ALL); @@ -85,7 +85,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet* } } - parts.append(sub); + parts.push_back(sub); } else if (wtx.IsZerocoinSpend()) { //zerocoin spend outputs bool fFeeAssigned = false; @@ -106,7 +106,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet* fFeeAssigned = true; } sub.idx = parts.size(); - parts.append(sub); + parts.push_back(sub); continue; } @@ -130,7 +130,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet* if (strAddress != "") sub.address = strAddress; sub.idx = parts.size(); - parts.append(sub); + parts.push_back(sub); continue; } @@ -147,7 +147,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet* if (strAddress != "") sub.address = strAddress; sub.idx = parts.size(); - parts.append(sub); + parts.push_back(sub); } } else if (nNet > 0 || wtx.IsCoinBase()) { // @@ -175,7 +175,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet* sub.type = TransactionRecord::Generated; } - parts.append(sub); + parts.push_back(sub); } } } else { @@ -207,8 +207,8 @@ QList TransactionRecord::decomposeTransaction(const CWallet* } if (fAllFromMeDenom && fAllToMeDenom && nFromMe * nToMe) { - parts.append(TransactionRecord(hash, nTime, TransactionRecord::ObfuscationDenominate, "", -nDebit, nCredit)); - parts.last().involvesWatchAddress = false; // maybe pass to TransactionRecord as constructor argument + parts.push_back(TransactionRecord(hash, nTime, TransactionRecord::ObfuscationDenominate, "", -nDebit, nCredit)); + parts.back().involvesWatchAddress = false; // maybe pass to TransactionRecord as constructor argument } else if (fAllFromMe && fAllToMe) { // Payment to self // TODO: this section still not accurate but covers most cases, @@ -244,8 +244,8 @@ QList TransactionRecord::decomposeTransaction(const CWallet* sub.debit = -(nDebit - nChange); sub.credit = nCredit - nChange; - parts.append(sub); - parts.last().involvesWatchAddress = involvesWatchAddress; // maybe pass to TransactionRecord as constructor argument + parts.push_back(sub); + parts.back().involvesWatchAddress = involvesWatchAddress; // maybe pass to TransactionRecord as constructor argument } else if (fAllFromMe || wtx.IsZerocoinMint()) { // // Debit @@ -295,14 +295,14 @@ QList TransactionRecord::decomposeTransaction(const CWallet* } sub.debit = -nValue; - parts.append(sub); + parts.push_back(sub); } } else { // // Mixed debit transaction, can't break down payees // - parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0)); - parts.last().involvesWatchAddress = involvesWatchAddress; + parts.push_back(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0)); + parts.back().involvesWatchAddress = involvesWatchAddress; } } @@ -398,9 +398,10 @@ bool TransactionRecord::statusUpdateNeeded() return status.cur_num_blocks != chainActive.Height() || status.cur_num_ix_locks != nCompleteTXLocks; } -QString TransactionRecord::getTxID() const +std::string TransactionRecord::getTxID() const { - return QString::fromStdString(hash.ToString()); + //return QString::fromStdString(hash.ToString()); + return hash.ToString(); } int TransactionRecord::getOutputIndex() const diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index dffe475544523..dbd72ebd477ae 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -11,9 +11,6 @@ #include "amount.h" #include "uint256.h" -#include -#include - class CWallet; class CWalletTx; @@ -55,8 +52,8 @@ class TransactionStatus /** @name Reported status @{*/ Status status; - qint64 depth; - qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number + int64_t depth; + int64_t open_for; /**< Timestamp if status==OpenUntilDate, otherwise number of additional blocks that need to be mined before finalization */ /**@}*/ @@ -105,12 +102,12 @@ class TransactionRecord { } - TransactionRecord(uint256 hash, qint64 time) : hash(hash), time(time), type(Other), address(""), debit(0), + TransactionRecord(uint256 hash, int64_t time) : hash(hash), time(time), type(Other), address(""), debit(0), credit(0), idx(0) { } - TransactionRecord(uint256 hash, qint64 time, Type type, const std::string& address, const CAmount& debit, const CAmount& credit) : hash(hash), time(time), type(type), address(address), debit(debit), credit(credit), + TransactionRecord(uint256 hash, int64_t time, Type type, const std::string& address, const CAmount& debit, const CAmount& credit) : hash(hash), time(time), type(type), address(address), debit(debit), credit(credit), idx(0) { } @@ -118,12 +115,12 @@ class TransactionRecord /** Decompose CWallet transaction to model transaction records. */ static bool showTransaction(const CWalletTx& wtx); - static QList decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx); + static std::vector decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx); /** @name Immutable transaction attributes @{*/ uint256 hash; - qint64 time; + int64_t time; Type type; std::string address; CAmount debit; @@ -140,7 +137,7 @@ class TransactionRecord bool involvesWatchAddress; /** Return the unique identifier for this transaction (part) */ - QString getTxID() const; + std::string getTxID() const; /** Return the output index of the subtransaction */ int getOutputIndex() const; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 3421b6bddce7e..c1a3f5bde25be 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -80,8 +80,13 @@ class TransactionTablePriv { LOCK2(cs_main, wallet->cs_wallet); for (std::map::iterator it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it) { - if (TransactionRecord::showTransaction(it->second)) - cachedWallet.append(TransactionRecord::decomposeTransaction(wallet, it->second)); + if (TransactionRecord::showTransaction(it->second)) { + std::vector vRecs = TransactionRecord::decomposeTransaction(wallet, it->second); + QList QLRecs; + QLRecs.reserve(vRecs.size()); + std::copy(vRecs.begin(), vRecs.end(), std::back_inserter(QLRecs)); + cachedWallet.append(QLRecs); + } } } } @@ -130,8 +135,11 @@ class TransactionTablePriv break; } // Added -- insert at the right position - QList toInsert = - TransactionRecord::decomposeTransaction(wallet, mi->second); + std::vector vToInsert = TransactionRecord::decomposeTransaction(wallet, mi->second); + QList toInsert; + toInsert.reserve(vToInsert.size()); + std::copy(vToInsert.begin(), vToInsert.end(), std::back_inserter(toInsert)); + if (!toInsert.isEmpty()) /* only if something to insert */ { parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex + toInsert.size() - 1); @@ -558,7 +566,7 @@ QVariant TransactionTableModel::data(const QModelIndex& index, int role) const case Status: return QString::fromStdString(rec->status.sortKey); case Date: - return rec->time; + return qint64(rec->time); case Type: return formatTxType(rec); case Watchonly: @@ -617,7 +625,7 @@ QVariant TransactionTableModel::data(const QModelIndex& index, int role) const case AmountRole: return qint64(rec->credit + rec->debit); case TxIDRole: - return rec->getTxID(); + return QString::fromStdString(rec->getTxID()); case TxHashRole: return QString::fromStdString(rec->hash.ToString()); case ConfirmedRole: