Changeset View
Changeset View
Standalone View
Standalone View
src/qt/transactionrecord.cpp
Show All 30 Lines | |||||
*/ | */ | ||||
QList<TransactionRecord> | QList<TransactionRecord> | ||||
TransactionRecord::decomposeTransaction(const CWallet *wallet, | TransactionRecord::decomposeTransaction(const CWallet *wallet, | ||||
const CWalletTx &wtx) { | const CWalletTx &wtx) { | ||||
QList<TransactionRecord> parts; | QList<TransactionRecord> parts; | ||||
int64_t nTime = wtx.GetTxTime(); | int64_t nTime = wtx.GetTxTime(); | ||||
Amount nCredit = wtx.GetCredit(ISMINE_ALL); | Amount nCredit = wtx.GetCredit(ISMINE_ALL); | ||||
Amount nDebit = wtx.GetDebit(ISMINE_ALL); | Amount nDebit = wtx.GetDebit(ISMINE_ALL); | ||||
CAmount nNet = (nCredit - nDebit).GetSatoshis(); | Amount nNet = nCredit - nDebit; | ||||
uint256 hash = wtx.GetId(); | uint256 hash = wtx.GetId(); | ||||
std::map<std::string, std::string> mapValue = wtx.mapValue; | std::map<std::string, std::string> mapValue = wtx.mapValue; | ||||
if (nNet > 0 || wtx.IsCoinBase()) { | if (nNet > 0 || wtx.IsCoinBase()) { | ||||
// | // | ||||
// Credit | // Credit | ||||
// | // | ||||
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) { | for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) { | ||||
const CTxOut &txout = wtx.tx->vout[i]; | const CTxOut &txout = wtx.tx->vout[i]; | ||||
isminetype mine = wallet->IsMine(txout); | isminetype mine = wallet->IsMine(txout); | ||||
if (mine) { | if (mine) { | ||||
TransactionRecord sub(hash, nTime); | TransactionRecord sub(hash, nTime); | ||||
CTxDestination address; | CTxDestination address; | ||||
sub.idx = i; // vout index | sub.idx = i; // vout index | ||||
sub.credit = txout.nValue.GetSatoshis(); | sub.credit = txout.nValue; | ||||
sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; | sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; | ||||
if (ExtractDestination(txout.scriptPubKey, address) && | if (ExtractDestination(txout.scriptPubKey, address) && | ||||
IsMine(*wallet, address)) { | IsMine(*wallet, address)) { | ||||
// Received by Bitcoin Address | // Received by Bitcoin Address | ||||
sub.type = TransactionRecord::RecvWithAddress; | sub.type = TransactionRecord::RecvWithAddress; | ||||
sub.address = EncodeDestination(address); | sub.address = EncodeDestination(address); | ||||
} else { | } else { | ||||
// Received by IP connection (deprecated features), or a | // Received by IP connection (deprecated features), or a | ||||
Show All 24 Lines | if (nNet > 0 || wtx.IsCoinBase()) { | ||||
if (mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true; | if (mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true; | ||||
if (fAllToMe > mine) fAllToMe = mine; | if (fAllToMe > mine) fAllToMe = mine; | ||||
} | } | ||||
if (fAllFromMe && fAllToMe) { | if (fAllFromMe && fAllToMe) { | ||||
// Payment to self | // Payment to self | ||||
Amount nChange = wtx.GetChange(); | Amount nChange = wtx.GetChange(); | ||||
parts.append(TransactionRecord(hash, nTime, | parts.append(TransactionRecord( | ||||
TransactionRecord::SendToSelf, "", | hash, nTime, TransactionRecord::SendToSelf, "", | ||||
-(nDebit - nChange).GetSatoshis(), | -1 * (nDebit - nChange), (nCredit - nChange))); | ||||
(nCredit - nChange).GetSatoshis())); | |||||
// maybe pass to TransactionRecord as constructor argument | // maybe pass to TransactionRecord as constructor argument | ||||
parts.last().involvesWatchAddress = involvesWatchAddress; | parts.last().involvesWatchAddress = involvesWatchAddress; | ||||
} else if (fAllFromMe) { | } else if (fAllFromMe) { | ||||
// | // | ||||
// Debit | // Debit | ||||
// | // | ||||
Amount nTxFee = nDebit - wtx.tx->GetValueOut(); | Amount nTxFee = nDebit - wtx.tx->GetValueOut(); | ||||
Show All 21 Lines | if (nNet > 0 || wtx.IsCoinBase()) { | ||||
} | } | ||||
Amount nValue = txout.nValue; | Amount nValue = txout.nValue; | ||||
/* Add fee to first output */ | /* Add fee to first output */ | ||||
if (nTxFee > Amount(0)) { | if (nTxFee > Amount(0)) { | ||||
nValue += nTxFee; | nValue += nTxFee; | ||||
nTxFee = Amount(0); | nTxFee = Amount(0); | ||||
} | } | ||||
sub.debit = -nValue.GetSatoshis(); | sub.debit = -1 * nValue; | ||||
parts.append(sub); | parts.append(sub); | ||||
} | } | ||||
} else { | } else { | ||||
// | // | ||||
// Mixed debit transaction, can't break down payees | // Mixed debit transaction, can't break down payees | ||||
// | // | ||||
parts.append(TransactionRecord( | parts.append(TransactionRecord( | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |