@@ -22,7 +22,8 @@ use sync::Arc;
2222
2323use self :: checksum:: verify_checksum;
2424use 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 } ;
2627use crate :: prelude:: * ;
2728use crate :: {
2829 expression, hash256, BareCtx , Error , ForEachKey , MiniscriptKey , Satisfier , ToPublicKey ,
@@ -474,7 +475,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
474475 Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
475476 Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
476477 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) ,
478479 }
479480 }
480481
@@ -491,7 +492,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
491492 Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
492493 Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
493494 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) ,
495496 }
496497 }
497498
@@ -509,6 +510,64 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
509510 }
510511}
511512
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+
512571impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
513572where
514573 P : MiniscriptKey ,
0 commit comments