Skip to content

Commit

Permalink
Move Transaction-Record from Qt section to Wallet section
Browse files Browse the repository at this point in the history
Signed-off-by: cevap <dev@i2pmail.org>
  • Loading branch information
FornaxA authored and Cevap Master committed Jan 6, 2019
1 parent 17379d1 commit 42a1e16
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Expand Up @@ -173,6 +173,7 @@ BITCOIN_CORE_H = \
timedata.h \
tinyformat.h \
torcontrol.h \
qt/transactionrecord.h \
txdb.h \
txmempool.h \
ui_interface.h \
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 0 additions & 2 deletions src/Makefile.qt.include
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactiondesc.cpp
Expand Up @@ -251,7 +251,7 @@ QString TransactionDesc::toHTML(CWallet* wallet, CWalletTx& wtx, TransactionReco
if (wtx.mapValue.count("comment") && !wtx.mapValue["comment"].empty())
strHTML += "<br><b>" + tr("Comment") + ":</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["comment"], true) + "<br>";

strHTML += "<b>" + tr("Transaction ID") + ":</b> " + rec->getTxID() + "<br>";
strHTML += "<b>" + tr("Transaction ID") + ":</b> " + QString::fromStdString(rec->getTxID()) + "<br>";
strHTML += "<b>" + tr("Output index") + ":</b> " + QString::number(rec->getOutputIndex()) + "<br>";

// Message from normal ion:URI (ion:XyZ...?message=example)
Expand Down
33 changes: 17 additions & 16 deletions src/qt/transactionrecord.cpp
Expand Up @@ -32,9 +32,9 @@ bool TransactionRecord::showTransaction(const CWalletTx& wtx)
/*
* Decompose CWallet transaction to model transaction records.
*/
QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx)
std::vector<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx)
{
QList<TransactionRecord> parts;
std::vector<TransactionRecord> parts;
int64_t nTime = wtx.GetComputedTxTime();
CAmount nCredit = wtx.GetCredit(ISMINE_ALL);
CAmount nDebit = wtx.GetDebit(ISMINE_ALL);
Expand Down Expand Up @@ -85,7 +85,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
}
}

parts.append(sub);
parts.push_back(sub);
} else if (wtx.IsZerocoinSpend()) {
//zerocoin spend outputs
bool fFeeAssigned = false;
Expand All @@ -106,7 +106,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
fFeeAssigned = true;
}
sub.idx = parts.size();
parts.append(sub);
parts.push_back(sub);
continue;
}

Expand All @@ -130,7 +130,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
if (strAddress != "")
sub.address = strAddress;
sub.idx = parts.size();
parts.append(sub);
parts.push_back(sub);
continue;
}

Expand All @@ -147,7 +147,7 @@ QList<TransactionRecord> 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()) {
//
Expand Down Expand Up @@ -175,7 +175,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
sub.type = TransactionRecord::Generated;
}

parts.append(sub);
parts.push_back(sub);
}
}
} else {
Expand Down Expand Up @@ -207,8 +207,8 @@ QList<TransactionRecord> 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,
Expand Down Expand Up @@ -244,8 +244,8 @@ QList<TransactionRecord> 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
Expand Down Expand Up @@ -295,14 +295,14 @@ QList<TransactionRecord> 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;
}
}

Expand Down Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions src/qt/transactionrecord.h
Expand Up @@ -11,9 +11,6 @@
#include "amount.h"
#include "uint256.h"

#include <QList>
#include <QString>

class CWallet;
class CWalletTx;

Expand Down Expand Up @@ -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 */
/**@}*/
Expand Down Expand Up @@ -105,25 +102,25 @@ 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)
{
}

/** Decompose CWallet transaction to model transaction records.
*/
static bool showTransaction(const CWalletTx& wtx);
static QList<TransactionRecord> decomposeTransaction(const CWallet* wallet, const CWalletTx& wtx);
static std::vector<TransactionRecord> 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;
Expand All @@ -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;
Expand Down
20 changes: 14 additions & 6 deletions src/qt/transactiontablemodel.cpp
Expand Up @@ -80,8 +80,13 @@ class TransactionTablePriv
{
LOCK2(cs_main, wallet->cs_wallet);
for (std::map<uint256, CWalletTx>::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<TransactionRecord> vRecs = TransactionRecord::decomposeTransaction(wallet, it->second);
QList<TransactionRecord> QLRecs;
QLRecs.reserve(vRecs.size());
std::copy(vRecs.begin(), vRecs.end(), std::back_inserter(QLRecs));
cachedWallet.append(QLRecs);
}
}
}
}
Expand Down Expand Up @@ -130,8 +135,11 @@ class TransactionTablePriv
break;
}
// Added -- insert at the right position
QList<TransactionRecord> toInsert =
TransactionRecord::decomposeTransaction(wallet, mi->second);
std::vector<TransactionRecord> vToInsert = TransactionRecord::decomposeTransaction(wallet, mi->second);
QList<TransactionRecord> 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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 42a1e16

Please sign in to comment.