mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Fix qt usages of txout-based GetCredit
This commit is contained in:
parent
0746330f8f
commit
bc3dc13b7e
5 changed files with 28 additions and 22 deletions
|
|
@ -402,10 +402,10 @@ public:
|
||||||
LOCK2(::cs_main, m_wallet.cs_wallet);
|
LOCK2(::cs_main, m_wallet.cs_wallet);
|
||||||
return m_wallet.GetDebit(txin, filter);
|
return m_wallet.GetDebit(txin, filter);
|
||||||
}
|
}
|
||||||
CAmountMap getCredit(const CTxOut& txout, isminefilter filter) override
|
CAmountMap getCredit(const CTransaction& tx, const size_t out_index, isminefilter filter) override
|
||||||
{
|
{
|
||||||
LOCK2(::cs_main, m_wallet.cs_wallet);
|
LOCK2(::cs_main, m_wallet.cs_wallet);
|
||||||
return m_wallet.GetCredit(txout, filter);
|
return m_wallet.GetCredit(tx, out_index, filter);
|
||||||
}
|
}
|
||||||
CoinsList listCoins() override
|
CoinsList listCoins() override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ public:
|
||||||
virtual CAmountMap getDebit(const CTxIn& txin, isminefilter filter) = 0;
|
virtual CAmountMap getDebit(const CTxIn& txin, isminefilter filter) = 0;
|
||||||
|
|
||||||
//! Return credit amount if transaction input belongs to wallet.
|
//! Return credit amount if transaction input belongs to wallet.
|
||||||
virtual CAmountMap getCredit(const CTxOut& txout, isminefilter filter) = 0;
|
virtual CAmountMap getCredit(const CTransaction& tx, const size_t out_index, isminefilter filter) = 0;
|
||||||
|
|
||||||
//! Return AvailableCoins + LockedCoins grouped by wallet address.
|
//! Return AvailableCoins + LockedCoins grouped by wallet address.
|
||||||
//! (put change in one group with wallet address)
|
//! (put change in one group with wallet address)
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,8 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
|
||||||
// Coinbase
|
// Coinbase
|
||||||
//
|
//
|
||||||
CAmount nUnmatured = 0;
|
CAmount nUnmatured = 0;
|
||||||
for (const CTxOut& txout : wtx.tx->vout)
|
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++)
|
||||||
nUnmatured += valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset);
|
nUnmatured += valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset);
|
||||||
strHTML += "<b>" + tr("Credit") + ":</b> ";
|
strHTML += "<b>" + tr("Credit") + ":</b> ";
|
||||||
if (status.is_in_main_chain)
|
if (status.is_in_main_chain)
|
||||||
strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", status.blocks_to_maturity) + ")";
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mine = wtx.txout_is_mine.begin();
|
mine = wtx.txout_is_mine.begin();
|
||||||
for (const CTxOut& txout : wtx.tx->vout) {
|
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++) {
|
||||||
if (*(mine++)) {
|
if (*(mine++)) {
|
||||||
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset)) + "<br>";
|
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset)) + "<br>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -288,9 +288,12 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
|
||||||
for (const CTxIn& txin : wtx.tx->vin)
|
for (const CTxIn& txin : wtx.tx->vin)
|
||||||
if(wallet.txinIsMine(txin))
|
if(wallet.txinIsMine(txin))
|
||||||
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -valueFor(wallet.getDebit(txin, ISMINE_ALL), ::policyAsset)) + "<br>";
|
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -valueFor(wallet.getDebit(txin, ISMINE_ALL), ::policyAsset)) + "<br>";
|
||||||
for (const CTxOut& txout : wtx.tx->vout)
|
for (size_t nOut = 0; nOut < wtx.tx->vout.size(); nOut++) {
|
||||||
if(wallet.txoutIsMine(txout))
|
const CTxOut& txout = wtx.tx->vout[nOut];
|
||||||
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(txout, ISMINE_ALL), ::policyAsset)) + "<br>";
|
if(wallet.txoutIsMine(txout)) {
|
||||||
|
strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, valueFor(wallet.getCredit(*(wtx.tx), nOut, ISMINE_ALL), ::policyAsset)) + "<br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
|
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
|
||||||
strHTML += GUIUtil::HtmlEscape(wtx.tx->ToString(), true);
|
strHTML += GUIUtil::HtmlEscape(wtx.tx->ToString(), true);
|
||||||
|
|
|
||||||
|
|
@ -1263,19 +1263,22 @@ isminetype CWallet::IsMine(const CTxOut& txout) const
|
||||||
return ::IsMine(*this, txout.scriptPubKey);
|
return ::IsMine(*this, txout.scriptPubKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAmountMap CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) const
|
CAmountMap CWallet::GetCredit(const CTransaction& tx, const size_t out_index, const isminefilter& filter) const
|
||||||
{
|
{
|
||||||
assert(false && "CWallet::GetCredit(const CTxOut&, const isminefilter&): this method should not be used anymore");
|
{
|
||||||
|
LOCK(cs_wallet);
|
||||||
CAmountMap credit;
|
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(tx.GetHash());
|
||||||
if (txout.nAsset.IsExplicit() && txout.nValue.IsExplicit()) {
|
if (mi != mapWallet.end())
|
||||||
credit[txout.nAsset.GetAsset()] = txout.nValue.GetAmount();
|
{
|
||||||
} else {
|
const CWalletTx& wtx = (*mi).second;
|
||||||
WalletLogPrintf("WARNING: Calculating credit of blinded transaction.\n");
|
if (out_index < wtx.tx->vout.size() && IsMine(wtx.tx->vout[out_index]) & filter) {
|
||||||
|
CAmountMap amounts;
|
||||||
|
amounts[wtx.GetOutputAsset(out_index)] = std::max<CAmount>(0, wtx.GetOutputValueOut(out_index));
|
||||||
|
return amounts;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!MoneyRange(credit))
|
return CAmountMap();
|
||||||
throw std::runtime_error(std::string(__func__) + ": value out of range");
|
|
||||||
return ((IsMine(txout) & filter) ? credit : CAmountMap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::IsChange(const CTxOut& txout) const
|
bool CWallet::IsChange(const CTxOut& txout) const
|
||||||
|
|
|
||||||
|
|
@ -1067,7 +1067,7 @@ public:
|
||||||
*/
|
*/
|
||||||
CAmountMap GetDebit(const CTxIn& txin, const isminefilter& filter) const;
|
CAmountMap GetDebit(const CTxIn& txin, const isminefilter& filter) const;
|
||||||
isminetype IsMine(const CTxOut& txout) const;
|
isminetype IsMine(const CTxOut& txout) const;
|
||||||
CAmountMap GetCredit(const CTxOut& txout, const isminefilter& filter) const;
|
CAmountMap GetCredit(const CTransaction& tx, const size_t out_index, const isminefilter& filter) const;
|
||||||
bool IsChange(const CTxOut& txout) const;
|
bool IsChange(const CTxOut& txout) const;
|
||||||
CAmountMap GetChange(const CTxOut& txout) const;
|
CAmountMap GetChange(const CTxOut& txout) const;
|
||||||
bool IsMine(const CTransaction& tx) const;
|
bool IsMine(const CTransaction& tx) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue