Skip to content

Commit

Permalink
Better representation of coinbase transactions in filtertransactions
Browse files Browse the repository at this point in the history
This fixes rpc_filtertransactions.py.

Signed-off-by: Azat Nizametdinov <azat@thirdhash.com>
  • Loading branch information
Nizametdinov committed Apr 5, 2019
1 parent 687215b commit 3116477
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,9 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,

// Compute fee:
CAmount nDebit = GetDebit(filter);
if (nDebit > 0) { // debit>0 means we signed/sent this transaction
if (nDebit > 0 && !IsCoinBase()) {
// debit>0 means we signed/sent this transaction
// Coinbase transactions cannot have fees
CAmount nValueOut = tx->GetValueOut();
nFee = nDebit - nValueOut;
}
Expand All @@ -1698,7 +1700,7 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
// 2) the output is to us (received)
if (nDebit > 0) {
// Don't report 'change' txouts
if (pwallet->IsChange(txout)) {
if (!IsCoinBase() && pwallet->IsChange(txout)) {
continue;
}
} else if (!(fIsMine & filter)) {
Expand All @@ -1716,6 +1718,20 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,

COutputEntry output = {address, txout.nValue, (int)i};

if (IsCoinBase()) {
// TODO UNIT-E: implement a better way to distinguish reward outputs
// For example, current approach does not work in case of stake splitting
if (i == tx->vout.size() - 1) {
// We consider the last output (and only it) to be a non-reward output
if (nDebit > 0 && !(fIsMine & filter)) {
listSent.push_back(output);
}
} else if (fIsMine & filter) {
listReceived.push_back(output);
}
continue;
}

// If we are debited by the transaction, add the output as a "sent" entry
if (nDebit > 0) {
listSent.push_back(output);
Expand Down

0 comments on commit 3116477

Please sign in to comment.