Skip to content

Commit

Permalink
gui: Add transaction record type Fee
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin/bitcoin #12578
Rebased-From: 550f1f3d3498d051ab94afdc0b9fb883c0655b99
  • Loading branch information
promag authored and instagibbs committed Apr 8, 2019
1 parent 41c8d4c commit 3edcdf8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ static WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LO
IsMine(wallet, result.txout_address.back()) :
ISMINE_NO);
}
// ELEMENTS: Retrieve unblinded information about outputs
for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
result.txout_amounts.emplace_back(wtx.GetOutputValueOut(i));
result.txout_assets.emplace_back(wtx.GetOutputAsset(i));
}
result.credit = wtx.GetCredit(ISMINE_ALL);
result.debit = wtx.GetDebit(ISMINE_ALL);
result.change = wtx.GetChange();
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ struct WalletTx
std::vector<isminetype> txout_is_mine;
std::vector<CTxDestination> txout_address;
std::vector<isminetype> txout_address_is_mine;
std::vector<CAmount> txout_amounts;
std::vector<CAsset> txout_assets;
CAmountMap credit;
CAmountMap debit;
CAmountMap change;
Expand Down
22 changes: 10 additions & 12 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
//
// Debit
//
CAmount nTxFee = nDebit - wtx.tx->GetValueOutMap()[::policyAsset];

for (unsigned int nOut = 0; nOut < wtx.tx->vout.size(); nOut++)
{
const CTxOut& txout = wtx.tx->vout[nOut];

if(wtx.txout_is_mine[nOut])
if(wtx.txout_is_mine[nOut] || txout.IsFee())
{
// Ignore parts sent to self, as this is usually the change
// from a transaction sent back to our own address.
Expand All @@ -121,6 +120,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
TransactionRecord sub(hash, nTime);
sub.idx = nOut;
sub.involvesWatchAddress = involvesWatchAddress;
sub.debit = -wtx.txout_amounts[nOut];

if (!boost::get<CNoDestination>(&wtx.txout_address[nOut]))
{
Expand All @@ -134,16 +134,14 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
sub.type = TransactionRecord::SendToOther;
sub.address = mapValue["to"];
}

CAmount nValue = txout.nValue.GetAmount();
/* Add fee to first output */
if (nTxFee > 0)
{
nValue += nTxFee;
nTxFee = 0;
}
sub.debit = -nValue;

parts.append(sub);
}
CAmount nTxFee = GetFeeMap(*wtx.tx)[::policyAsset];
if (nTxFee > 0)
{
TransactionRecord sub(hash, nTime);
sub.type = TransactionRecord::Fee;
sub.debit = -nTxFee;
parts.append(sub);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/qt/transactionrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class TransactionRecord
SendToOther,
RecvWithAddress,
RecvFromOther,
SendToSelf
SendToSelf,
Fee
};

/** Number of confirmation recommended for accepting a transaction */
Expand Down
3 changes: 3 additions & 0 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const
return tr("Payment to yourself");
case TransactionRecord::Generated:
return tr("Mined");
case TransactionRecord::Fee:
return tr("Fee");
default:
return QString();
}
Expand All @@ -372,6 +374,7 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx
return QIcon(":/icons/tx_input");
case TransactionRecord::SendToAddress:
case TransactionRecord::SendToOther:
case TransactionRecord::Fee:
return QIcon(":/icons/tx_output");
default:
return QIcon(":/icons/tx_inout");
Expand Down
1 change: 1 addition & 0 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
TransactionFilterProxy::TYPE(TransactionRecord::SendToOther));
typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated));
typeWidget->addItem(tr("Fee"), TransactionFilterProxy::TYPE(TransactionRecord::Fee));
typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));

hlayout->addWidget(typeWidget);
Expand Down

0 comments on commit 3edcdf8

Please sign in to comment.