Skip to content

Commit 87b0745

Browse files
committed
Merge #610: Populate the redeemScript for sh(wsh(sortedmulti()))
82de8b5 Populate the redeemScript for `sh(wsh(sortedmulti()))` (Alekos Filini) Pull request description: ### Description Also explicitly match all the individual variants to ensure a similar problem doesn't happen again. Fixes #609 ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### Bugfixes: * [ ] This pull request breaks the existing API * [x] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: notmandatory: ACK 82de8b5 Tree-SHA512: 7cccae44679089b70e8d9df466a165debe17c4cf30ae11cb27357fbda830d3d7ce53161e414b354b1f2be46efe413b8e44132f5e6d625298b740d44112ca286a
2 parents 4c1749a + 82de8b5 commit 87b0745

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/descriptor/mod.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ impl<'s> DescriptorScripts for DerivedDescriptor<'s> {
335335
DescriptorType::Sh => Some(self.explicit_script().unwrap()),
336336
DescriptorType::Bare => Some(self.explicit_script().unwrap()),
337337
DescriptorType::ShSortedMulti => Some(self.explicit_script().unwrap()),
338-
_ => None,
338+
DescriptorType::ShWshSortedMulti => Some(self.explicit_script().unwrap().to_v0_p2wsh()),
339+
DescriptorType::Pkh
340+
| DescriptorType::Wpkh
341+
| DescriptorType::Tr
342+
| DescriptorType::Wsh
343+
| DescriptorType::WshSortedMulti => None,
339344
}
340345
}
341346

@@ -346,7 +351,13 @@ impl<'s> DescriptorScripts for DerivedDescriptor<'s> {
346351
DescriptorType::WshSortedMulti | DescriptorType::ShWshSortedMulti => {
347352
Some(self.explicit_script().unwrap())
348353
}
349-
_ => None,
354+
DescriptorType::Bare
355+
| DescriptorType::Sh
356+
| DescriptorType::Pkh
357+
| DescriptorType::Wpkh
358+
| DescriptorType::ShSortedMulti
359+
| DescriptorType::Tr
360+
| DescriptorType::ShWpkh => None,
350361
}
351362
}
352363
}
@@ -516,6 +527,7 @@ mod test {
516527
use bitcoin::hashes::hex::FromHex;
517528
use bitcoin::secp256k1::Secp256k1;
518529
use bitcoin::util::{bip32, psbt};
530+
use bitcoin::Script;
519531

520532
use super::*;
521533
use crate::psbt::PsbtUtils;
@@ -779,4 +791,22 @@ mod test {
779791
DescriptorError::DuplicatedKeys
780792
));
781793
}
794+
795+
#[test]
796+
fn test_sh_wsh_sortedmulti_redeemscript() {
797+
use super::{AsDerived, DescriptorScripts};
798+
799+
let secp = Secp256k1::new();
800+
801+
let descriptor = "sh(wsh(sortedmulti(3,tpubDEsqS36T4DVsKJd9UH8pAKzrkGBYPLEt9jZMwpKtzh1G6mgYehfHt9WCgk7MJG5QGSFWf176KaBNoXbcuFcuadAFKxDpUdMDKGBha7bY3QM/0/*,tpubDF3cpwfs7fMvXXuoQbohXtLjNM6ehwYT287LWtmLsd4r77YLg6MZg4vTETx5MSJ2zkfigbYWu31VA2Z2Vc1cZugCYXgS7FQu6pE8V6TriEH/0/*,tpubDE1SKfcW76Tb2AASv5bQWMuScYNAdoqLHoexw13sNDXwmUhQDBbCD3QAedKGLhxMrWQdMDKENzYtnXPDRvexQPNuDrLj52wAjHhNEm8sJ4p/0/*,tpubDFLc6oXwJmhm3FGGzXkfJNTh2KitoY3WhmmQvuAjMhD8YbyWn5mAqckbxXfm2etM3p5J6JoTpSrMqRSTfMLtNW46poDaEZJ1kjd3csRSjwH/0/*,tpubDEWD9NBeWP59xXmdqSNt4VYdtTGwbpyP8WS962BuqpQeMZmX9Pur14dhXdZT5a7wR1pK6dPtZ9fP5WR493hPzemnBvkfLLYxnUjAKj1JCQV/0/*,tpubDEHyZkkwd7gZWCTgQuYQ9C4myF2hMEmyHsBCCmLssGqoqUxeT3gzohF5uEVURkf9TtmeepJgkSUmteac38FwZqirjApzNX59XSHLcwaTZCH/0/*,tpubDEqLouCekwnMUWN486kxGzD44qVgeyuqHyxUypNEiQt5RnUZNJe386TKPK99fqRV1vRkZjYAjtXGTECz98MCsdLcnkM67U6KdYRzVubeCgZ/0/*)))";
802+
let (descriptor, _) =
803+
into_wallet_descriptor_checked(descriptor, &secp, Network::Testnet).unwrap();
804+
805+
let descriptor = descriptor.as_derived(0, &secp);
806+
807+
let script = Script::from_str("5321022f533b667e2ea3b36e21961c9fe9dca340fbe0af5210173a83ae0337ab20a57621026bb53a98e810bd0ee61a0ed1164ba6c024786d76554e793e202dc6ce9c78c4ea2102d5b8a7d66a41ffdb6f4c53d61994022e886b4f45001fb158b95c9164d45f8ca3210324b75eead2c1f9c60e8adeb5e7009fec7a29afcdb30d829d82d09562fe8bae8521032d34f8932200833487bd294aa219dcbe000b9f9b3d824799541430009f0fa55121037468f8ea99b6c64788398b5ad25480cad08f4b0d65be54ce3a55fd206b5ae4722103f72d3d96663b0ea99b0aeb0d7f273cab11a8de37885f1dddc8d9112adb87169357ae").unwrap();
808+
809+
assert_eq!(descriptor.psbt_redeem_script(), Some(script.to_v0_p2wsh()));
810+
assert_eq!(descriptor.psbt_witness_script(), Some(script));
811+
}
782812
}

0 commit comments

Comments
 (0)