From 0c59a96e2ec25b0a8ef8f2221d9ffbeb268bf63e Mon Sep 17 00:00:00 2001 From: Claude Code Date: Tue, 2 Dec 2025 08:08:52 -0600 Subject: [PATCH] Merge bitcoin/bitcoin#25933: wallet: AvailableCoins, simplify output script type acquisition --- src/wallet/spend.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 1de3acd1e16b..dac1c41eeacf 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -215,26 +215,18 @@ CoinsResult AvailableCoins(const CWallet& wallet, // Filter by spendable outputs only if (!spendable && only_spendable) continue; - // When parsing a scriptPubKey, Solver returns the parsed pubkeys or hashes (depending on the script) - // We don't need those here, so we are leaving them in return_values_unused - std::vector> return_values_unused; - TxoutType type; + // Obtain script type + std::vector> script_solutions; + TxoutType type = Solver(output.scriptPubKey, script_solutions); - // If the Output is P2SH and spendable, we want to know if it is + // If the output is P2SH and solvable, we want to know if it is // a P2SH (legacy). We can determine this from the redeemScript. - // If the Output is not spendable, it will be classified as a P2SH (legacy), + // If the output is not solvable, it will be classified as a P2SH (legacy), // since we have no way of knowing otherwise without the redeemScript - if (output.scriptPubKey.IsPayToScriptHash() && solvable) { - CScript redeemScript; - CTxDestination destination; - if (!ExtractDestination(output.scriptPubKey, destination)) - continue; - const CScriptID& hash = CScriptID(std::get(destination)); - if (!provider->GetCScript(hash, redeemScript)) - continue; - type = Solver(redeemScript, return_values_unused); - } else { - type = Solver(output.scriptPubKey, return_values_unused); + if (type == TxoutType::SCRIPTHASH && solvable) { + CScript script; + if (!provider->GetCScript(CScriptID(uint160(script_solutions[0])), script)) continue; + type = Solver(script, script_solutions); } COutput coin(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate);