mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
GUI: TransactionRecord: Refactor to turn send-to-self into send+receive pairs
This commit is contained in:
parent
b9765ba1d6
commit
f3fbe99fcf
3 changed files with 59 additions and 81 deletions
|
@ -387,6 +387,7 @@ struct WalletTx
|
|||
CTransactionRef tx;
|
||||
std::vector<wallet::isminetype> txin_is_mine;
|
||||
std::vector<wallet::isminetype> txout_is_mine;
|
||||
std::vector<bool> txout_is_change;
|
||||
std::vector<CTxDestination> txout_address;
|
||||
std::vector<wallet::isminetype> txout_address_is_mine;
|
||||
CAmount credit;
|
||||
|
|
|
@ -54,16 +54,63 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
|
|||
}
|
||||
}
|
||||
|
||||
if (!any_from_me) {
|
||||
//
|
||||
// Credit
|
||||
//
|
||||
if (fAllFromMe || !any_from_me) {
|
||||
for (const isminetype mine : wtx.txout_is_mine)
|
||||
{
|
||||
if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true;
|
||||
}
|
||||
|
||||
CAmount nTxFee = nDebit - wtx.tx->GetValueOut();
|
||||
|
||||
for(unsigned int i = 0; i < wtx.tx->vout.size(); i++)
|
||||
{
|
||||
const CTxOut& txout = wtx.tx->vout[i];
|
||||
|
||||
if (wtx.txout_is_change[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fAllFromMe) {
|
||||
//
|
||||
// Debit
|
||||
//
|
||||
|
||||
TransactionRecord sub(hash, nTime);
|
||||
sub.idx = i;
|
||||
sub.involvesWatchAddress = involvesWatchAddress;
|
||||
|
||||
if (!std::get_if<CNoDestination>(&wtx.txout_address[i]))
|
||||
{
|
||||
// Sent to Bitcoin Address
|
||||
sub.type = TransactionRecord::SendToAddress;
|
||||
sub.address = EncodeDestination(wtx.txout_address[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sent to IP, or other non-address transaction like OP_EVAL
|
||||
sub.type = TransactionRecord::SendToOther;
|
||||
sub.address = mapValue["to"];
|
||||
}
|
||||
|
||||
CAmount nValue = txout.nValue;
|
||||
/* Add fee to first output */
|
||||
if (nTxFee > 0)
|
||||
{
|
||||
nValue += nTxFee;
|
||||
nTxFee = 0;
|
||||
}
|
||||
sub.debit = -nValue;
|
||||
|
||||
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;
|
||||
|
@ -89,83 +136,12 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
|
|||
parts.append(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isminetype fAllToMe = ISMINE_SPENDABLE;
|
||||
for (const isminetype mine : wtx.txout_is_mine)
|
||||
{
|
||||
if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true;
|
||||
if(fAllToMe > mine) fAllToMe = mine;
|
||||
}
|
||||
|
||||
if (fAllFromMe && fAllToMe)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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.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]))
|
||||
{
|
||||
// Sent to Bitcoin Address
|
||||
sub.type = TransactionRecord::SendToAddress;
|
||||
sub.address = EncodeDestination(wtx.txout_address[nOut]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sent to IP, or other non-address transaction like OP_EVAL
|
||||
sub.type = TransactionRecord::SendToOther;
|
||||
sub.address = mapValue["to"];
|
||||
}
|
||||
|
||||
CAmount nValue = txout.nValue;
|
||||
/* Add fee to first output */
|
||||
if (nTxFee > 0)
|
||||
{
|
||||
nValue += nTxFee;
|
||||
nTxFee = 0;
|
||||
}
|
||||
sub.debit = -nValue;
|
||||
|
||||
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;
|
||||
|
|
|
@ -64,6 +64,7 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
|
|||
result.txout_address_is_mine.reserve(wtx.tx->vout.size());
|
||||
for (const auto& txout : wtx.tx->vout) {
|
||||
result.txout_is_mine.emplace_back(wallet.IsMine(txout));
|
||||
result.txout_is_change.push_back(OutputIsChange(wallet, txout));
|
||||
result.txout_address.emplace_back();
|
||||
result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
|
||||
wallet.IsMine(result.txout_address.back()) :
|
||||
|
|
Loading…
Add table
Reference in a new issue