@@ -22,7 +22,8 @@ use sync::Arc;
22
22
23
23
use self :: checksum:: verify_checksum;
24
24
use crate :: miniscript:: decode:: Terminal ;
25
- use crate :: miniscript:: { Legacy , Miniscript , Segwitv0 } ;
25
+ use crate :: miniscript:: { satisfy, Legacy , Miniscript , Segwitv0 } ;
26
+ use crate :: plan:: { AssetProvider , Plan } ;
26
27
use crate :: prelude:: * ;
27
28
use crate :: {
28
29
expression, hash256, BareCtx , Error , ForEachKey , MiniscriptKey , Satisfier , ToPublicKey ,
@@ -474,7 +475,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
474
475
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
475
476
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
476
477
Descriptor :: Sh ( ref sh) => sh. get_satisfaction ( satisfier) ,
477
- Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( satisfier) ,
478
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( & satisfier) ,
478
479
}
479
480
}
480
481
@@ -491,7 +492,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
491
492
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
492
493
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
493
494
Descriptor :: Sh ( ref sh) => sh. get_satisfaction_mall ( satisfier) ,
494
- Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( satisfier) ,
495
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( & satisfier) ,
495
496
}
496
497
}
497
498
@@ -509,6 +510,64 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
509
510
}
510
511
}
511
512
513
+ impl Descriptor < DefiniteDescriptorKey > {
514
+ /// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
515
+ ///
516
+ /// If the assets aren't sufficient for generating a Plan, the descriptor is returned
517
+ pub fn plan < P > ( self , provider : & P ) -> Result < Plan , Self >
518
+ where
519
+ P : AssetProvider < DefiniteDescriptorKey > ,
520
+ {
521
+ let satisfaction = match self {
522
+ Descriptor :: Bare ( ref bare) => bare. plan_satisfaction ( provider) ,
523
+ Descriptor :: Pkh ( ref pkh) => pkh. plan_satisfaction ( provider) ,
524
+ Descriptor :: Wpkh ( ref wpkh) => wpkh. plan_satisfaction ( provider) ,
525
+ Descriptor :: Wsh ( ref wsh) => wsh. plan_satisfaction ( provider) ,
526
+ Descriptor :: Sh ( ref sh) => sh. plan_satisfaction ( provider) ,
527
+ Descriptor :: Tr ( ref tr) => tr. plan_satisfaction ( provider) ,
528
+ } ;
529
+
530
+ if let satisfy:: Witness :: Stack ( stack) = satisfaction. stack {
531
+ Ok ( Plan {
532
+ descriptor : self ,
533
+ template : stack,
534
+ absolute_timelock : satisfaction. absolute_timelock . map ( Into :: into) ,
535
+ relative_timelock : satisfaction. relative_timelock ,
536
+ } )
537
+ } else {
538
+ Err ( self )
539
+ }
540
+ }
541
+
542
+ /// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
543
+ ///
544
+ /// If the assets aren't sufficient for generating a Plan, the descriptor is returned
545
+ pub fn plan_mall < P > ( self , provider : & P ) -> Result < Plan , Self >
546
+ where
547
+ P : AssetProvider < DefiniteDescriptorKey > ,
548
+ {
549
+ let satisfaction = match self {
550
+ Descriptor :: Bare ( ref bare) => bare. plan_satisfaction_mall ( provider) ,
551
+ Descriptor :: Pkh ( ref pkh) => pkh. plan_satisfaction_mall ( provider) ,
552
+ Descriptor :: Wpkh ( ref wpkh) => wpkh. plan_satisfaction_mall ( provider) ,
553
+ Descriptor :: Wsh ( ref wsh) => wsh. plan_satisfaction_mall ( provider) ,
554
+ Descriptor :: Sh ( ref sh) => sh. plan_satisfaction_mall ( provider) ,
555
+ Descriptor :: Tr ( ref tr) => tr. plan_satisfaction_mall ( provider) ,
556
+ } ;
557
+
558
+ if let satisfy:: Witness :: Stack ( stack) = satisfaction. stack {
559
+ Ok ( Plan {
560
+ descriptor : self ,
561
+ template : stack,
562
+ absolute_timelock : satisfaction. absolute_timelock . map ( Into :: into) ,
563
+ relative_timelock : satisfaction. relative_timelock ,
564
+ } )
565
+ } else {
566
+ Err ( self )
567
+ }
568
+ }
569
+ }
570
+
512
571
impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
513
572
where
514
573
P : MiniscriptKey ,
0 commit comments