diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -60,7 +60,7 @@ strHTML += ""; int64_t nTime = wtx.GetTxTime(); - CAmount nCredit = wtx.GetCredit(ISMINE_ALL); + CAmount nCredit = wtx.GetCredit(ISMINE_ALL).GetSatoshis(); CAmount nDebit = wtx.GetDebit(ISMINE_ALL); CAmount nNet = nCredit - nDebit; @@ -137,13 +137,14 @@ // // Coinbase // - CAmount nUnmatured = 0; + Amount nUnmatured = 0; for (const CTxOut &txout : wtx.tx->vout) { nUnmatured += wallet->GetCredit(txout, ISMINE_ALL); } strHTML += "" + tr("Credit") + ": "; if (wtx.IsInMainChain()) - strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured) + + strHTML += BitcoinUnits::formatHtmlWithUnit( + unit, nUnmatured.GetSatoshis()) + " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")"; @@ -249,7 +250,8 @@ if (wallet->IsMine(txout)) strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatHtmlWithUnit( - unit, wallet->GetCredit(txout, ISMINE_ALL)) + + unit, wallet->GetCredit(txout, ISMINE_ALL) + .GetSatoshis()) + "
"; } } @@ -325,10 +327,12 @@ } for (const CTxOut &txout : wtx.tx->vout) { if (wallet->IsMine(txout)) - strHTML += "" + tr("Credit") + ": " + - BitcoinUnits::formatHtmlWithUnit( - unit, wallet->GetCredit(txout, ISMINE_ALL)) + - "
"; + strHTML += + "" + tr("Credit") + ": " + + BitcoinUnits::formatHtmlWithUnit( + unit, + wallet->GetCredit(txout, ISMINE_ALL).GetSatoshis()) + + "
"; } strHTML += "
" + tr("Transaction") + ":
"; diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -34,7 +34,7 @@ const CWalletTx &wtx) { QList parts; int64_t nTime = wtx.GetTxTime(); - CAmount nCredit = wtx.GetCredit(ISMINE_ALL); + CAmount nCredit = wtx.GetCredit(ISMINE_ALL).GetSatoshis(); CAmount nDebit = wtx.GetDebit(ISMINE_ALL); CAmount nNet = nCredit - nDebit; uint256 hash = wtx.GetId(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2233,7 +2233,7 @@ const CWalletTx &wtx = pwalletMain->mapWallet[hash]; - CAmount nCredit = wtx.GetCredit(filter); + CAmount nCredit = wtx.GetCredit(filter).GetSatoshis(); CAmount nDebit = wtx.GetDebit(filter); CAmount nNet = nCredit - nDebit; CAmount nFee = diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -285,7 +285,7 @@ mutable bool fAvailableWatchCreditCached; mutable bool fChangeCached; mutable CAmount nDebitCached; - mutable CAmount nCreditCached; + mutable Amount nCreditCached; mutable CAmount nImmatureCreditCached; mutable CAmount nAvailableCreditCached; mutable CAmount nWatchDebitCached; @@ -394,7 +394,7 @@ //! filter decides which addresses will count towards the debit CAmount GetDebit(const isminefilter &filter) const; - CAmount GetCredit(const isminefilter &filter) const; + Amount GetCredit(const isminefilter &filter) const; CAmount GetImmatureCredit(bool fUseCache = true) const; CAmount GetAvailableCredit(bool fUseCache = true) const; CAmount GetImmatureWatchOnlyCredit(const bool &fUseCache = true) const; @@ -904,7 +904,7 @@ */ CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const; isminetype IsMine(const CTxOut &txout) const; - CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const; + Amount GetCredit(const CTxOut &txout, const isminefilter &filter) const; bool IsChange(const CTxOut &txout) const; Amount GetChange(const CTxOut &txout) const; bool IsMine(const CTransaction &tx) const; @@ -913,7 +913,7 @@ CAmount 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; - CAmount GetCredit(const CTransaction &tx, const isminefilter &filter) const; + Amount GetCredit(const CTransaction &tx, const isminefilter &filter) const; Amount GetChange(const CTransaction &tx) const; void SetBestChain(const CBlockLocator &loc) override; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1380,14 +1380,14 @@ return ::IsMine(*this, txout.scriptPubKey); } -CAmount CWallet::GetCredit(const CTxOut &txout, - const isminefilter &filter) const { +Amount CWallet::GetCredit(const CTxOut &txout, + const isminefilter &filter) const { if (!MoneyRange(txout.nValue)) { throw std::runtime_error(std::string(__func__) + ": value out of range"); } - return (IsMine(txout) & filter) ? txout.nValue.GetSatoshis() : 0; + return (IsMine(txout) & filter) ? txout.nValue : Amount(0); } bool CWallet::IsChange(const CTxOut &txout) const { @@ -1477,9 +1477,9 @@ return true; } -CAmount CWallet::GetCredit(const CTransaction &tx, - const isminefilter &filter) const { - CAmount nCredit = 0; +Amount CWallet::GetCredit(const CTransaction &tx, + const isminefilter &filter) const { + Amount nCredit = 0; for (const CTxOut &txout : tx.vout) { nCredit += GetCredit(txout, filter); if (!MoneyRange(nCredit)) { @@ -1867,14 +1867,14 @@ return debit; } -CAmount CWalletTx::GetCredit(const isminefilter &filter) const { +Amount CWalletTx::GetCredit(const isminefilter &filter) const { // Must wait until coinbase is safely deep enough in the chain before // valuing it. if (IsCoinBase() && GetBlocksToMaturity() > 0) { return 0; } - CAmount credit = 0; + Amount credit = 0; if (filter & ISMINE_SPENDABLE) { // GetBalance can assume transactions in mapWallet won't change. if (fCreditCached) { @@ -1890,7 +1890,8 @@ if (fWatchCreditCached) { credit += nWatchCreditCached; } else { - nWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); + nWatchCreditCached = + pwallet->GetCredit(*this, ISMINE_WATCH_ONLY).GetSatoshis(); fWatchCreditCached = true; credit += nWatchCreditCached; } @@ -1902,7 +1903,8 @@ CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const { if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { if (fUseCache && fImmatureCreditCached) return nImmatureCreditCached; - nImmatureCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE); + nImmatureCreditCached = + pwallet->GetCredit(*this, ISMINE_SPENDABLE).GetSatoshis(); fImmatureCreditCached = true; return nImmatureCreditCached; } @@ -1930,7 +1932,8 @@ for (unsigned int i = 0; i < tx->vout.size(); i++) { if (!pwallet->IsSpent(hashTx, i)) { const CTxOut &txout = tx->vout[i]; - nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); + nCredit += + pwallet->GetCredit(txout, ISMINE_SPENDABLE).GetSatoshis(); if (!MoneyRange(nCredit)) { throw std::runtime_error( "CWalletTx::GetAvailableCredit() : value out of range"); @@ -1950,7 +1953,7 @@ } nImmatureWatchCreditCached = - pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); + pwallet->GetCredit(*this, ISMINE_WATCH_ONLY).GetSatoshis(); fImmatureWatchCreditCached = true; return nImmatureWatchCreditCached; } @@ -1973,7 +1976,7 @@ return nAvailableWatchCreditCached; } - CAmount nCredit = 0; + Amount nCredit = 0; for (unsigned int i = 0; i < tx->vout.size(); i++) { if (!pwallet->IsSpent(GetId(), i)) { const CTxOut &txout = tx->vout[i]; @@ -1985,9 +1988,9 @@ } } - nAvailableWatchCreditCached = nCredit; + nAvailableWatchCreditCached = nCredit.GetSatoshis(); fAvailableWatchCreditCached = true; - return nCredit; + return nCredit.GetSatoshis(); } Amount CWalletTx::GetChange() const {