@@ -30,8 +30,7 @@ use std::{
3030} ;
3131
3232use bitcoin:: blockdata:: witness:: Witness ;
33- use bitcoin:: secp256k1;
34- use bitcoin:: { self , Script } ;
33+ use bitcoin:: { self , secp256k1, Script } ;
3534
3635use self :: checksum:: verify_checksum;
3736use expression;
@@ -47,6 +46,7 @@ mod segwitv0;
4746mod sh;
4847mod sortedmulti;
4948mod tr;
49+
5050// Descriptor Exports
5151pub use self :: bare:: { Bare , Pkh } ;
5252pub use self :: segwitv0:: { Wpkh , Wsh , WshInner } ;
@@ -184,6 +184,8 @@ pub enum Descriptor<Pk: MiniscriptKey> {
184184 Sh ( Sh < Pk > ) ,
185185 /// Pay-to-Witness-ScriptHash with Segwitv0 context
186186 Wsh ( Wsh < Pk > ) ,
187+ /// Pay-to-Taproot
188+ Tr ( Tr < Pk > ) ,
187189}
188190
189191/// Descriptor Type of the descriptor
@@ -209,6 +211,8 @@ pub enum DescriptorType {
209211 WshSortedMulti ,
210212 /// Sh Wsh Sorted Multi
211213 ShWshSortedMulti ,
214+ /// Tr Descriptor
215+ Tr ,
212216}
213217
214218impl < Pk : MiniscriptKey > Descriptor < Pk > {
@@ -295,6 +299,12 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
295299 Ok ( Descriptor :: Wsh ( Wsh :: new_sortedmulti ( k, pks) ?) )
296300 }
297301
302+ /// Create new tr descriptor
303+ /// Errors when miniscript exceeds resource limits under Tap context
304+ pub fn new_tr ( key : Pk , script : Option < tr:: TapTree < Pk > > ) -> Result < Self , Error > {
305+ Ok ( Descriptor :: Tr ( Tr :: new ( key, script) ?) )
306+ }
307+
298308 /// Get the [DescriptorType] of [Descriptor]
299309 pub fn desc_type ( & self ) -> DescriptorType {
300310 match * self {
@@ -314,6 +324,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
314324 WshInner :: SortedMulti ( ref _smv) => DescriptorType :: WshSortedMulti ,
315325 WshInner :: Ms ( ref _ms) => DescriptorType :: Wsh ,
316326 } ,
327+ Descriptor :: Tr ( ref _tr) => DescriptorType :: Tr ,
317328 }
318329 }
319330}
@@ -350,6 +361,9 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Descriptor<P> {
350361 Descriptor :: Wsh ( ref wsh) => {
351362 Descriptor :: Wsh ( wsh. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
352363 }
364+ Descriptor :: Tr ( ref tr) => {
365+ Descriptor :: Tr ( tr. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
366+ }
353367 } ;
354368 Ok ( desc)
355369 }
@@ -371,6 +385,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
371385 Descriptor :: Wpkh ( ref wpkh) => wpkh. sanity_check ( ) ,
372386 Descriptor :: Wsh ( ref wsh) => wsh. sanity_check ( ) ,
373387 Descriptor :: Sh ( ref sh) => sh. sanity_check ( ) ,
388+ Descriptor :: Tr ( ref tr) => tr. sanity_check ( ) ,
374389 }
375390 }
376391 /// Computes the Bitcoin address of the descriptor, if one exists
@@ -384,6 +399,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
384399 Descriptor :: Wpkh ( ref wpkh) => wpkh. address ( network) ,
385400 Descriptor :: Wsh ( ref wsh) => wsh. address ( network) ,
386401 Descriptor :: Sh ( ref sh) => sh. address ( network) ,
402+ Descriptor :: Tr ( ref tr) => tr. address ( network) ,
387403 }
388404 }
389405
@@ -398,6 +414,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
398414 Descriptor :: Wpkh ( ref wpkh) => wpkh. script_pubkey ( ) ,
399415 Descriptor :: Wsh ( ref wsh) => wsh. script_pubkey ( ) ,
400416 Descriptor :: Sh ( ref sh) => sh. script_pubkey ( ) ,
417+ Descriptor :: Tr ( ref tr) => tr. script_pubkey ( ) ,
401418 }
402419 }
403420
@@ -419,6 +436,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
419436 Descriptor :: Wpkh ( ref wpkh) => wpkh. unsigned_script_sig ( ) ,
420437 Descriptor :: Wsh ( ref wsh) => wsh. unsigned_script_sig ( ) ,
421438 Descriptor :: Sh ( ref sh) => sh. unsigned_script_sig ( ) ,
439+ Descriptor :: Tr ( ref tr) => tr. unsigned_script_sig ( ) ,
422440 }
423441 }
424442
@@ -438,6 +456,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
438456 Descriptor :: Wpkh ( ref wpkh) => wpkh. explicit_script ( ) ,
439457 Descriptor :: Wsh ( ref wsh) => wsh. explicit_script ( ) ,
440458 Descriptor :: Sh ( ref sh) => sh. explicit_script ( ) ,
459+ Descriptor :: Tr ( ref tr) => tr. explicit_script ( ) ,
441460 }
442461 }
443462
@@ -455,6 +474,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
455474 Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
456475 Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
457476 Descriptor :: Sh ( ref sh) => sh. get_satisfaction ( satisfier) ,
477+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( satisfier) ,
458478 }
459479 }
460480
@@ -472,6 +492,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
472492 Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
473493 Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
474494 Descriptor :: Sh ( ref sh) => sh. get_satisfaction_mall ( satisfier) ,
495+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( satisfier) ,
475496 }
476497 }
477498
@@ -486,6 +507,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
486507 Descriptor :: Wpkh ( ref wpkh) => wpkh. max_satisfaction_weight ( ) ,
487508 Descriptor :: Wsh ( ref wsh) => wsh. max_satisfaction_weight ( ) ,
488509 Descriptor :: Sh ( ref sh) => sh. max_satisfaction_weight ( ) ,
510+ Descriptor :: Tr ( ref tr) => tr. max_satisfaction_weight ( ) ,
489511 }
490512 }
491513
@@ -504,6 +526,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
504526 Descriptor :: Wpkh ( ref wpkh) => wpkh. script_code ( ) ,
505527 Descriptor :: Wsh ( ref wsh) => wsh. script_code ( ) ,
506528 Descriptor :: Sh ( ref sh) => sh. script_code ( ) ,
529+ Descriptor :: Tr ( ref tr) => tr. script_code ( ) ,
507530 }
508531 }
509532}
@@ -520,6 +543,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
520543 Descriptor :: Wpkh ( ref wpkh) => wpkh. for_each_key ( pred) ,
521544 Descriptor :: Wsh ( ref wsh) => wsh. for_each_key ( pred) ,
522545 Descriptor :: Sh ( ref sh) => sh. for_each_key ( pred) ,
546+ Descriptor :: Tr ( ref tr) => tr. for_each_key ( pred) ,
523547 }
524548 }
525549}
@@ -610,6 +634,7 @@ where
610634 ( "wpkh" , 1 ) => Descriptor :: Wpkh ( Wpkh :: from_tree ( top) ?) ,
611635 ( "sh" , 1 ) => Descriptor :: Sh ( Sh :: from_tree ( top) ?) ,
612636 ( "wsh" , 1 ) => Descriptor :: Wsh ( Wsh :: from_tree ( top) ?) ,
637+ ( "tr" , _) => Descriptor :: Tr ( Tr :: from_tree ( top) ?) ,
613638 _ => Descriptor :: Bare ( Bare :: from_tree ( top) ?) ,
614639 } )
615640 }
@@ -639,6 +664,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
639664 Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{:?}" , wpkh) ,
640665 Descriptor :: Sh ( ref sub) => write ! ( f, "{:?}" , sub) ,
641666 Descriptor :: Wsh ( ref sub) => write ! ( f, "{:?}" , sub) ,
667+ Descriptor :: Tr ( ref tr) => write ! ( f, "{:?}" , tr) ,
642668 }
643669 }
644670}
@@ -651,6 +677,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Descriptor<Pk> {
651677 Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{}" , wpkh) ,
652678 Descriptor :: Sh ( ref sub) => write ! ( f, "{}" , sub) ,
653679 Descriptor :: Wsh ( ref sub) => write ! ( f, "{}" , sub) ,
680+ Descriptor :: Tr ( ref tr) => write ! ( f, "{}" , tr) ,
654681 }
655682 }
656683}
0 commit comments