mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
Merge bitcoin/bitcoin#27037: rpc: decode Miniscript descriptor when possible in decodescript
6699d850e4
doc: release notes for #27037 (Antoine Poinsot)dfc9acbf01
rpc: decode Miniscript descriptor when possible in decodescript (Antoine Poinsot) Pull request description: The descriptor inference logic would previously always use a dummy signing provider and would never analyze the witness script of a P2WSH scriptPubKey. It's often not possible to infer a Miniscript only from the onchain Script, but it was such a low hanging fruit that it's probably worth having it? Fixes https://github.com/bitcoin/bitcoin/issues/27007. I think it also closes https://github.com/bitcoin/bitcoin/issues/25606. ACKs for top commit: instagibbs: ACK6699d850e4
achow101: ACK6699d850e4
sipa: utACK6699d850e4
Tree-SHA512: e592bf1ad45497e7bd58c26b33cd9d05bb3007f1e987bee773d26013c3824e1b394fe4903809d80997d5ba66616cc79d77850cd7e7f847a0efb2211c59466982
This commit is contained in:
commit
e2ae5c349c
6 changed files with 25 additions and 5 deletions
5
doc/release-notes-27037.md
Normal file
5
doc/release-notes-27037.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
RPC
|
||||||
|
---
|
||||||
|
|
||||||
|
- `decodescript` may now infer a Miniscript descriptor under P2WSH context if it is not lacking
|
||||||
|
information.
|
|
@ -15,6 +15,7 @@ class CBlockHeader;
|
||||||
class CScript;
|
class CScript;
|
||||||
class CTransaction;
|
class CTransaction;
|
||||||
struct CMutableTransaction;
|
struct CMutableTransaction;
|
||||||
|
class SigningProvider;
|
||||||
class uint256;
|
class uint256;
|
||||||
class UniValue;
|
class UniValue;
|
||||||
class CTxUndo;
|
class CTxUndo;
|
||||||
|
@ -52,7 +53,7 @@ UniValue ValueFromAmount(const CAmount amount);
|
||||||
std::string FormatScript(const CScript& script);
|
std::string FormatScript(const CScript& script);
|
||||||
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
|
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
|
||||||
std::string SighashToStr(unsigned char sighash_type);
|
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);
|
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
|
#endif // BITCOIN_CORE_IO_H
|
||||||
|
|
|
@ -147,13 +147,13 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
|
||||||
return HexStr(ssTx);
|
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;
|
CTxDestination address;
|
||||||
|
|
||||||
out.pushKV("asm", ScriptToAsmStr(script));
|
out.pushKV("asm", ScriptToAsmStr(script));
|
||||||
if (include_address) {
|
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) {
|
if (include_hex) {
|
||||||
out.pushKV("hex", HexStr(script));
|
out.pushKV("hex", HexStr(script));
|
||||||
|
|
|
@ -522,15 +522,17 @@ static RPCHelpMan decodescript()
|
||||||
if (can_wrap_P2WSH) {
|
if (can_wrap_P2WSH) {
|
||||||
UniValue sr(UniValue::VOBJ);
|
UniValue sr(UniValue::VOBJ);
|
||||||
CScript segwitScr;
|
CScript segwitScr;
|
||||||
|
FillableSigningProvider provider;
|
||||||
if (which_type == TxoutType::PUBKEY) {
|
if (which_type == TxoutType::PUBKEY) {
|
||||||
segwitScr = GetScriptForDestination(WitnessV0KeyHash(Hash160(solutions_data[0])));
|
segwitScr = GetScriptForDestination(WitnessV0KeyHash(Hash160(solutions_data[0])));
|
||||||
} else if (which_type == TxoutType::PUBKEYHASH) {
|
} else if (which_type == TxoutType::PUBKEYHASH) {
|
||||||
segwitScr = GetScriptForDestination(WitnessV0KeyHash(uint160{solutions_data[0]}));
|
segwitScr = GetScriptForDestination(WitnessV0KeyHash(uint160{solutions_data[0]}));
|
||||||
} else {
|
} else {
|
||||||
// Scripts that are not fit for P2WPKH are encoded as P2WSH.
|
// Scripts that are not fit for P2WPKH are encoded as P2WSH.
|
||||||
|
provider.AddCScript(script);
|
||||||
segwitScr = GetScriptForDestination(WitnessV0ScriptHash(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)));
|
sr.pushKV("p2sh-segwit", EncodeDestination(ScriptHash(segwitScr)));
|
||||||
r.pushKV("segwit", sr);
|
r.pushKV("segwit", sr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
"p2sh": "2N34iiGoUUkVSPiaaTFpJjB1FR9TXQu3PGM",
|
"p2sh": "2N34iiGoUUkVSPiaaTFpJjB1FR9TXQu3PGM",
|
||||||
"segwit": {
|
"segwit": {
|
||||||
"asm": "0 96c2368fc30514a438a8bd909f93c49a1549d77198ccbdb792043b666cb24f42",
|
"asm": "0 96c2368fc30514a438a8bd909f93c49a1549d77198ccbdb792043b666cb24f42",
|
||||||
"desc": "addr(bcrt1qjmprdr7rq522gw9ghkgfly7yng25n4m3nrxtmdujqsakvm9jfapqk795l5)#5akkdska",
|
"desc": "wsh(raw(02eeee))#gtay4y0z",
|
||||||
"hex": "002096c2368fc30514a438a8bd909f93c49a1549d77198ccbdb792043b666cb24f42",
|
"hex": "002096c2368fc30514a438a8bd909f93c49a1549d77198ccbdb792043b666cb24f42",
|
||||||
"address": "bcrt1qjmprdr7rq522gw9ghkgfly7yng25n4m3nrxtmdujqsakvm9jfapqk795l5",
|
"address": "bcrt1qjmprdr7rq522gw9ghkgfly7yng25n4m3nrxtmdujqsakvm9jfapqk795l5",
|
||||||
"type": "witness_v0_scripthash",
|
"type": "witness_v0_scripthash",
|
||||||
|
|
|
@ -263,6 +263,16 @@ class DecodeScriptTest(BitcoinTestFramework):
|
||||||
rpc_result = self.nodes[0].decodescript(script)
|
rpc_result = self.nodes[0].decodescript(script)
|
||||||
assert_equal(result, rpc_result)
|
assert_equal(result, rpc_result)
|
||||||
|
|
||||||
|
def decodescript_miniscript(self):
|
||||||
|
"""Check that a Miniscript is decoded when possible under P2WSH context."""
|
||||||
|
# Sourced from https://github.com/bitcoin/bitcoin/pull/27037#issuecomment-1416151907.
|
||||||
|
# Miniscript-compatible offered HTLC
|
||||||
|
res = self.nodes[0].decodescript("82012088a914ffffffffffffffffffffffffffffffffffffffff88210250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0ad51b2")
|
||||||
|
assert res["segwit"]["desc"] == "wsh(and_v(and_v(v:hash160(ffffffffffffffffffffffffffffffffffffffff),v:pk(0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0)),older(1)))#gm8xz4fl"
|
||||||
|
# Miniscript-incompatible offered HTLC
|
||||||
|
res = self.nodes[0].decodescript("82012088a914ffffffffffffffffffffffffffffffffffffffff882102ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffacb2")
|
||||||
|
assert res["segwit"]["desc"] == "wsh(raw(82012088a914ffffffffffffffffffffffffffffffffffffffff882102ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffacb2))#ra6w2xa7"
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.log.info("Test decoding of standard input scripts [scriptSig]")
|
self.log.info("Test decoding of standard input scripts [scriptSig]")
|
||||||
self.decodescript_script_sig()
|
self.decodescript_script_sig()
|
||||||
|
@ -272,6 +282,8 @@ class DecodeScriptTest(BitcoinTestFramework):
|
||||||
self.decoderawtransaction_asm_sighashtype()
|
self.decoderawtransaction_asm_sighashtype()
|
||||||
self.log.info("Data-driven tests")
|
self.log.info("Data-driven tests")
|
||||||
self.decodescript_datadriven_tests()
|
self.decodescript_datadriven_tests()
|
||||||
|
self.log.info("Miniscript descriptor decoding")
|
||||||
|
self.decodescript_miniscript()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
DecodeScriptTest().main()
|
DecodeScriptTest().main()
|
||||||
|
|
Loading…
Reference in a new issue