diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-11-14 12:02:40 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-12-01 10:07:51 +0100 |
commit | 33330702081f67cb05fd86e00b252f6355249513 (patch) | |
tree | b6dceed0f3170f605a114029c940da6a2d433ab7 | |
parent | fab0d998f4bf0f3f09afa51845d91408dd484408 (diff) | |
download | bitcoin-33330702081f67cb05fd86e00b252f6355249513.tar.xz |
refactor: Call type-solver earlier in decodescript
Also, remove std::string type.
-rw-r--r-- | src/rpc/rawtransaction.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index d5e6b4f5a5..c15cb3785a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -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)) { |