aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2022-08-25 17:23:02 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2022-09-17 10:29:30 -0300
commit58b7df3caa21519de61e10f6ee42f0be9ac3cc30 (patch)
treebfc3f3b118d65be83f0ea16672c6249785c480b2 /src/wallet
parentba2edcae7321d6f8dc4aad4acbbd2d3b5e846f5f (diff)
wallet: AvailableCoins, simplify output script type acquisition
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/spend.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 92cf771358..0e87d5e51a 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -260,32 +260,24 @@ CoinsResult AvailableCoins(const CWallet& wallet,
// Filter by spendable outputs only
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
- // 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
- CScript script;
bool is_from_p2sh{false};
- if (output.scriptPubKey.IsPayToScriptHash() && solvable) {
- CTxDestination destination;
- if (!ExtractDestination(output.scriptPubKey, destination))
- continue;
- const CScriptID& hash = CScriptID(std::get<ScriptHash>(destination));
- if (!provider->GetCScript(hash, script))
- continue;
+ if (type == TxoutType::SCRIPTHASH && solvable) {
+ CScript script;
+ if (!provider->GetCScript(CScriptID(uint160(script_solutions[0])), script)) continue;
+ type = Solver(script, script_solutions);
is_from_p2sh = true;
- } else {
- script = output.scriptPubKey;
}
- COutput coin(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);
+ result.Add(GetOutputType(type, is_from_p2sh),
+ COutput(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate));
// Cache total amount as we go
result.total_amount += output.nValue;