Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readd listtransactionrecords #9

Open
wants to merge 3 commits into
base: tmp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion contrib/bitrpc/bitrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,17 @@
except:
print "\n---An error occurred---\n"


elif cmd == "listtransactionrecords":
try:
acct = raw_input("Account (optional): ")
count = raw_input("Number of transactions (optional): ")
frm = raw_input("Skip (optional):")
try:
print access.listtransactionrecords(acct, count, frm)
except:
print access.listtransactionrecords()
except:
print "\n---An error occurred---\n"

elif cmd == "move":
try:
Expand Down
2 changes: 1 addition & 1 deletion contrib/wagerr-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ HEADERS += src/activemasternode.h \
src/qt/transactiondesc.h \
src/qt/transactiondescdialog.h \
src/qt/transactionfilterproxy.h \
src/qt(transactionrecord.h \
src/transactionrecord.h \
src/qt/transactiontablemodel.h \
src/qt/transactionview.h \
src/qt/utilitydialog.h \
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ BITCOIN_CORE_H = \
timedata.h \
tinyformat.h \
torcontrol.h \
transactionrecord.h \
txdb.h \
txmempool.h \
ui_interface.h \
Expand Down Expand Up @@ -272,6 +273,7 @@ libbitcoin_wallet_a_SOURCES = \
wallet/rpcdump.cpp \
wallet/rpcwallet.cpp \
kernel.cpp \
transactionrecord.cpp \
wallet/wallet.cpp \
wallet/wallet_ismine.cpp \
wallet/walletdb.cpp \
Expand Down
3 changes: 0 additions & 3 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ QT_MOC_CPP = \
qt/moc_transactiondesc.cpp \
qt/moc_transactiondescdialog.cpp \
qt/moc_transactionfilterproxy.cpp \
qt/moc_transactionrecord.cpp \
qt/moc_transactiontablemodel.cpp \
qt/moc_transactionview.cpp \
qt/moc_utilitydialog.cpp \
Expand Down Expand Up @@ -203,7 +202,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 @@ -343,7 +341,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
Original file line number Diff line number Diff line change
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 wagerr:URI (wagerr:XyZ...?message=example)
Expand Down
20 changes: 14 additions & 6 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ 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 @@ -129,8 +135,10 @@ 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 @@ -557,7 +565,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 @@ -616,7 +624,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
1 change: 1 addition & 0 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ static const CRPCCommand vRPCCommands[] =
{"wallet", "listreceivedbyaddress", &listreceivedbyaddress, false, false, true},
{"wallet", "listsinceblock", &listsinceblock, false, false, true},
{"wallet", "listtransactions", &listtransactions, false, false, true},
{"wallet", "listtransactionrecords", &listtransactionrecords, false, false, true},
{"wallet", "listunspent", &listunspent, false, false, true},
{"wallet", "lockunspent", &lockunspent, true, false, true},
{"wallet", "move", &movecmd, false, false, true},
Expand Down
1 change: 1 addition & 0 deletions src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ extern UniValue addmultisigaddress(const UniValue& params, bool fHelp);
extern UniValue listreceivedbyaddress(const UniValue& params, bool fHelp);
extern UniValue listreceivedbyaccount(const UniValue& params, bool fHelp);
extern UniValue listtransactions(const UniValue& params, bool fHelp);
extern UniValue listtransactionrecords(const UniValue& params, bool fHelp);
extern UniValue listaddressgroupings(const UniValue& params, bool fHelp);
extern UniValue listaccounts(const UniValue& params, bool fHelp);
extern UniValue listsinceblock(const UniValue& params, bool fHelp);
Expand Down
93 changes: 76 additions & 17 deletions src/qt/transactionrecord.cpp → src/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool TransactionRecord::showTransaction(const CWalletTx& wtx)
return true;
}

bool DecomposeBettingCoinstake(const CWallet* wallet, const CWalletTx& wtx, const CTxDestination address, bool fMyZMint, QList<TransactionRecord> &coinStakeRecords) {
bool DecomposeBettingCoinstake(const CWallet* wallet, const CWalletTx& wtx, const CTxDestination address, bool fMyZMint, std::vector<TransactionRecord> &coinStakeRecords) {
std::map<uint64_t, CTxOut> stakeRewards;
std::map<uint64_t, CTxOut> betRewards;
std::map<uint64_t, CTxOut> MNRewards;
Expand Down Expand Up @@ -154,9 +154,9 @@ bool DecomposeBettingCoinstake(const CWallet* wallet, const CWalletTx& wtx, cons
/*
* 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 @@ -211,7 +211,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 @@ -232,7 +232,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
fFeeAssigned = true;
}
sub.idx = parts.size();
parts.append(sub);
parts.push_back(sub);
continue;
}

Expand All @@ -256,7 +256,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 @@ -273,7 +273,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 @@ -301,7 +301,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
sub.type = TransactionRecord::Generated;
}

parts.append(sub);
parts.push_back(sub);
}
}
} else {
Expand Down Expand Up @@ -333,8 +333,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 @@ -370,8 +370,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 @@ -421,14 +421,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 @@ -524,12 +524,71 @@ 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 hash.ToString();
}

int TransactionRecord::getOutputIndex() const
{
return idx;
}

std::string TransactionRecord::GetTransactionRecordType() const
{
return GetTransactionRecordType(type);
}
std::string TransactionRecord::GetTransactionRecordType(Type type) const
{
switch (type)
{
case Other: return "Other";
case BetWin: return "BetWinnings";
case BetPlaced: return "Bet";
case Generated: return "Generated";
case StakeMint: return "StakeMint";
case StakeZWGR: return "StakeZWGR";
case SendToAddress: return "SendToAddress";
case SendToOther: return "SendToOther";
case RecvWithAddress: return "RecvWithAddress";
case MNReward: return "MNReward";
case RecvFromOther: return "RecvFromOther";
case SendToSelf: return "SendToSelf";
case ZerocoinMint: return "ZerocoinMint";
case ZerocoinSpend: return "ZerocoinSpend";
case RecvFromZerocoinSpend: return "RecvFromZerocoinSpend";
case ZerocoinSpend_Change_zWgr: return "ZerocoinSpend_Change_zWgr";
case ZerocoinSpend_FromMe: return "ZerocoinSpend_FromMe";
case RecvWithObfuscation: return "RecvWithObfuscation";
case ObfuscationDenominate: return "ObfuscationDenominate";
case ObfuscationCollateralPayment: return "ObfuscationCollateralPayment";
case ObfuscationMakeCollaterals: return "ObfuscationMakeCollaterals";
case ObfuscationCreateDenominations: return "ObfuscationCreateDenominations";
case Obfuscated: return "Obfuscated";
}
return NULL;
}

std::string TransactionRecord::GetTransactionStatus() const
{
return GetTransactionStatus(status.status);
}
std::string TransactionRecord::GetTransactionStatus(TransactionStatus::Status status) const
{
switch (status)
{
case TransactionStatus::Confirmed: return "Confirmed"; /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
/// Normal (sent/received) transactions
case TransactionStatus::OpenUntilDate: return "OpenUntilDate"; /**< Transaction not yet final, waiting for date */
case TransactionStatus::OpenUntilBlock: return "OpenUntilBlock"; /**< Transaction not yet final, waiting for block */
case TransactionStatus::Offline: return "Offline"; /**< Not sent to any other nodes **/
case TransactionStatus::Unconfirmed: return "Unconfirmed"; /**< Not yet mined into a block **/
case TransactionStatus::Confirming: return "Confirmed"; /**< Confirmed, but waiting for the recommended number of confirmations **/
case TransactionStatus::Conflicted: return "Conflicted"; /**< Conflicts with other transaction or mempool **/
/// Generated (mined) transactions
case TransactionStatus::Immature: return "Immature"; /**< Mined but waiting for maturity */
case TransactionStatus::MaturesWarning: return "MaturesWarning"; /**< Transaction will likely not mature because no nodes have confirmed */
case TransactionStatus::NotAccepted: return "NotAccepted"; /**< Mined but not accepted */
}
return NULL;
}
Loading