diff options
author | Antoine Poinsot <darosior@protonmail.com> | 2023-02-03 17:44:22 +0100 |
---|---|---|
committer | Antoine Poinsot <darosior@protonmail.com> | 2023-02-03 18:15:42 +0100 |
commit | dfc9acbf0170bde6f2abb879b5584dabd1266531 (patch) | |
tree | b48e36e113db1f3d97ae1746c4bfb51f335e25cc /src | |
parent | aaa55971f6af3f19b22c28103630b856df266ebb (diff) | |
download | bitcoin-dfc9acbf0170bde6f2abb879b5584dabd1266531.tar.xz |
rpc: decode Miniscript descriptor when possible in decodescript
The descriptor inference logic would previously always use a dummy
signing provider and would never analyze the witness script of a P2WSH
scriptPubKey.
Note even a valid Miniscript might not always be decodable from Script
without more contextual information (for instance the key preimage for a
pk_h).
Diffstat (limited to 'src')
-rw-r--r-- | src/core_io.h | 3 | ||||
-rw-r--r-- | src/core_write.cpp | 4 | ||||
-rw-r--r-- | src/rpc/rawtransaction.cpp | 4 |
3 files changed, 7 insertions, 4 deletions
diff --git a/src/core_io.h b/src/core_io.h index 33e1ad82fc..997f3bfd5b 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -15,6 +15,7 @@ class CBlockHeader; class CScript; class CTransaction; struct CMutableTransaction; +class SigningProvider; class uint256; class UniValue; class CTxUndo; @@ -52,7 +53,7 @@ UniValue ValueFromAmount(const CAmount amount); std::string FormatScript(const CScript& script); std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0); std::string SighashToStr(unsigned char sighash_type); -void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false); +void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false, const SigningProvider* provider = nullptr); void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS); #endif // BITCOIN_CORE_IO_H diff --git a/src/core_write.cpp b/src/core_write.cpp index 300bd30e43..b0e3b0b3c4 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -147,13 +147,13 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags) return HexStr(ssTx); } -void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool include_address) +void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool include_address, const SigningProvider* provider) { CTxDestination address; out.pushKV("asm", ScriptToAsmStr(script)); if (include_address) { - out.pushKV("desc", InferDescriptor(script, DUMMY_SIGNING_PROVIDER)->ToString()); + out.pushKV("desc", InferDescriptor(script, provider ? *provider : DUMMY_SIGNING_PROVIDER)->ToString()); } if (include_hex) { out.pushKV("hex", HexStr(script)); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 7704496c10..503099d8a9 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -522,15 +522,17 @@ static RPCHelpMan decodescript() if (can_wrap_P2WSH) { UniValue sr(UniValue::VOBJ); CScript segwitScr; + FillableSigningProvider provider; if (which_type == TxoutType::PUBKEY) { segwitScr = GetScriptForDestination(WitnessV0KeyHash(Hash160(solutions_data[0]))); } else if (which_type == TxoutType::PUBKEYHASH) { segwitScr = GetScriptForDestination(WitnessV0KeyHash(uint160{solutions_data[0]})); } else { // Scripts that are not fit for P2WPKH are encoded as P2WSH. + provider.AddCScript(script); segwitScr = GetScriptForDestination(WitnessV0ScriptHash(script)); } - ScriptToUniv(segwitScr, /*out=*/sr, /*include_hex=*/true, /*include_address=*/true); + ScriptToUniv(segwitScr, /*out=*/sr, /*include_hex=*/true, /*include_address=*/true, /*provider=*/&provider); sr.pushKV("p2sh-segwit", EncodeDestination(ScriptHash(segwitScr))); r.pushKV("segwit", sr); } |