diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -60,9 +60,9 @@ strHTML += ""; int64_t nTime = wtx.GetTxTime(); - CAmount nCredit = wtx.GetCredit(ISMINE_ALL).GetSatoshis(); - CAmount nDebit = wtx.GetDebit(ISMINE_ALL); - CAmount nNet = nCredit - nDebit; + Amount nCredit = wtx.GetCredit(ISMINE_ALL); + Amount nDebit = wtx.GetDebit(ISMINE_ALL); + CAmount nNet = (nCredit - nDebit).GetSatoshis(); strHTML += "" + tr("Status") + ": " + FormatTxStatus(wtx); int nRequests = wtx.GetRequestCount(); @@ -219,13 +219,15 @@ if (fAllToMe) { // Payment to self - CAmount nChange = wtx.GetChange().GetSatoshis(); - CAmount nValue = nCredit - nChange; + Amount nChange = wtx.GetChange(); + Amount nValue = nCredit - nChange; strHTML += "" + tr("Total debit") + ": " + - BitcoinUnits::formatHtmlWithUnit(unit, -nValue) + + BitcoinUnits::formatHtmlWithUnit( + unit, -nValue.GetSatoshis()) + "
"; strHTML += "" + tr("Total credit") + ": " + - BitcoinUnits::formatHtmlWithUnit(unit, nValue) + + BitcoinUnits::formatHtmlWithUnit( + unit, nValue.GetSatoshis()) + "
"; } @@ -241,10 +243,12 @@ // for (const CTxIn &txin : wtx.tx->vin) { if (wallet->IsMine(txin)) - strHTML += "" + tr("Debit") + ": " + - BitcoinUnits::formatHtmlWithUnit( - unit, -wallet->GetDebit(txin, ISMINE_ALL)) + - "
"; + strHTML += + "" + tr("Debit") + ": " + + BitcoinUnits::formatHtmlWithUnit( + unit, + -wallet->GetDebit(txin, ISMINE_ALL).GetSatoshis()) + + "
"; } for (const CTxOut &txout : wtx.tx->vout) { if (wallet->IsMine(txout)) @@ -320,10 +324,12 @@ strHTML += "

" + tr("Debug information") + "

"; for (const CTxIn &txin : wtx.tx->vin) { if (wallet->IsMine(txin)) - strHTML += "" + tr("Debit") + ": " + - BitcoinUnits::formatHtmlWithUnit( - unit, -wallet->GetDebit(txin, ISMINE_ALL)) + - "
"; + strHTML += + "" + tr("Debit") + ": " + + BitcoinUnits::formatHtmlWithUnit( + unit, + -wallet->GetDebit(txin, ISMINE_ALL).GetSatoshis()) + + "
"; } for (const CTxOut &txout : wtx.tx->vout) { if (wallet->IsMine(txout)) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -34,9 +34,9 @@ const CWalletTx &wtx) { QList parts; int64_t nTime = wtx.GetTxTime(); - CAmount nCredit = wtx.GetCredit(ISMINE_ALL).GetSatoshis(); - CAmount nDebit = wtx.GetDebit(ISMINE_ALL); - CAmount nNet = nCredit - nDebit; + Amount nCredit = wtx.GetCredit(ISMINE_ALL); + Amount nDebit = wtx.GetDebit(ISMINE_ALL); + CAmount nNet = (nCredit - nDebit).GetSatoshis(); uint256 hash = wtx.GetId(); std::map mapValue = wtx.mapValue; @@ -92,9 +92,10 @@ // Payment to self CAmount nChange = wtx.GetChange().GetSatoshis(); - parts.append( - TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, - "", -(nDebit - nChange), nCredit - nChange)); + parts.append(TransactionRecord(hash, nTime, + TransactionRecord::SendToSelf, "", + -(nDebit - nChange).GetSatoshis(), + (nCredit - nChange).GetSatoshis())); // maybe pass to TransactionRecord as constructor argument parts.last().involvesWatchAddress = involvesWatchAddress; } else if (fAllFromMe) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2233,9 +2233,9 @@ const CWalletTx &wtx = pwalletMain->mapWallet[hash]; - CAmount nCredit = wtx.GetCredit(filter).GetSatoshis(); - CAmount nDebit = wtx.GetDebit(filter); - CAmount nNet = nCredit - nDebit; + Amount nCredit = wtx.GetCredit(filter); + Amount nDebit = wtx.GetDebit(filter); + CAmount nNet = (nCredit - nDebit).GetSatoshis(); CAmount nFee = (wtx.IsFromMe(filter) ? wtx.tx->GetValueOut() - nDebit : Amount(0)) .GetSatoshis(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -284,7 +284,7 @@ mutable bool fImmatureWatchCreditCached; mutable bool fAvailableWatchCreditCached; mutable bool fChangeCached; - mutable CAmount nDebitCached; + mutable Amount nDebitCached; mutable Amount nCreditCached; mutable CAmount nImmatureCreditCached; mutable CAmount nAvailableCreditCached; @@ -393,7 +393,7 @@ } //! filter decides which addresses will count towards the debit - CAmount GetDebit(const isminefilter &filter) const; + Amount GetDebit(const isminefilter &filter) const; Amount GetCredit(const isminefilter &filter) const; CAmount GetImmatureCredit(bool fUseCache = true) const; CAmount GetAvailableCredit(bool fUseCache = true) const; @@ -902,7 +902,7 @@ * Returns amount of debit if the input matches the filter, otherwise * returns 0 */ - CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const; + Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const; isminetype IsMine(const CTxOut &txout) const; Amount GetCredit(const CTxOut &txout, const isminefilter &filter) const; bool IsChange(const CTxOut &txout) const; @@ -910,7 +910,7 @@ bool IsMine(const CTransaction &tx) const; /** should probably be renamed to IsRelevantToMe */ bool IsFromMe(const CTransaction &tx) const; - CAmount GetDebit(const CTransaction &tx, const isminefilter &filter) const; + Amount GetDebit(const CTransaction &tx, const isminefilter &filter) const; /** Returns whether all of the inputs match the filter */ bool IsAllFromMe(const CTransaction &tx, const isminefilter &filter) const; Amount GetCredit(const CTransaction &tx, const isminefilter &filter) const; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1360,7 +1360,7 @@ // Note that this function doesn't distinguish between a 0-valued input, and a // not-"is mine" (according to the filter) input. -CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter &filter) const { +Amount CWallet::GetDebit(const CTxIn &txin, const isminefilter &filter) const { LOCK(cs_wallet); std::map::const_iterator mi = mapWallet.find(txin.prevout.hash); @@ -1437,9 +1437,9 @@ return GetDebit(tx, ISMINE_ALL) > 0; } -CAmount CWallet::GetDebit(const CTransaction &tx, - const isminefilter &filter) const { - CAmount nDebit = 0; +Amount CWallet::GetDebit(const CTransaction &tx, + const isminefilter &filter) const { + Amount nDebit = 0; for (const CTxIn &txin : tx.vin) { nDebit += GetDebit(txin, filter); if (!MoneyRange(nDebit)) { @@ -1617,11 +1617,11 @@ strSentAccount = strFromAccount; // Compute fee: - CAmount nDebit = GetDebit(filter); + Amount nDebit = GetDebit(filter); // debit>0 means we signed/sent this transaction. if (nDebit > 0) { - CAmount nValueOut = tx->GetValueOut().GetSatoshis(); - nFee = nDebit - nValueOut; + Amount nValueOut = tx->GetValueOut(); + nFee = (nDebit - nValueOut).GetSatoshis(); } // Sent/received. @@ -1631,7 +1631,7 @@ // Only need to handle txouts if AT LEAST one of these is true: // 1) they debit from us (sent) // 2) the output is to us (received) - if (nDebit > 0) { + if (nDebit > Amount(0)) { // Don't report 'change' txouts if (pwallet->IsChange(txout)) { continue; @@ -1655,7 +1655,7 @@ // If we are debited by the transaction, add the output as a "sent" // entry. - if (nDebit > 0) { + if (nDebit > Amount(0)) { listSent.push_back(output); } @@ -1840,15 +1840,16 @@ return result; } -CAmount CWalletTx::GetDebit(const isminefilter &filter) const { +Amount CWalletTx::GetDebit(const isminefilter &filter) const { if (tx->vin.empty()) return 0; - CAmount debit = 0; + Amount debit = 0; if (filter & ISMINE_SPENDABLE) { if (fDebitCached) { debit += nDebitCached; } else { - nDebitCached = pwallet->GetDebit(*this, ISMINE_SPENDABLE); + nDebitCached = + pwallet->GetDebit(*this, ISMINE_SPENDABLE).GetSatoshis(); fDebitCached = true; debit += nDebitCached; } @@ -1858,9 +1859,10 @@ if (fWatchDebitCached) { debit += nWatchDebitCached; } else { - nWatchDebitCached = pwallet->GetDebit(*this, ISMINE_WATCH_ONLY); + nWatchDebitCached = + pwallet->GetDebit(*this, ISMINE_WATCH_ONLY).GetSatoshis(); fWatchDebitCached = true; - debit += nWatchDebitCached; + debit += Amount(nWatchDebitCached); } }