@@ -22,8 +22,11 @@ use bitcoin::{self, Address, Network, Script};
2222
2323use super :: checksum:: { self , verify_checksum} ;
2424use super :: SortedMultiVec ;
25+ use crate :: descriptor:: { DefiniteDescriptorKey , DescriptorType } ;
2526use crate :: expression:: { self , FromTree } ;
2627use crate :: miniscript:: context:: { ScriptContext , ScriptContextError } ;
28+ use crate :: miniscript:: satisfy:: { Placeholder , WitnessTemplate } ;
29+ use crate :: plan:: { AssetProvider , Plan } ;
2730use crate :: policy:: { semantic, Liftable } ;
2831use crate :: prelude:: * ;
2932use crate :: util:: varint_len;
@@ -173,6 +176,32 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
173176 }
174177}
175178
179+ impl Wsh < DefiniteDescriptorKey > {
180+ /// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
181+ pub fn get_plan < P > ( & self , provider : & P ) -> Option < Plan >
182+ where
183+ P : AssetProvider < DefiniteDescriptorKey > ,
184+ {
185+ match & self . inner {
186+ WshInner :: SortedMulti ( sm) => sm. build_template ( provider) . into_plan ( DescriptorType :: Wsh ) ,
187+ WshInner :: Ms ( ms) => ms. build_template ( provider) . into_plan ( DescriptorType :: Wsh ) ,
188+ }
189+ }
190+
191+ /// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
192+ pub fn get_plan_mall < P > ( & self , provider : & P ) -> Option < Plan >
193+ where
194+ P : AssetProvider < DefiniteDescriptorKey > ,
195+ {
196+ match & self . inner {
197+ WshInner :: SortedMulti ( sm) => sm. build_template ( provider) . into_plan ( DescriptorType :: Wsh ) ,
198+ WshInner :: Ms ( ms) => ms
199+ . build_template_mall ( provider)
200+ . into_plan ( DescriptorType :: Wsh ) ,
201+ }
202+ }
203+ }
204+
176205/// Wsh Inner
177206#[ derive( Clone , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
178207pub enum WshInner < Pk : MiniscriptKey > {
@@ -393,6 +422,37 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
393422 }
394423}
395424
425+ impl Wpkh < DefiniteDescriptorKey > {
426+ /// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
427+ pub fn get_plan < P > ( & self , provider : & P ) -> Option < Plan >
428+ where
429+ P : AssetProvider < DefiniteDescriptorKey > ,
430+ {
431+ if provider. lookup_ecdsa_sig ( & self . pk ) {
432+ let stack = vec ! [
433+ Placeholder :: EcdsaSigPk ( self . pk. clone( ) ) ,
434+ Placeholder :: Pubkey ( self . pk. clone( ) , Segwitv0 :: pk_len( & self . pk) ) ,
435+ ] ;
436+ Some ( Plan {
437+ relative_timelock : None ,
438+ absolute_timelock : None ,
439+ desc_type : DescriptorType :: Wpkh ,
440+ template : WitnessTemplate :: from_placeholder_stack ( stack) ,
441+ } )
442+ } else {
443+ None
444+ }
445+ }
446+
447+ /// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
448+ pub fn get_plan_mall < P > ( & self , provider : & P ) -> Option < Plan >
449+ where
450+ P : AssetProvider < DefiniteDescriptorKey > ,
451+ {
452+ self . get_plan ( provider)
453+ }
454+ }
455+
396456impl < Pk : MiniscriptKey > fmt:: Debug for Wpkh < Pk > {
397457 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
398458 write ! ( f, "wpkh({:?})" , self . pk)
0 commit comments