@@ -22,8 +22,11 @@ use bitcoin::{self, Address, Network, Script};
22
22
23
23
use super :: checksum:: { self , verify_checksum} ;
24
24
use super :: SortedMultiVec ;
25
+ use crate :: descriptor:: { DefiniteDescriptorKey , DescriptorType } ;
25
26
use crate :: expression:: { self , FromTree } ;
26
27
use crate :: miniscript:: context:: { ScriptContext , ScriptContextError } ;
28
+ use crate :: miniscript:: satisfy:: { Placeholder , WitnessTemplate } ;
29
+ use crate :: plan:: { AssetProvider , Plan } ;
27
30
use crate :: policy:: { semantic, Liftable } ;
28
31
use crate :: prelude:: * ;
29
32
use crate :: util:: varint_len;
@@ -173,6 +176,32 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
173
176
}
174
177
}
175
178
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
+
176
205
/// Wsh Inner
177
206
#[ derive( Clone , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
178
207
pub enum WshInner < Pk : MiniscriptKey > {
@@ -393,6 +422,37 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
393
422
}
394
423
}
395
424
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
+
396
456
impl < Pk : MiniscriptKey > fmt:: Debug for Wpkh < Pk > {
397
457
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
398
458
write ! ( f, "wpkh({:?})" , self . pk)
0 commit comments