@@ -29,8 +29,7 @@ use std::{
29
29
str:: { self , FromStr } ,
30
30
} ;
31
31
32
- use bitcoin:: secp256k1;
33
- use bitcoin:: { self , Script } ;
32
+ use bitcoin:: { self , secp256k1, Script } ;
34
33
35
34
use self :: checksum:: verify_checksum;
36
35
use expression;
@@ -46,6 +45,7 @@ mod segwitv0;
46
45
mod sh;
47
46
mod sortedmulti;
48
47
mod tr;
48
+
49
49
// Descriptor Exports
50
50
pub use self :: bare:: { Bare , Pkh } ;
51
51
pub use self :: segwitv0:: { Wpkh , Wsh , WshInner } ;
@@ -185,6 +185,8 @@ pub enum Descriptor<Pk: MiniscriptKey> {
185
185
Sh ( Sh < Pk > ) ,
186
186
/// Pay-to-Witness-ScriptHash with Segwitv0 context
187
187
Wsh ( Wsh < Pk > ) ,
188
+ /// Pay-to-Taproot
189
+ Tr ( Tr < Pk > ) ,
188
190
}
189
191
190
192
/// Descriptor Type of the descriptor
@@ -210,6 +212,8 @@ pub enum DescriptorType {
210
212
WshSortedMulti ,
211
213
/// Sh Wsh Sorted Multi
212
214
ShWshSortedMulti ,
215
+ /// Tr Descriptor
216
+ Tr ,
213
217
}
214
218
215
219
impl < Pk : MiniscriptKey > Descriptor < Pk > {
@@ -296,6 +300,12 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
296
300
Ok ( Descriptor :: Wsh ( Wsh :: new_sortedmulti ( k, pks) ?) )
297
301
}
298
302
303
+ /// Create new tr descriptor
304
+ /// Errors when miniscript exceeds resource limits under Segwitv0 context
305
+ pub fn new_tr ( key : Pk , script : Option < tr:: TapTree < Pk > > ) -> Result < Self , Error > {
306
+ Ok ( Descriptor :: Tr ( Tr :: new ( key, script) ?) )
307
+ }
308
+
299
309
/// Get the [DescriptorType] of [Descriptor]
300
310
pub fn desc_type ( & self ) -> DescriptorType {
301
311
match * self {
@@ -315,6 +325,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
315
325
WshInner :: SortedMulti ( ref _smv) => DescriptorType :: WshSortedMulti ,
316
326
WshInner :: Ms ( ref _ms) => DescriptorType :: Wsh ,
317
327
} ,
328
+ Descriptor :: Tr ( ref _tr) => DescriptorType :: Tr ,
318
329
}
319
330
}
320
331
}
@@ -351,6 +362,9 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Descriptor<P> {
351
362
Descriptor :: Wsh ( ref wsh) => {
352
363
Descriptor :: Wsh ( wsh. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
353
364
}
365
+ Descriptor :: Tr ( ref tr) => {
366
+ Descriptor :: Tr ( tr. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
367
+ }
354
368
} ;
355
369
Ok ( desc)
356
370
}
@@ -372,6 +386,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
372
386
Descriptor :: Wpkh ( ref wpkh) => wpkh. sanity_check ( ) ,
373
387
Descriptor :: Wsh ( ref wsh) => wsh. sanity_check ( ) ,
374
388
Descriptor :: Sh ( ref sh) => sh. sanity_check ( ) ,
389
+ Descriptor :: Tr ( ref tr) => tr. sanity_check ( ) ,
375
390
}
376
391
}
377
392
/// Computes the Bitcoin address of the descriptor, if one exists
@@ -385,6 +400,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
385
400
Descriptor :: Wpkh ( ref wpkh) => wpkh. address ( network) ,
386
401
Descriptor :: Wsh ( ref wsh) => wsh. address ( network) ,
387
402
Descriptor :: Sh ( ref sh) => sh. address ( network) ,
403
+ Descriptor :: Tr ( ref tr) => tr. address ( network) ,
388
404
}
389
405
}
390
406
@@ -399,6 +415,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
399
415
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_pubkey ( ) ,
400
416
Descriptor :: Wsh ( ref wsh) => wsh. script_pubkey ( ) ,
401
417
Descriptor :: Sh ( ref sh) => sh. script_pubkey ( ) ,
418
+ Descriptor :: Tr ( ref tr) => tr. script_pubkey ( ) ,
402
419
}
403
420
}
404
421
@@ -420,6 +437,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
420
437
Descriptor :: Wpkh ( ref wpkh) => wpkh. unsigned_script_sig ( ) ,
421
438
Descriptor :: Wsh ( ref wsh) => wsh. unsigned_script_sig ( ) ,
422
439
Descriptor :: Sh ( ref sh) => sh. unsigned_script_sig ( ) ,
440
+ Descriptor :: Tr ( ref tr) => tr. unsigned_script_sig ( ) ,
423
441
}
424
442
}
425
443
@@ -439,6 +457,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
439
457
Descriptor :: Wpkh ( ref wpkh) => wpkh. explicit_script ( ) ,
440
458
Descriptor :: Wsh ( ref wsh) => wsh. explicit_script ( ) ,
441
459
Descriptor :: Sh ( ref sh) => sh. explicit_script ( ) ,
460
+ Descriptor :: Tr ( ref tr) => tr. explicit_script ( ) ,
442
461
}
443
462
}
444
463
@@ -456,6 +475,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
456
475
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
457
476
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
458
477
Descriptor :: Sh ( ref sh) => sh. get_satisfaction ( satisfier) ,
478
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( satisfier) ,
459
479
}
460
480
}
461
481
@@ -473,6 +493,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
473
493
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
474
494
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
475
495
Descriptor :: Sh ( ref sh) => sh. get_satisfaction_mall ( satisfier) ,
496
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( satisfier) ,
476
497
}
477
498
}
478
499
@@ -487,6 +508,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
487
508
Descriptor :: Wpkh ( ref wpkh) => wpkh. max_satisfaction_weight ( ) ,
488
509
Descriptor :: Wsh ( ref wsh) => wsh. max_satisfaction_weight ( ) ,
489
510
Descriptor :: Sh ( ref sh) => sh. max_satisfaction_weight ( ) ,
511
+ Descriptor :: Tr ( ref tr) => tr. max_satisfaction_weight ( ) ,
490
512
}
491
513
}
492
514
@@ -505,6 +527,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
505
527
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_code ( ) ,
506
528
Descriptor :: Wsh ( ref wsh) => wsh. script_code ( ) ,
507
529
Descriptor :: Sh ( ref sh) => sh. script_code ( ) ,
530
+ Descriptor :: Tr ( ref tr) => tr. script_code ( ) ,
508
531
}
509
532
}
510
533
}
@@ -521,6 +544,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
521
544
Descriptor :: Wpkh ( ref wpkh) => wpkh. for_each_key ( pred) ,
522
545
Descriptor :: Wsh ( ref wsh) => wsh. for_each_key ( pred) ,
523
546
Descriptor :: Sh ( ref sh) => sh. for_each_key ( pred) ,
547
+ Descriptor :: Tr ( ref tr) => tr. for_each_key ( pred) ,
524
548
}
525
549
}
526
550
}
@@ -640,6 +664,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
640
664
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{:?}" , wpkh) ,
641
665
Descriptor :: Sh ( ref sub) => write ! ( f, "{:?}" , sub) ,
642
666
Descriptor :: Wsh ( ref sub) => write ! ( f, "{:?}" , sub) ,
667
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{:?}" , tr) ,
643
668
}
644
669
}
645
670
}
@@ -652,6 +677,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Descriptor<Pk> {
652
677
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{}" , wpkh) ,
653
678
Descriptor :: Sh ( ref sub) => write ! ( f, "{}" , sub) ,
654
679
Descriptor :: Wsh ( ref sub) => write ! ( f, "{}" , sub) ,
680
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{}" , tr) ,
655
681
}
656
682
}
657
683
}
0 commit comments