aboutsummaryrefslogtreecommitdiff
path: root/src/qt/transactionrecord.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2018-12-15 19:52:03 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2023-06-23 02:05:24 +0000
commitf3fbe99fcf90daec79d49fd5d868102dc99feb23 (patch)
treea84011ce1fd3e7ef37cbd28f70c4e556f27db728 /src/qt/transactionrecord.cpp
parentb9765ba1d67d7b74c17f9ce70cad5487715208a0 (diff)
downloadbitcoin-f3fbe99fcf90daec79d49fd5d868102dc99feb23.tar.xz
GUI: TransactionRecord: Refactor to turn send-to-self into send+receive pairs
Diffstat (limited to 'src/qt/transactionrecord.cpp')
-rw-r--r--src/qt/transactionrecord.cpp130
1 files changed, 53 insertions, 77 deletions
diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp
index 4b48b124d4..8a373451eb 100644
--- a/src/qt/transactionrecord.cpp
+++ b/src/qt/transactionrecord.cpp
@@ -54,90 +54,36 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
}
}
- if (!any_from_me) {
- //
- // Credit
- //
- for(unsigned int i = 0; i < wtx.tx->vout.size(); i++)
- {
- const CTxOut& txout = wtx.tx->vout[i];
- isminetype mine = wtx.txout_is_mine[i];
- if(mine)
- {
- TransactionRecord sub(hash, nTime);
- sub.idx = i; // vout index
- sub.credit = txout.nValue;
- sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY;
- if (wtx.txout_address_is_mine[i])
- {
- // Received by Bitcoin Address
- sub.type = TransactionRecord::RecvWithAddress;
- sub.address = EncodeDestination(wtx.txout_address[i]);
- }
- else
- {
- // Received by IP connection (deprecated features), or a multisignature or other non-simple transaction
- sub.type = TransactionRecord::RecvFromOther;
- sub.address = mapValue["from"];
- }
- if (wtx.is_coinbase)
- {
- // Generated
- sub.type = TransactionRecord::Generated;
- }
-
- parts.append(sub);
- }
- }
- }
- else
- {
- isminetype fAllToMe = ISMINE_SPENDABLE;
+ if (fAllFromMe || !any_from_me) {
for (const isminetype mine : wtx.txout_is_mine)
{
if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true;
- if(fAllToMe > mine) fAllToMe = mine;
}
- if (fAllFromMe && fAllToMe)
+ CAmount nTxFee = nDebit - wtx.tx->GetValueOut();
+
+ for(unsigned int i = 0; i < wtx.tx->vout.size(); i++)
{
- // Payment to self
- std::string address;
- for (auto it = wtx.txout_address.begin(); it != wtx.txout_address.end(); ++it) {
- if (it != wtx.txout_address.begin()) address += ", ";
- address += EncodeDestination(*it);
+ const CTxOut& txout = wtx.tx->vout[i];
+
+ if (wtx.txout_is_change[i]) {
+ continue;
}
- CAmount nChange = wtx.change;
- parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, address, -(nDebit - nChange), nCredit - nChange));
- parts.last().involvesWatchAddress = involvesWatchAddress; // maybe pass to TransactionRecord as constructor argument
- }
- else if (fAllFromMe)
- {
- //
- // Debit
- //
- CAmount nTxFee = nDebit - wtx.tx->GetValueOut();
+ if (fAllFromMe) {
+ //
+ // Debit
+ //
- for (unsigned int nOut = 0; nOut < wtx.tx->vout.size(); nOut++)
- {
- const CTxOut& txout = wtx.tx->vout[nOut];
TransactionRecord sub(hash, nTime);
- sub.idx = nOut;
+ sub.idx = i;
sub.involvesWatchAddress = involvesWatchAddress;
- if(wtx.txout_is_mine[nOut])
- {
- // Ignore parts sent to self, as this is usually the change
- // from a transaction sent back to our own address.
- continue;
- }
-
- if (!std::get_if<CNoDestination>(&wtx.txout_address[nOut]))
+ if (!std::get_if<CNoDestination>(&wtx.txout_address[i]))
{
// Sent to Bitcoin Address
sub.type = TransactionRecord::SendToAddress;
- sub.address = EncodeDestination(wtx.txout_address[nOut]);
+ sub.address = EncodeDestination(wtx.txout_address[i]);
}
else
{
@@ -157,15 +103,45 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
parts.append(sub);
}
+
+ isminetype mine = wtx.txout_is_mine[i];
+ if(mine)
+ {
+ //
+ // Credit
+ //
+
+ TransactionRecord sub(hash, nTime);
+ sub.idx = i; // vout index
+ sub.credit = txout.nValue;
+ sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY;
+ if (wtx.txout_address_is_mine[i])
+ {
+ // Received by Bitcoin Address
+ sub.type = TransactionRecord::RecvWithAddress;
+ sub.address = EncodeDestination(wtx.txout_address[i]);
+ }
+ else
+ {
+ // Received by IP connection (deprecated features), or a multisignature or other non-simple transaction
+ sub.type = TransactionRecord::RecvFromOther;
+ sub.address = mapValue["from"];
+ }
+ if (wtx.is_coinbase)
+ {
+ // Generated
+ sub.type = TransactionRecord::Generated;
+ }
+
+ parts.append(sub);
+ }
}
- else
- {
- //
- // Mixed debit transaction, can't break down payees
- //
- parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0));
- parts.last().involvesWatchAddress = involvesWatchAddress;
- }
+ } else {
+ //
+ // Mixed debit transaction, can't break down payees
+ //
+ parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0));
+ parts.last().involvesWatchAddress = involvesWatchAddress;
}
return parts;