@@ -46,6 +46,7 @@ mod segwitv0;
4646mod  sh; 
4747mod  sortedmulti; 
4848mod  tr; 
49+ 
4950// Descriptor Exports 
5051pub  use  self :: bare:: { Bare ,  Pkh } ; 
5152pub  use  self :: segwitv0:: { Wpkh ,  Wsh ,  WshInner } ; 
@@ -168,6 +169,9 @@ pub enum Descriptor<Pk: MiniscriptKey> {
168169Sh ( Sh < Pk > ) , 
169170    /// Pay-to-Witness-ScriptHash with Segwitv0 context 
170171Wsh ( Wsh < Pk > ) , 
172+     // /// Pay-to-Taproot with Segwitv0 context 
173+     // /// TODO: Update context to Segwitv1 
174+     // Tr(Tr<Pk>) 
171175} 
172176
173177/// Descriptor Type of the descriptor 
@@ -193,6 +197,8 @@ pub enum DescriptorType {
193197WshSortedMulti , 
194198    /// Sh Wsh Sorted Multi 
195199ShWshSortedMulti , 
200+     // /// Tr Descriptor 
201+     // Tr 
196202} 
197203
198204impl < Pk :  MiniscriptKey >  Descriptor < Pk >  { 
@@ -279,6 +285,12 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
279285        Ok ( Descriptor :: Wsh ( Wsh :: new_sortedmulti ( k,  pks) ?) ) 
280286    } 
281287
288+     // /// Create new tr descriptor 
289+     // /// Errors when miniscript exceeds resource limits under Segwitv0 context 
290+     // pub fn new_tr(key: Pk, script: Option<tr::TapTree<Pk>>) -> Result<Self, Error> { 
291+     //     Ok(Descriptor::Tr(Tr::new(key, script)?)) 
292+     // } 
293+ 
282294    /// Get the [DescriptorType] of [Descriptor] 
283295pub  fn  desc_type ( & self )  -> DescriptorType  { 
284296        match  * self  { 
@@ -298,6 +310,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
298310                WshInner :: SortedMulti ( ref  _smv)  => DescriptorType :: WshSortedMulti , 
299311                WshInner :: Ms ( ref  _ms)  => DescriptorType :: Wsh , 
300312            } , 
313+             // Descriptor::Tr(_) => DescriptorType::Tr, 
301314        } 
302315    } 
303316} 
@@ -624,6 +637,7 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
624637#[ cfg( test) ]  
625638mod  tests { 
626639    use  super :: checksum:: desc_checksum; 
640+     use  super :: tr:: Tr ; 
627641    use  super :: DescriptorTrait ; 
628642    use  bitcoin:: blockdata:: opcodes:: all:: { OP_CLTV ,  OP_CSV } ; 
629643    use  bitcoin:: blockdata:: script:: Instruction ; 
@@ -1088,6 +1102,35 @@ mod tests {
10881102        assert_eq ! ( check,  & Ok ( Instruction :: Op ( OP_CSV ) ) ) 
10891103    } 
10901104
1105+     #[ test]  
1106+     fn  tr_roundtrip_key ( )  { 
1107+         let  script = Tr :: < DummyKey > :: from_str ( "tr()" ) . unwrap ( ) . to_string ( ) ; 
1108+         assert_eq ! ( script,  format!( "tr()#x4ml3kxd" ) ) 
1109+     } 
1110+ 
1111+     #[ test]  
1112+     fn  tr_roundtrip_script ( )  { 
1113+         let  descriptor = Tr :: < DummyKey > :: from_str ( "tr(,{pk(),pk()})" ) 
1114+             . unwrap ( ) 
1115+             . to_string ( ) ; 
1116+ 
1117+         assert_eq ! ( descriptor,  "tr(,{pk(),pk()})#7dqr6v8r" ) 
1118+     } 
1119+ 
1120+     #[ test]  
1121+     fn  tr_roundtrip_tree ( )  { 
1122+         let  p1 = "020000000000000000000000000000000000000000000000000000000000000001" ; 
1123+         let  p2 = "020000000000000000000000000000000000000000000000000000000000000002" ; 
1124+         let  p3 = "020000000000000000000000000000000000000000000000000000000000000003" ; 
1125+         let  p4 = "020000000000000000000000000000000000000000000000000000000000000004" ; 
1126+         let  p5 = "f54a5851e9372b87810a8e60cdd2e7cfd80b6e31" ; 
1127+         let  descriptor = Tr :: < PublicKey > :: from_str ( & format ! ( "tr({},{{pk({}),{{pk({}),or_d(pk({}),pkh({}))}}}})" ,  p1,  p2,  p3,  p4,  p5) ) 
1128+             . unwrap ( ) 
1129+             . to_string ( ) ; 
1130+ 
1131+         assert_eq ! ( descriptor,  format!( "tr({},{{pk({}),{{pk({}),or_d(pk({}),pkh({}))}}}})#fdhmu4fj" ,  p1,  p2,  p3,  p4,  p5) ) 
1132+     } 
1133+ 
10911134    #[ test]  
10921135    fn  roundtrip_tests ( )  { 
10931136        let  descriptor = Descriptor :: < bitcoin:: PublicKey > :: from_str ( "multi" ) ; 
0 commit comments