Skip to content

Commit

Permalink
refactor: Call type-solver earlier in decodescript
Browse files Browse the repository at this point in the history
Also, remove std::string type.
  • Loading branch information
MarcoFalke committed Dec 1, 2021
1 parent fab0d99 commit 3333070
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,18 +576,16 @@ static RPCHelpMan decodescript()
}
ScriptPubKeyToUniv(script, r, /* include_hex */ false);

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

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

0 comments on commit 3333070

Please sign in to comment.