@@ -22,7 +22,8 @@ use bitcoin::{secp256k1, Address, Network, Script, ScriptBuf, TxIn, Witness};
22
22
use sync:: Arc ;
23
23
24
24
use self :: checksum:: verify_checksum;
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, miniscript, BareCtx , Error , ForEachKey , MiniscriptKey , Satisfier ,
@@ -476,7 +477,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
476
477
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
477
478
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
478
479
Descriptor :: Sh ( ref sh) => sh. get_satisfaction ( satisfier) ,
479
- Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( satisfier) ,
480
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( & satisfier) ,
480
481
}
481
482
}
482
483
@@ -493,7 +494,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
493
494
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
494
495
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
495
496
Descriptor :: Sh ( ref sh) => sh. get_satisfaction_mall ( satisfier) ,
496
- Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( satisfier) ,
497
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( & satisfier) ,
497
498
}
498
499
}
499
500
@@ -511,6 +512,60 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
511
512
}
512
513
}
513
514
515
+ impl Descriptor < DefiniteDescriptorKey > {
516
+ /// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
517
+ pub fn get_plan < P > ( self , provider : & P ) -> Option < Plan >
518
+ where
519
+ P : AssetProvider < DefiniteDescriptorKey > ,
520
+ {
521
+ let satisfaction = match self {
522
+ Descriptor :: Bare ( ref bare) => bare. get_plan_satisfaction ( provider) ,
523
+ Descriptor :: Pkh ( ref pkh) => pkh. get_plan_satisfaction ( provider) ,
524
+ Descriptor :: Wpkh ( ref wpkh) => wpkh. get_plan_satisfaction ( provider) ,
525
+ Descriptor :: Wsh ( ref wsh) => wsh. get_plan_satisfaction ( provider) ,
526
+ Descriptor :: Sh ( ref sh) => sh. get_plan_satisfaction ( provider) ,
527
+ Descriptor :: Tr ( ref tr) => tr. get_plan_satisfaction ( provider) ,
528
+ } ;
529
+
530
+ if let satisfy:: Witness :: Stack ( stack) = satisfaction. stack {
531
+ Some ( 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
+ None
539
+ }
540
+ }
541
+
542
+ /// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
543
+ pub fn get_plan_mall < P > ( self , provider : & P ) -> Option < Plan >
544
+ where
545
+ P : AssetProvider < DefiniteDescriptorKey > ,
546
+ {
547
+ let satisfaction = match self {
548
+ Descriptor :: Bare ( ref bare) => bare. get_plan_satisfaction_mall ( provider) ,
549
+ Descriptor :: Pkh ( ref pkh) => pkh. get_plan_satisfaction_mall ( provider) ,
550
+ Descriptor :: Wpkh ( ref wpkh) => wpkh. get_plan_satisfaction_mall ( provider) ,
551
+ Descriptor :: Wsh ( ref wsh) => wsh. get_plan_satisfaction_mall ( provider) ,
552
+ Descriptor :: Sh ( ref sh) => sh. get_plan_satisfaction_mall ( provider) ,
553
+ Descriptor :: Tr ( ref tr) => tr. get_plan_satisfaction_mall ( provider) ,
554
+ } ;
555
+
556
+ if let satisfy:: Witness :: Stack ( stack) = satisfaction. stack {
557
+ Some ( Plan {
558
+ descriptor : self ,
559
+ template : stack,
560
+ absolute_timelock : satisfaction. absolute_timelock . map ( Into :: into) ,
561
+ relative_timelock : satisfaction. relative_timelock ,
562
+ } )
563
+ } else {
564
+ None
565
+ }
566
+ }
567
+ }
568
+
514
569
impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
515
570
where
516
571
P : MiniscriptKey ,
0 commit comments