@@ -30,8 +30,7 @@ use std::{
30
30
} ;
31
31
32
32
use bitcoin:: blockdata:: witness:: Witness ;
33
- use bitcoin:: secp256k1;
34
- use bitcoin:: { self , Script } ;
33
+ use bitcoin:: { self , secp256k1, Script } ;
35
34
36
35
use self :: checksum:: verify_checksum;
37
36
use expression;
@@ -47,6 +46,7 @@ mod segwitv0;
47
46
mod sh;
48
47
mod sortedmulti;
49
48
mod tr;
49
+
50
50
// Descriptor Exports
51
51
pub use self :: bare:: { Bare , Pkh } ;
52
52
pub use self :: segwitv0:: { Wpkh , Wsh , WshInner } ;
@@ -184,6 +184,8 @@ pub enum Descriptor<Pk: MiniscriptKey> {
184
184
Sh ( Sh < Pk > ) ,
185
185
/// Pay-to-Witness-ScriptHash with Segwitv0 context
186
186
Wsh ( Wsh < Pk > ) ,
187
+ /// Pay-to-Taproot
188
+ Tr ( Tr < Pk > ) ,
187
189
}
188
190
189
191
/// Descriptor Type of the descriptor
@@ -209,6 +211,8 @@ pub enum DescriptorType {
209
211
WshSortedMulti ,
210
212
/// Sh Wsh Sorted Multi
211
213
ShWshSortedMulti ,
214
+ /// Tr Descriptor
215
+ Tr ,
212
216
}
213
217
214
218
impl < Pk : MiniscriptKey > Descriptor < Pk > {
@@ -295,6 +299,12 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
295
299
Ok ( Descriptor :: Wsh ( Wsh :: new_sortedmulti ( k, pks) ?) )
296
300
}
297
301
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
+
298
308
/// Get the [DescriptorType] of [Descriptor]
299
309
pub fn desc_type ( & self ) -> DescriptorType {
300
310
match * self {
@@ -314,6 +324,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
314
324
WshInner :: SortedMulti ( ref _smv) => DescriptorType :: WshSortedMulti ,
315
325
WshInner :: Ms ( ref _ms) => DescriptorType :: Wsh ,
316
326
} ,
327
+ Descriptor :: Tr ( ref _tr) => DescriptorType :: Tr ,
317
328
}
318
329
}
319
330
}
@@ -350,6 +361,9 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Descriptor<P> {
350
361
Descriptor :: Wsh ( ref wsh) => {
351
362
Descriptor :: Wsh ( wsh. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
352
363
}
364
+ Descriptor :: Tr ( ref tr) => {
365
+ Descriptor :: Tr ( tr. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
366
+ }
353
367
} ;
354
368
Ok ( desc)
355
369
}
@@ -371,6 +385,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
371
385
Descriptor :: Wpkh ( ref wpkh) => wpkh. sanity_check ( ) ,
372
386
Descriptor :: Wsh ( ref wsh) => wsh. sanity_check ( ) ,
373
387
Descriptor :: Sh ( ref sh) => sh. sanity_check ( ) ,
388
+ Descriptor :: Tr ( ref tr) => tr. sanity_check ( ) ,
374
389
}
375
390
}
376
391
/// Computes the Bitcoin address of the descriptor, if one exists
@@ -384,6 +399,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
384
399
Descriptor :: Wpkh ( ref wpkh) => wpkh. address ( network) ,
385
400
Descriptor :: Wsh ( ref wsh) => wsh. address ( network) ,
386
401
Descriptor :: Sh ( ref sh) => sh. address ( network) ,
402
+ Descriptor :: Tr ( ref tr) => tr. address ( network) ,
387
403
}
388
404
}
389
405
@@ -398,6 +414,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
398
414
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_pubkey ( ) ,
399
415
Descriptor :: Wsh ( ref wsh) => wsh. script_pubkey ( ) ,
400
416
Descriptor :: Sh ( ref sh) => sh. script_pubkey ( ) ,
417
+ Descriptor :: Tr ( ref tr) => tr. script_pubkey ( ) ,
401
418
}
402
419
}
403
420
@@ -419,6 +436,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
419
436
Descriptor :: Wpkh ( ref wpkh) => wpkh. unsigned_script_sig ( ) ,
420
437
Descriptor :: Wsh ( ref wsh) => wsh. unsigned_script_sig ( ) ,
421
438
Descriptor :: Sh ( ref sh) => sh. unsigned_script_sig ( ) ,
439
+ Descriptor :: Tr ( ref tr) => tr. unsigned_script_sig ( ) ,
422
440
}
423
441
}
424
442
@@ -438,6 +456,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
438
456
Descriptor :: Wpkh ( ref wpkh) => wpkh. explicit_script ( ) ,
439
457
Descriptor :: Wsh ( ref wsh) => wsh. explicit_script ( ) ,
440
458
Descriptor :: Sh ( ref sh) => sh. explicit_script ( ) ,
459
+ Descriptor :: Tr ( ref tr) => tr. explicit_script ( ) ,
441
460
}
442
461
}
443
462
@@ -455,6 +474,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
455
474
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
456
475
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
457
476
Descriptor :: Sh ( ref sh) => sh. get_satisfaction ( satisfier) ,
477
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( satisfier) ,
458
478
}
459
479
}
460
480
@@ -472,6 +492,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
472
492
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
473
493
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
474
494
Descriptor :: Sh ( ref sh) => sh. get_satisfaction_mall ( satisfier) ,
495
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( satisfier) ,
475
496
}
476
497
}
477
498
@@ -486,6 +507,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
486
507
Descriptor :: Wpkh ( ref wpkh) => wpkh. max_satisfaction_weight ( ) ,
487
508
Descriptor :: Wsh ( ref wsh) => wsh. max_satisfaction_weight ( ) ,
488
509
Descriptor :: Sh ( ref sh) => sh. max_satisfaction_weight ( ) ,
510
+ Descriptor :: Tr ( ref tr) => tr. max_satisfaction_weight ( ) ,
489
511
}
490
512
}
491
513
@@ -504,6 +526,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
504
526
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_code ( ) ,
505
527
Descriptor :: Wsh ( ref wsh) => wsh. script_code ( ) ,
506
528
Descriptor :: Sh ( ref sh) => sh. script_code ( ) ,
529
+ Descriptor :: Tr ( ref tr) => tr. script_code ( ) ,
507
530
}
508
531
}
509
532
}
@@ -520,6 +543,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
520
543
Descriptor :: Wpkh ( ref wpkh) => wpkh. for_each_key ( pred) ,
521
544
Descriptor :: Wsh ( ref wsh) => wsh. for_each_key ( pred) ,
522
545
Descriptor :: Sh ( ref sh) => sh. for_each_key ( pred) ,
546
+ Descriptor :: Tr ( ref tr) => tr. for_each_key ( pred) ,
523
547
}
524
548
}
525
549
}
@@ -610,6 +634,7 @@ where
610
634
( "wpkh" , 1 ) => Descriptor :: Wpkh ( Wpkh :: from_tree ( top) ?) ,
611
635
( "sh" , 1 ) => Descriptor :: Sh ( Sh :: from_tree ( top) ?) ,
612
636
( "wsh" , 1 ) => Descriptor :: Wsh ( Wsh :: from_tree ( top) ?) ,
637
+ ( "tr" , _) => Descriptor :: Tr ( Tr :: from_tree ( top) ?) ,
613
638
_ => Descriptor :: Bare ( Bare :: from_tree ( top) ?) ,
614
639
} )
615
640
}
@@ -639,6 +664,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
639
664
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{:?}" , wpkh) ,
640
665
Descriptor :: Sh ( ref sub) => write ! ( f, "{:?}" , sub) ,
641
666
Descriptor :: Wsh ( ref sub) => write ! ( f, "{:?}" , sub) ,
667
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{:?}" , tr) ,
642
668
}
643
669
}
644
670
}
@@ -651,6 +677,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Descriptor<Pk> {
651
677
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{}" , wpkh) ,
652
678
Descriptor :: Sh ( ref sub) => write ! ( f, "{}" , sub) ,
653
679
Descriptor :: Wsh ( ref sub) => write ! ( f, "{}" , sub) ,
680
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{}" , tr) ,
654
681
}
655
682
}
656
683
}
0 commit comments