Skip to content

Commit 1ae68dc

Browse files
committed
Fix qt usages of txout-based GetCredit
1 parent c17af5d commit 1ae68dc

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

src/interfaces/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ class WalletImpl : public Wallet
438438
LOCK(m_wallet->cs_wallet);
439439
return m_wallet->GetDebit(txin, filter);
440440
}
441-
CAmountMap getCredit(const CTxOut& txout, isminefilter filter) override
441+
CAmountMap getCredit(const CTransaction& tx, const size_t out_index, isminefilter filter) override
442442
{
443443
auto locked_chain = m_wallet->chain().lock();
444444
LOCK(m_wallet->cs_wallet);
445-
return m_wallet->GetCredit(txout, filter);
445+
return m_wallet->GetCredit(tx, out_index, filter);
446446
}
447447
CoinsList listCoins() override
448448
{

src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Wallet
215215
virtual CAmountMap getDebit(const CTxIn& txin, isminefilter filter) = 0;
216216

217217
//! Return credit amount if transaction input belongs to wallet.
218-
virtual CAmountMap getCredit(const CTxOut& txout, isminefilter filter) = 0;
218+
virtual CAmountMap getCredit(const CTransaction& tx, const size_t out_index, isminefilter filter) = 0;
219219

220220
//! Return AvailableCoins + LockedCoins grouped by wallet address.
221221
//! (put change in one group with wallet address)

src/qt/transactiondesc.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
136136
// Coinbase
137137
//
138138
CAmount nUnmatured = 0;
139-
for (const CTxOut& txout : wtx.tx->vout)
140-
nUnmatured += valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset);
139+
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++)
140+
nUnmatured += valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset);
141141
strHTML += "<b>" + tr("Credit") + ":</b> ";
142142
if (status.is_in_main_chain)
143143
strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", status.blocks_to_maturity) + ")";
@@ -233,9 +233,9 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
233233
}
234234
}
235235
mine = wtx.txout_is_mine.begin();
236-
for (const CTxOut& txout : wtx.tx->vout) {
236+
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++) {
237237
if (*(mine++)) {
238-
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset)) + "<br>";
238+
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset)) + "<br>";
239239
}
240240
}
241241
}
@@ -293,9 +293,12 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
293293
for (const CTxIn& txin : wtx.tx->vin)
294294
if(wallet.txinIsMine(txin))
295295
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -valueFor(wallet.getDebit(txin, ISMINE_ALL), ::policyAsset)) + "<br>";
296-
for (const CTxOut& txout : wtx.tx->vout)
297-
if(wallet.txoutIsMine(txout))
298-
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset)) + "<br>";
296+
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++) {
297+
const CTxOut& txout = wtx.tx->vout[nOut];
298+
if(wallet.txoutIsMine(txout)) {
299+
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset)) + "<br>";
300+
}
301+
}
299302

300303
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
301304
strHTML += GUIUtil::HtmlEscape(wtx.tx->ToString(), true);

src/wallet/wallet.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,19 +1346,22 @@ isminetype CWallet::IsMine(const CTxOut& txout) const
13461346
return ::IsMine(*this, txout.scriptPubKey);
13471347
}
13481348

1349-
CAmountMap CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) const
1349+
CAmountMap CWallet::GetCredit(const CTransaction& tx, const size_t out_index, const isminefilter& filter) const
13501350
{
1351-
assert(false && "CWallet::GetCredit(const CTxOut&, const isminefilter&): this method should not be used anymore");
1352-
1353-
CAmountMap credit;
1354-
if (txout.nAsset.IsExplicit() && txout.nValue.IsExplicit()) {
1355-
credit[txout.nAsset.GetAsset()] = txout.nValue.GetAmount();
1356-
} else {
1357-
WalletLogPrintf("WARNING: Calculating credit of blinded transaction.\n");
1351+
{
1352+
LOCK(cs_wallet);
1353+
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(tx.GetHash());
1354+
if (mi != mapWallet.end())
1355+
{
1356+
const CWalletTx& wtx = (*mi).second;
1357+
if (out_index < wtx.tx->vout.size() && IsMine(wtx.tx->vout[out_index]) & filter) {
1358+
CAmountMap amounts;
1359+
amounts[wtx.GetOutputAsset(out_index)] = std::max<CAmount>(0, wtx.GetOutputValueOut(out_index));
1360+
return amounts;
1361+
}
1362+
}
13581363
}
1359-
if (!MoneyRange(credit))
1360-
throw std::runtime_error(std::string(__func__) + ": value out of range");
1361-
return ((IsMine(txout) & filter) ? credit : CAmountMap());
1364+
return CAmountMap();
13621365
}
13631366

13641367
bool CWallet::IsChange(const CTxOut& txout) const

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
11491149
*/
11501150
CAmountMap GetDebit(const CTxIn& txin, const isminefilter& filter) const;
11511151
isminetype IsMine(const CTxOut& txout) const;
1152-
CAmountMap GetCredit(const CTxOut& txout, const isminefilter& filter) const;
1152+
CAmountMap GetCredit(const CTransaction& tx, const size_t out_index, const isminefilter& filter) const;
11531153
bool IsChange(const CTxOut& txout) const;
11541154
bool IsChange(const CScript& script) const;
11551155
CAmountMap GetChange(const CTxOut& txout) const;

0 commit comments

Comments
 (0)