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

Added transaction categories for beacon and voting #973

Closed
wants to merge 8 commits into from
Closed
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
5 changes: 3 additions & 2 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ QT_FORMS_UI = \
qt/forms/transactiondescdialog.ui \
qt/forms/askpassphrasedialog.ui \
qt/forms/sendcoinsentry.ui

QT_MOC_CPP = \
qt/moc_aboutdialog.cpp \
qt/moc_addressbookpage.cpp \
Expand Down Expand Up @@ -269,6 +269,7 @@ RES_ICONS = \
qt/res/icons/tx_mined.svg \
qt/res/icons/tx_output.svg \
qt/res/icons/tx_por.svg \
qt/res/icons/tx_vote.svg \
qt/res/icons/icons_native/overview.svg \
qt/res/icons/icons_light/overview.svg \
qt/res/icons/icons_dark/overview.svg \
Expand Down Expand Up @@ -400,7 +401,7 @@ CLEANFILES += $(CLEAN_QT)
gridcoinresearch_clean: FORCE
rm -f $(CLEAN_QT) $(qt_gridcoinresearch_OBJECTS) qt/gridcoinresearch$(EXEEXT)

gridcoinresearch:
gridcoinresearch:
@echo "$(ZIP_LIBS)"
qt/gridcoinresearch$(EXEEXT)

Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoin.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<file alias="history_dark">res/icons/icons_dark/transactions.svg</file>
<file alias="history_light">res/icons/icons_light/transactions.svg</file>
<file alias="history_native">res/icons/icons_native/transactions.svg</file>
<file alias="tx_vote">res/icons/tx_vote.svg</file>
</qresource>
<qresource prefix="/images">
<file alias="splash">res/images/splash3.png</file>
Expand Down
49 changes: 49 additions & 0 deletions src/qt/res/icons/tx_vote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 77 additions & 11 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#include "wallet.h"
#include "base58.h"

std::vector<std::pair<std::string, std::string>> GetTxNormalBoincHashInfo(const CMerkleTx& mtx);
std::string GetTxProject(uint256 hash, int& out_blocknumber, int& out_blocktype, double& out_rac);

std::string GetBurnAddress();

/* Return positive answer if transaction should be shown in list. */
bool TransactionRecord::showTransaction(const CWalletTx &wtx)
{

std::string ShowOrphans = GetArg("-showorphans", "false");

//R Halford - POS Transactions - If Orphaned follow showorphans directive:
Expand All @@ -17,7 +18,7 @@ bool TransactionRecord::showTransaction(const CWalletTx &wtx)
//Orphaned tx
return (ShowOrphans=="true" ? true : false);
}

if (wtx.IsCoinBase())
{
// Ensures we show generated coins / mined transactions at depth 1
Expand Down Expand Up @@ -71,9 +72,33 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
sub.credit = txout.nValue;
if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*wallet, address))
{
// Received by Bitcoin Address
sub.type = TransactionRecord::RecvWithAddress;
// Received by Gridcoin Address
sub.address = CBitcoinAddress(address).ToString();
std::vector<std::pair<std::string, std::string>> vTxNormalInfoIn = GetTxNormalBoincHashInfo(wtx);
for (const auto& vTxNormalInfo : vTxNormalInfoIn)
{
if (vTxNormalInfo.first == "Message Type")
{
if (vTxNormalInfo.second == "Text Message")
{
sub.type = TransactionRecord::RecvMessage;
break;
}

else if(vTxNormalInfo.second == "Text Rain Message")
{
sub.type = TransactionRecord::RecvRain;
break;
}

else
{
sub.type = TransactionRecord::RecvWithAddress;
break;
}

}
}
}
else
{
Expand All @@ -93,7 +118,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
continue; // last coinstake output

if (wtx.vout.size()==2)
{
{
//Standard POR CoinStake
sub.type = TransactionRecord::Generated;
sub.credit = nNet > 0 ? nNet : wtx.GetValueOut() - nDebit;
Expand All @@ -112,7 +137,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
{
sub.credit = nNet > 0 ? nNet : GetMyValueOut(wallet,wtx) - nDebit;
}

hashPrev = hash;
}
}
Expand Down Expand Up @@ -162,9 +187,52 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
CTxDestination address;
if (ExtractDestination(txout.scriptPubKey, address))
{
// Sent to Bitcoin Address
sub.type = TransactionRecord::SendToAddress;
// Sent to Gridcoin Address
sub.address = CBitcoinAddress(address).ToString();

std::vector<std::pair<std::string, std::string>> vTxNormalInfoIn = GetTxNormalBoincHashInfo(wtx);
for (const auto& vTxNormalInfo : vTxNormalInfoIn)
{
if (vTxNormalInfo.first == "Message Type")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably fail when localized.

{
// Sent to mainnet / testnet burn address
if(sub.address == GetBurnAddress())
{
if (vTxNormalInfo.second == "Vote" || vTxNormalInfo.second == "Add Poll")
{
sub.type = TransactionRecord::Vote;
break;
}

else if (vTxNormalInfo.second == "Add Beacon Contract")
{
sub.type = TransactionRecord::Beacon;
break;
}
else
{
sub.type = TransactionRecord::SendToAddress;
break;
}
}

else if (vTxNormalInfo.second == "Text Message")
{
sub.type = TransactionRecord::SendMessage;
break;
}
else if (vTxNormalInfo.second == "Text Rain Message")
{
sub.type = TransactionRecord::SendRain;
break;
}
else
{
sub.type = TransactionRecord::SendToAddress;
break;
}
}
}
}
else
{
Expand Down Expand Up @@ -292,5 +360,3 @@ std::string TransactionRecord::getTxID()
{
return hash.ToString() + strprintf("-%03d", idx);
}


13 changes: 12 additions & 1 deletion src/qt/transactionrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

#include <QList>

// Workaround for Windows #define:ing SendMessage to SendMessageW.
#if defined(SendMessage)
#undef SendMessage
#endif

class CWallet;
class CWalletTx;

Expand Down Expand Up @@ -70,7 +75,13 @@ class TransactionRecord
SendToOther,
RecvWithAddress,
RecvFromOther,
SendToSelf
SendToSelf,
Vote,
Beacon,
SendMessage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macros are evil in c++. I suggest the #undef option.

SendRain,
RecvMessage,
RecvRain
};

/** Number of confirmation recommended for accepting a transaction */
Expand Down
37 changes: 36 additions & 1 deletion src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const
return tr("Sent to");
case TransactionRecord::SendToSelf:
return tr("Payment to yourself");
case TransactionRecord::Vote:
return tr("Voting fee");
case TransactionRecord::Beacon:
return tr("Beacon fee");
case TransactionRecord::RecvMessage:
return tr("Received message with");
case TransactionRecord::SendMessage:
return tr("Sent message to");
case TransactionRecord::RecvRain:
return tr("Received rain with");
case TransactionRecord::SendRain:
return tr("Sent rain");
case TransactionRecord::Generated:
if (wtx->RemoteFlag==1 && false)
{
Expand Down Expand Up @@ -436,6 +448,18 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx
case TransactionRecord::SendToAddress:
case TransactionRecord::SendToOther:
return QIcon(":/icons/tx_output");
case TransactionRecord::Vote:
return QIcon(":/icons/tx_vote");
case TransactionRecord::Beacon:
return QIcon(":/icons/tx_output");
case TransactionRecord::RecvMessage:
return QIcon(":/icons/tx_input");
case TransactionRecord::SendMessage:
return QIcon(":/icons/tx_output");
case TransactionRecord::RecvRain:
return QIcon(":/icons/tx_input");
case TransactionRecord::SendRain:
return QIcon(":/icons/tx_output");
default:
return QIcon(":/icons/tx_inout");
}
Expand All @@ -452,7 +476,15 @@ QString TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx, b
case TransactionRecord::RecvWithAddress:
case TransactionRecord::SendToAddress:
case TransactionRecord::Generated:
case TransactionRecord::SendMessage:
case TransactionRecord::RecvMessage:
case TransactionRecord::SendRain:
case TransactionRecord::RecvRain:
return lookupAddress(wtx->address, tooltip);
case TransactionRecord::Vote:
return tr("Voting fee");
case TransactionRecord::Beacon:
return tr("Beacon fee");
case TransactionRecord::SendToSelf:
default:
return tr("(n/a)");
Expand All @@ -467,6 +499,8 @@ QVariant TransactionTableModel::addressColor(const TransactionRecord *wtx) const
case TransactionRecord::RecvWithAddress:
case TransactionRecord::SendToAddress:
case TransactionRecord::Generated:
case TransactionRecord::SendMessage:
case TransactionRecord::RecvMessage:
{
QString label = walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(wtx->address));
if(label.isEmpty())
Expand Down Expand Up @@ -536,7 +570,8 @@ QString TransactionTableModel::formatTooltip(const TransactionRecord *rec) const
{
QString tooltip = formatTxStatus(rec) + QString("\n") + formatTxType(rec);
if(rec->type==TransactionRecord::RecvFromOther || rec->type==TransactionRecord::SendToOther ||
rec->type==TransactionRecord::SendToAddress || rec->type==TransactionRecord::RecvWithAddress)
rec->type==TransactionRecord::SendToAddress || rec->type==TransactionRecord::RecvWithAddress ||
rec->type==TransactionRecord::SendMessage || rec->type==TransactionRecord::RecvMessage)
{
tooltip += QString(" ") + formatTxToAddress(rec, true);
}
Expand Down
6 changes: 6 additions & 0 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ TransactionView::TransactionView(QWidget *parent) :
TransactionFilterProxy::TYPE(TransactionRecord::SendToOther));
typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated));
typeWidget->addItem(tr("Vote"), TransactionFilterProxy::TYPE(TransactionRecord::Vote));
typeWidget->addItem(tr("Beacon"), TransactionFilterProxy::TYPE(TransactionRecord::Beacon));
typeWidget->addItem(tr("Sent message"), TransactionFilterProxy::TYPE(TransactionRecord::SendMessage));
typeWidget->addItem(tr("Received message"), TransactionFilterProxy::TYPE(TransactionRecord::RecvMessage));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the transaction is "To yourself" "Sent message" and "Received message" at the same time?

typeWidget->addItem(tr("Sent rain"), TransactionFilterProxy::TYPE(TransactionRecord::SendRain));
typeWidget->addItem(tr("Received rain"), TransactionFilterProxy::TYPE(TransactionRecord::RecvRain));
typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));

hlayout->addWidget(typeWidget);
Expand Down