Skip to content

Commit bc3dc13

Browse files
instagibbsstevenroose
authored andcommitted
Fix qt usages of txout-based GetCredit
1 parent 0746330 commit bc3dc13

5 files changed

Lines changed: 28 additions & 22 deletions

File tree

src/interfaces/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ class WalletImpl : public Wallet
402402
LOCK2(::cs_main, m_wallet.cs_wallet);
403403
return m_wallet.GetDebit(txin, filter);
404404
}
405-
CAmountMap getCredit(const CTxOut& txout, isminefilter filter) override
405+
CAmountMap getCredit(const CTransaction& tx, const size_t out_index, isminefilter filter) override
406406
{
407407
LOCK2(::cs_main, m_wallet.cs_wallet);
408-
return m_wallet.GetCredit(txout, filter);
408+
return m_wallet.GetCredit(tx, out_index, filter);
409409
}
410410
CoinsList listCoins() override
411411
{

src/interfaces/wallet.h

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

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

221221
//! Return AvailableCoins + LockedCoins grouped by wallet address.
222222
//! (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
@@ -133,8 +133,8 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
133133
// Coinbase
134134
//
135135
CAmount nUnmatured = 0;
136-
for (const CTxOut& txout : wtx.tx->vout)
137-
nUnmatured += valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset);
136+
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++)
137+
nUnmatured += valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset);
138138
strHTML += "<b>" + tr("Credit") + ":</b> ";
139139
if (status.is_in_main_chain)
140140
strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", status.blocks_to_maturity) + ")";
@@ -230,9 +230,9 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
230230
}
231231
}
232232
mine = wtx.txout_is_mine.begin();
233-
for (const CTxOut& txout : wtx.tx->vout) {
233+
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++) {
234234
if (*(mine++)) {
235-
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset)) + "<br>";
235+
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset)) + "<br>";
236236
}
237237
}
238238
}
@@ -288,9 +288,12 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
288288
for (const CTxIn& txin : wtx.tx->vin)
289289
if(wallet.txinIsMine(txin))
290290
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -valueFor(wallet.getDebit(txin, ISMINE_ALL), ::policyAsset)) + "<br>";
291-
for (const CTxOut& txout : wtx.tx->vout)
292-
if(wallet.txoutIsMine(txout))
293-
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset)) + "<br>";
291+
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++) {
292+
const CTxOut& txout = wtx.tx->vout[nOut];
293+
if(wallet.txoutIsMine(txout)) {
294+
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset)) + "<br>";
295+
}
296+
}
294297

295298
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
296299
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
@@ -1263,19 +1263,22 @@ isminetype CWallet::IsMine(const CTxOut& txout) const
12631263
return ::IsMine(*this, txout.scriptPubKey);
12641264
}
12651265

1266-
CAmountMap CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) const
1266+
CAmountMap CWallet::GetCredit(const CTransaction& tx, const size_t out_index, const isminefilter& filter) const
12671267
{
1268-
assert(false && "CWallet::GetCredit(const CTxOut&, const isminefilter&): this method should not be used anymore");
1269-
1270-
CAmountMap credit;
1271-
if (txout.nAsset.IsExplicit() && txout.nValue.IsExplicit()) {
1272-
credit[txout.nAsset.GetAsset()] = txout.nValue.GetAmount();
1273-
} else {
1274-
WalletLogPrintf("WARNING: Calculating credit of blinded transaction.\n");
1268+
{
1269+
LOCK(cs_wallet);
1270+
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(tx.GetHash());
1271+
if (mi != mapWallet.end())
1272+
{
1273+
const CWalletTx& wtx = (*mi).second;
1274+
if (out_index < wtx.tx->vout.size() && IsMine(wtx.tx->vout[out_index]) & filter) {
1275+
CAmountMap amounts;
1276+
amounts[wtx.GetOutputAsset(out_index)] = std::max<CAmount>(0, wtx.GetOutputValueOut(out_index));
1277+
return amounts;
1278+
}
1279+
}
12751280
}
1276-
if (!MoneyRange(credit))
1277-
throw std::runtime_error(std::string(__func__) + ": value out of range");
1278-
return ((IsMine(txout) & filter) ? credit : CAmountMap());
1281+
return CAmountMap();
12791282
}
12801283

12811284
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
@@ -1067,7 +1067,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
10671067
*/
10681068
CAmountMap GetDebit(const CTxIn& txin, const isminefilter& filter) const;
10691069
isminetype IsMine(const CTxOut& txout) const;
1070-
CAmountMap GetCredit(const CTxOut& txout, const isminefilter& filter) const;
1070+
CAmountMap GetCredit(const CTransaction& tx, const size_t out_index, const isminefilter& filter) const;
10711071
bool IsChange(const CTxOut& txout) const;
10721072
CAmountMap GetChange(const CTxOut& txout) const;
10731073
bool IsMine(const CTransaction& tx) const;

0 commit comments

Comments
 (0)