Merge 8ae2808a43 into merged_master (Bitcoin PR bitcoin/bitcoin#25659)

This commit is contained in:
Byron Hambly 2025-04-03 11:43:10 +02:00
commit 64bdcdbfb5
2 changed files with 23 additions and 46 deletions

View file

@ -480,28 +480,24 @@ CAmountMap GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinCo
return AvailableCoins(wallet, coinControl).GetTotalAmount();
}
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
{
AssertLockHeld(wallet.cs_wallet);
const CTransaction* ptx = &tx;
int n = output;
while (OutputIsChange(wallet, ptx->vout[n]) && ptx->vin.size() > 0) {
const COutPoint& prevout = ptx->vin[0].prevout;
auto it = wallet.mapWallet.find(prevout.hash);
if (it == wallet.mapWallet.end() || it->second.tx->vout.size() <= prevout.n ||
!wallet.IsMine(it->second.tx->vout[prevout.n])) {
break;
}
ptx = it->second.tx.get();
n = prevout.n;
}
return ptx->vout[n];
}
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint)
{
AssertLockHeld(wallet.cs_wallet);
return FindNonChangeParentOutput(wallet, *wallet.GetWalletTx(outpoint.hash)->tx, outpoint.n);
const CWalletTx* wtx{Assert(wallet.GetWalletTx(outpoint.hash))};
const CTransaction* ptx = wtx->tx.get();
int n = outpoint.n;
while (OutputIsChange(wallet, ptx->vout[n]) && ptx->vin.size() > 0) {
const COutPoint& prevout = ptx->vin[0].prevout;
const CWalletTx* it = wallet.GetWalletTx(prevout.hash);
if (!it || it->tx->vout.size() <= prevout.n ||
!wallet.IsMine(it->tx->vout[prevout.n])) {
break;
}
ptx = it->tx.get();
n = prevout.n;
}
return ptx->vout[n];
}
std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
@ -510,7 +506,13 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
std::map<CTxDestination, std::vector<COutput>> result;
for (COutput& coin : AvailableCoinsListUnspent(wallet).All()) {
CCoinControl coin_control;
// Include watch-only for LegacyScriptPubKeyMan wallets without private keys
coin_control.fAllowWatchOnly = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
CoinFilterParams coins_params;
coins_params.only_spendable = false;
coins_params.skip_locked = false;
for (const COutput& coin : AvailableCoins(wallet, &coin_control, /*feerate=*/std::nullopt, coins_params).All()) {
CTxDestination address;
// Retrieve the transaction from the wallet
@ -522,33 +524,9 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
if ((coin.spendable || (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.solvable)) &&
ExtractDestination(FindNonChangeParentOutput(wallet, coin.outpoint).scriptPubKey, address)) {
result[address].emplace_back(std::move(coin));
result[address].emplace_back(coin);
}
}
std::vector<COutPoint> lockedCoins;
wallet.ListLockedCoins(lockedCoins);
// Include watch-only for LegacyScriptPubKeyMan wallets without private keys
const bool include_watch_only = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
const isminetype is_mine_filter = include_watch_only ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
for (const COutPoint& output : lockedCoins) {
auto it = wallet.mapWallet.find(output.hash);
if (it != wallet.mapWallet.end()) {
const auto& wtx = it->second;
int depth = wallet.GetTxDepthInMainChain(wtx);
if (depth >= 0 && output.n < wtx.tx->vout.size() &&
wallet.IsMine(wtx.tx->vout[output.n]) == is_mine_filter
) {
CTxDestination address;
if (ExtractDestination(FindNonChangeParentOutput(wallet, *wtx.tx, output.n).scriptPubKey, address)) {
const auto out = wtx.tx->vout.at(output.n);
result[address].emplace_back(
COutPoint(wtx.GetHash(), output.n), out, depth, CalculateMaximumSignedInputSize(out, &wallet, /*coin_control=*/nullptr), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), CachedTxIsFromMe(wallet, wtx, ISMINE_ALL));
}
}
}
}
return result;
}

View file

@ -104,7 +104,6 @@ CAmountMap GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinCo
/**
* Find non-change parent output.
*/
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
/**