diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 6e9c67f7e..32d92bbbe 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -133,8 +133,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco // Coinbase // CAmount nUnmatured = 0; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) - nUnmatured += wallet->GetCredit(txout, ISMINE_ALL); + for (int i = 0; i < wtx.vout.size(); i++) + nUnmatured += wallet->GetCredit(wtx, i, ISMINE_ALL); + strHTML += "" + tr("Credit") + ": "; if (wtx.IsInMainChain()) strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")"; @@ -159,9 +160,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco } isminetype fAllToMe = ISMINE_SPENDABLE; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (int i = 0; i < wtx.vout.size(); i++) { - isminetype mine = wallet->IsMine(txout); + isminetype mine = wallet->IsMine(wtx, i); if(fAllToMe > mine) fAllToMe = mine; } @@ -173,10 +174,11 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco // // Debit // - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (int i = 0; i < wtx.vout.size(); i++) { + const CTxOut& txout = wtx.vout[i]; // Ignore change - isminetype toSelf = wallet->IsMine(txout); + isminetype toSelf = wallet->IsMine(wtx, i); if ((toSelf == ISMINE_SPENDABLE) && (fAllFromMe == ISMINE_SPENDABLE)) continue; @@ -224,9 +226,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco BOOST_FOREACH(const CTxIn& txin, wtx.vin) if (wallet->IsMine(txin)) strHTML += "" + tr("Debit") + ": " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "
"; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) - if (wallet->IsMine(txout)) - strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(txout, ISMINE_ALL)) + "
"; + for (int i = 0; i < wtx.vout.size(); i++) + if (wallet->IsMine(wtx, i)) + strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(wtx, i, ISMINE_ALL)) + "
"; } } @@ -281,9 +283,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco BOOST_FOREACH(const CTxIn& txin, wtx.vin) if(wallet->IsMine(txin)) strHTML += "" + tr("Debit") + ": " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "
"; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) - if(wallet->IsMine(txout)) - strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(txout, ISMINE_ALL)) + "
"; + for (int i = 0; i < wtx.vout.size(); i++) + if (wallet->IsMine(wtx, i)) + strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(wtx, i, ISMINE_ALL)) + "
"; strHTML += "
" + tr("Transaction") + ":
"; strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true); @@ -310,8 +312,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco strHTML += QString::fromStdString(CBitcoinAddress(address).ToString()); } strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatHtmlWithUnit(unit, vout.nValue); - strHTML = strHTML + " IsMine=" + (wallet->IsMine(vout) & ISMINE_SPENDABLE ? tr("true") : tr("false")) + ""; - strHTML = strHTML + " IsWatchOnly=" + (wallet->IsMine(vout) & ISMINE_WATCH_ONLY ? tr("true") : tr("false")) + ""; + strHTML = strHTML + " IsMine=" + (wallet->IsMine(prev, prevout.n) & ISMINE_SPENDABLE ? tr("true") : tr("false")) + ""; + strHTML = strHTML + " IsWatchOnly=" + (wallet->IsMine(prev, prevout.n) & ISMINE_WATCH_ONLY ? tr("true") : tr("false")) + ""; } } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5ffaed5fd..170014885 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1395,7 +1395,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const { const CWalletTx& prev = (*mi).second; if (txin.prevout.n < prev.vout.size()) - return IsMine(prev.vout[txin.prevout.n]); + return IsMine(prev, txin.prevout.n); } } return ISMINE_NO; @@ -1410,7 +1410,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const { const CWalletTx& prev = (*mi).second; if (txin.prevout.n < prev.vout.size()) - if (IsMine(prev.vout[txin.prevout.n]) & filter) + if (IsMine(prev, txin.prevout.n) & filter) return prev.vout[txin.prevout.n].nValue; // komodo_interest? } } @@ -1487,7 +1487,7 @@ unsigned int HaveKeys(const vector& pubkeys, const CKeyStore& keystore) // special case handling for non-standard/Verus OP_RETURN script outputs, which need the transaction // to determine ownership -isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum) +isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum) const { vector vSolutions; txnouttype whichType; @@ -1608,14 +1608,19 @@ CAmount CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) co return nDebit; } +CAmount CWallet::GetCredit(const CTransaction& tx, int32_t voutNum, const isminefilter& filter) const +{ + if (voutNum >= tx.vout.size() || !MoneyRange(tx.vout[voutNum].nValue)) + throw std::runtime_error("CWallet::GetCredit(): value out of range"); + return ((IsMine(tx, voutNum) & filter) ? tx.vout[voutNum].nValue : 0); +} + CAmount CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) const { CAmount nCredit = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) + for (int i = 0; i < tx.vout.size(); i++) { - nCredit += GetCredit(txout, filter); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWallet::GetCredit(): value out of range"); + nCredit += GetCredit(tx, i, filter); } return nCredit; } @@ -2119,8 +2124,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const { if (!pwallet->IsSpent(hashTx, i)) { - const CTxOut &txout = vout[i]; - nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); + nCredit += pwallet->GetCredit(*this, i, ISMINE_SPENDABLE); if (!MoneyRange(nCredit)) throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); } @@ -2162,8 +2166,7 @@ CAmount CWalletTx::GetAvailableWatchOnlyCredit(const bool& fUseCache) const { if (!pwallet->IsSpent(GetHash(), i)) { - const CTxOut &txout = vout[i]; - nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); + nCredit += pwallet->GetCredit(*this, i, ISMINE_WATCH_ONLY); if (!MoneyRange(nCredit)) throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); } @@ -2392,9 +2395,9 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if (nDepth < 0) continue; - for (unsigned int i = 0; i < pcoin->vout.size(); i++) + for (int i = 0; i < pcoin->vout.size(); i++) { - isminetype mine = IsMine(pcoin->vout[i]); + isminetype mine = IsMine(*pcoin, i); if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO && !IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) && (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7662d3b44..e1dc30a3a 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1050,7 +1050,7 @@ public: isminetype IsMine(const CTxIn& txin) const; CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const; isminetype IsMine(const CTxOut& txout) const; - isminetype IsMine(const CTransaction& tx, uint32_t voutNum); + isminetype IsMine(const CTransaction& tx, uint32_t voutNum) const; CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const; bool IsChange(const CTxOut& txout) const; CAmount GetChange(const CTxOut& txout) const; @@ -1058,6 +1058,7 @@ public: /** should probably be renamed to IsRelevantToMe */ bool IsFromMe(const CTransaction& tx) const; CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const; + CAmount GetCredit(const CTransaction& tx, int32_t voutNum, const isminefilter& filter) const; CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const; CAmount GetChange(const CTransaction& tx) const; void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, ZCIncrementalMerkleTree tree, bool added);