mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-29 21:42:32 +02:00
Merge bitcoin/bitcoin#25933: wallet: AvailableCoins, simplify output script type acquisition
58b7df3caa
wallet: AvailableCoins, simplify output script type acquisition (furszy) Pull request description: There is an unnecessary `ExtractDestination()` call and subsequent result parse into an `CScriptID`. The `Solver()` call, which we are already doing below anyway, retrieves the script type and, in the P2SH case, the program id. ACKs for top commit: achow101: ACK58b7df3caa
aureleoules: re-ACK58b7df3caa
rajarshimaitra: ACK58b7df3caa
w0xlt: ACK58b7df3caa
Tree-SHA512: 51080766877c34cb2232ee3a1cb6b6a62b829c9297c67b99577742b94854a737a74d248015a4603ca9b6cd0a3c9e1d6d78673ff3cc9fc65dd82deea72dc537fd
This commit is contained in:
commit
25cd47de71
@ -260,32 +260,24 @@ CoinsResult AvailableCoins(const CWallet& wallet,
|
|||||||
// Filter by spendable outputs only
|
// Filter by spendable outputs only
|
||||||
if (!spendable && only_spendable) continue;
|
if (!spendable && only_spendable) continue;
|
||||||
|
|
||||||
// If the Output is P2SH and spendable, we want to know if it is
|
// Obtain script type
|
||||||
|
std::vector<std::vector<uint8_t>> script_solutions;
|
||||||
|
TxoutType type = Solver(output.scriptPubKey, script_solutions);
|
||||||
|
|
||||||
|
// If the output is P2SH and solvable, we want to know if it is
|
||||||
// a P2SH (legacy) or one of P2SH-P2WPKH, P2SH-P2WSH (P2SH-Segwit). We can determine
|
// a P2SH (legacy) or one of P2SH-P2WPKH, P2SH-P2WSH (P2SH-Segwit). We can determine
|
||||||
// this from the redeemScript. If the Output is not spendable, it will be classified
|
// this from the redeemScript. 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
|
// as a P2SH (legacy), since we have no way of knowing otherwise without the redeemScript
|
||||||
CScript script;
|
|
||||||
bool is_from_p2sh{false};
|
bool is_from_p2sh{false};
|
||||||
if (output.scriptPubKey.IsPayToScriptHash() && solvable) {
|
if (type == TxoutType::SCRIPTHASH && solvable) {
|
||||||
CTxDestination destination;
|
CScript script;
|
||||||
if (!ExtractDestination(output.scriptPubKey, destination))
|
if (!provider->GetCScript(CScriptID(uint160(script_solutions[0])), script)) continue;
|
||||||
continue;
|
type = Solver(script, script_solutions);
|
||||||
const CScriptID& hash = CScriptID(std::get<ScriptHash>(destination));
|
|
||||||
if (!provider->GetCScript(hash, script))
|
|
||||||
continue;
|
|
||||||
is_from_p2sh = true;
|
is_from_p2sh = true;
|
||||||
} else {
|
|
||||||
script = output.scriptPubKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COutput coin(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate);
|
result.Add(GetOutputType(type, is_from_p2sh),
|
||||||
|
COutput(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate));
|
||||||
// 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<std::vector<uint8_t>> return_values_unused;
|
|
||||||
TxoutType type;
|
|
||||||
type = Solver(script, return_values_unused);
|
|
||||||
result.Add(GetOutputType(type, is_from_p2sh), coin);
|
|
||||||
|
|
||||||
// Cache total amount as we go
|
// Cache total amount as we go
|
||||||
result.total_amount += output.nValue;
|
result.total_amount += output.nValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user