@@ -22,7 +22,8 @@ use bitcoin::{secp256k1, Address, Network, Script, ScriptBuf, TxIn, Witness};
2222use sync:: Arc ;
2323
2424use 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 } ;
2627use crate :: prelude:: * ;
2728use crate :: {
2829 expression, hash256, miniscript, BareCtx , Error , ForEachKey , MiniscriptKey , Satisfier ,
@@ -476,7 +477,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
476477 Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
477478 Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
478479 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) ,
480481 }
481482 }
482483
@@ -493,7 +494,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
493494 Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
494495 Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
495496 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) ,
497498 }
498499 }
499500
@@ -511,6 +512,60 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
511512 }
512513}
513514
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+
514569impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
515570where
516571 P : MiniscriptKey ,
0 commit comments