@@ -260,32 +260,24 @@ CoinsResult AvailableCoins(const CWallet& wallet,
260
260
// Filter by spendable outputs only
261
261
if (!spendable && only_spendable) continue ;
262
262
263
- // If the Output is P2SH and spendable, we want to know if it is
263
+ // Obtain script type
264
+ std::vector<std::vector<uint8_t >> script_solutions;
265
+ TxoutType type = Solver (output.scriptPubKey , script_solutions);
266
+
267
+ // If the output is P2SH and solvable, we want to know if it is
264
268
// a P2SH (legacy) or one of P2SH-P2WPKH, P2SH-P2WSH (P2SH-Segwit). We can determine
265
- // this from the redeemScript. If the Output is not spendable , it will be classified
269
+ // this from the redeemScript. If the output is not solvable , it will be classified
266
270
// as a P2SH (legacy), since we have no way of knowing otherwise without the redeemScript
267
- CScript script;
268
271
bool is_from_p2sh{false };
269
- if (output.scriptPubKey .IsPayToScriptHash () && solvable) {
270
- CTxDestination destination;
271
- if (!ExtractDestination (output.scriptPubKey , destination))
272
- continue ;
273
- const CScriptID& hash = CScriptID (std::get<ScriptHash>(destination));
274
- if (!provider->GetCScript (hash, script))
275
- continue ;
272
+ if (type == TxoutType::SCRIPTHASH && solvable) {
273
+ CScript script;
274
+ if (!provider->GetCScript (CScriptID (uint160 (script_solutions[0 ])), script)) continue ;
275
+ type = Solver (script, script_solutions);
276
276
is_from_p2sh = true ;
277
- } else {
278
- script = output.scriptPubKey ;
279
277
}
280
278
281
- COutput coin (outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime (), tx_from_me, feerate);
282
-
283
- // When parsing a scriptPubKey, Solver returns the parsed pubkeys or hashes (depending on the script)
284
- // We don't need those here, so we are leaving them in return_values_unused
285
- std::vector<std::vector<uint8_t >> return_values_unused;
286
- TxoutType type;
287
- type = Solver (script, return_values_unused);
288
- result.Add (GetOutputType (type, is_from_p2sh), coin);
279
+ result.Add (GetOutputType (type, is_from_p2sh),
280
+ COutput (outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime (), tx_from_me, feerate));
289
281
290
282
// Cache total amount as we go
291
283
result.total_amount += output.nValue ;
0 commit comments