Skip to content

Commit 3333070

Browse files
author
MarcoFalke
committed
refactor: Call type-solver earlier in decodescript
Also, remove std::string type.
1 parent fab0d99 commit 3333070

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,18 +576,16 @@ static RPCHelpMan decodescript()
576576
}
577577
ScriptPubKeyToUniv(script, r, /* include_hex */ false);
578578

579-
UniValue type;
580-
type = find_value(r, "type");
579+
std::vector<std::vector<unsigned char>> solutions_data;
580+
const TxoutType which_type{Solver(script, solutions_data)};
581581

582-
if (type.isStr() && type.get_str() != "scripthash") {
582+
if (which_type != TxoutType::SCRIPTHASH) {
583583
// P2SH cannot be wrapped in a P2SH. If this script is already a P2SH,
584584
// don't return the address for a P2SH of the P2SH.
585585
r.pushKV("p2sh", EncodeDestination(ScriptHash(script)));
586586
// P2SH and witness programs cannot be wrapped in P2WSH, if this script
587587
// is a witness program, don't return addresses for a segwit programs.
588-
if (type.get_str() == "pubkey" || type.get_str() == "pubkeyhash" || type.get_str() == "multisig" || type.get_str() == "nonstandard") {
589-
std::vector<std::vector<unsigned char>> solutions_data;
590-
TxoutType which_type = Solver(script, solutions_data);
588+
if (which_type == TxoutType::PUBKEY || which_type == TxoutType::PUBKEYHASH || which_type == TxoutType::MULTISIG || which_type == TxoutType::NONSTANDARD) {
591589
// Uncompressed pubkeys cannot be used with segwit checksigs.
592590
// If the script contains an uncompressed pubkey, skip encoding of a segwit program.
593591
if ((which_type == TxoutType::PUBKEY) || (which_type == TxoutType::MULTISIG)) {

0 commit comments

Comments
 (0)