Fix for calling GetAmount on potentially blinded output

Introduced in 103069c46c
for Bitcoin PR bitcoin/bitcoin#22100
This commit is contained in:
Byron Hambly 2023-08-08 14:11:12 +02:00
parent 941940e946
commit b958e586ef
No known key found for this signature in database
GPG key ID: DE8F6EA20A661697
2 changed files with 6 additions and 22 deletions

View file

@ -113,27 +113,12 @@ bool ScriptIsChange(const CWallet& wallet, const CScript& script)
return false;
}
CAmountMap OutputGetChange(const CWallet& wallet, const CTxOut& txout)
{
AssertLockHeld(wallet.cs_wallet);
CAmountMap change;
change[txout.nAsset.GetAsset()] = txout.nValue.GetAmount();
if (!MoneyRange(change))
throw std::runtime_error(std::string(__func__) + ": value out of range");
return (OutputIsChange(wallet, txout) ? change : CAmountMap());
}
CAmountMap TxGetChange(const CWallet& wallet, const CTransaction& tx)
CAmountMap TxGetChange(const CWallet& wallet, const CWalletTx& wtx)
{
LOCK(wallet.cs_wallet);
CAmountMap nChange;
for (const CTxOut& txout : tx.vout)
{
nChange += OutputGetChange(wallet, txout);
if (!MoneyRange(nChange))
throw std::runtime_error(std::string(__func__) + ": value out of range");
}
CAmountMap nChange = GetChange(wallet, wtx);
if (!MoneyRange(nChange))
throw std::runtime_error(std::string(__func__) + ": value out of range");
return nChange;
}
@ -203,7 +188,7 @@ CAmountMap CachedTxGetChange(const CWallet& wallet, const CWalletTx& wtx)
{
if (wtx.fChangeCached)
return wtx.nChangeCached;
wtx.nChangeCached = TxGetChange(wallet, *wtx.tx);
wtx.nChangeCached = TxGetChange(wallet, wtx);
wtx.fChangeCached = true;
return wtx.nChangeCached;
}

View file

@ -22,9 +22,8 @@ CAmountMap TxGetCredit(const CWallet& wallet, const CTransaction& tx, const ismi
bool ScriptIsChange(const CWallet& wallet, const CScript& script) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
bool OutputIsChange(const CWallet& wallet, const CTxOut& txout) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
CAmountMap OutputGetChange(const CWallet& wallet, const CTxOut& txout) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
CAmountMap TxGetChange(const CWallet& wallet, const CTransaction& tx);
// ELEMENTS:
CAmountMap TxGetChange(const CWallet& wallet, const CWalletTx& wtx);
CAmountMap GetCredit(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
CAmountMap GetChange(const CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);