@@ -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 } ;
@@ -186,6 +186,8 @@ pub enum Descriptor<Pk: MiniscriptKey> {
186
186
Sh ( Sh < Pk > ) ,
187
187
/// Pay-to-Witness-ScriptHash with Segwitv0 context
188
188
Wsh ( Wsh < Pk > ) ,
189
+ /// Pay-to-Taproot
190
+ Tr ( Tr < Pk > ) ,
189
191
}
190
192
191
193
/// Descriptor Type of the descriptor
@@ -211,6 +213,8 @@ pub enum DescriptorType {
211
213
WshSortedMulti ,
212
214
/// Sh Wsh Sorted Multi
213
215
ShWshSortedMulti ,
216
+ /// Tr Descriptor
217
+ Tr ,
214
218
}
215
219
216
220
impl < Pk : MiniscriptKey > Descriptor < Pk > {
@@ -297,6 +301,12 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
297
301
Ok ( Descriptor :: Wsh ( Wsh :: new_sortedmulti ( k, pks) ?) )
298
302
}
299
303
304
+ /// Create new tr descriptor
305
+ /// Errors when miniscript exceeds resource limits under Segwitv0 context
306
+ pub fn new_tr ( key : Pk , script : Option < tr:: TapTree < Pk > > ) -> Result < Self , Error > {
307
+ Ok ( Descriptor :: Tr ( Tr :: new ( key, script) ?) )
308
+ }
309
+
300
310
/// Get the [DescriptorType] of [Descriptor]
301
311
pub fn desc_type ( & self ) -> DescriptorType {
302
312
match * self {
@@ -316,6 +326,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
316
326
WshInner :: SortedMulti ( ref _smv) => DescriptorType :: WshSortedMulti ,
317
327
WshInner :: Ms ( ref _ms) => DescriptorType :: Wsh ,
318
328
} ,
329
+ Descriptor :: Tr ( ref _tr) => DescriptorType :: Tr ,
319
330
}
320
331
}
321
332
}
@@ -352,6 +363,9 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Descriptor<P> {
352
363
Descriptor :: Wsh ( ref wsh) => {
353
364
Descriptor :: Wsh ( wsh. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
354
365
}
366
+ Descriptor :: Tr ( ref tr) => {
367
+ Descriptor :: Tr ( tr. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
368
+ }
355
369
} ;
356
370
Ok ( desc)
357
371
}
@@ -373,6 +387,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
373
387
Descriptor :: Wpkh ( ref wpkh) => wpkh. sanity_check ( ) ,
374
388
Descriptor :: Wsh ( ref wsh) => wsh. sanity_check ( ) ,
375
389
Descriptor :: Sh ( ref sh) => sh. sanity_check ( ) ,
390
+ Descriptor :: Tr ( ref tr) => tr. sanity_check ( ) ,
376
391
}
377
392
}
378
393
/// Computes the Bitcoin address of the descriptor, if one exists
@@ -386,6 +401,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
386
401
Descriptor :: Wpkh ( ref wpkh) => wpkh. address ( network) ,
387
402
Descriptor :: Wsh ( ref wsh) => wsh. address ( network) ,
388
403
Descriptor :: Sh ( ref sh) => sh. address ( network) ,
404
+ Descriptor :: Tr ( ref tr) => tr. address ( network) ,
389
405
}
390
406
}
391
407
@@ -400,6 +416,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
400
416
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_pubkey ( ) ,
401
417
Descriptor :: Wsh ( ref wsh) => wsh. script_pubkey ( ) ,
402
418
Descriptor :: Sh ( ref sh) => sh. script_pubkey ( ) ,
419
+ Descriptor :: Tr ( ref tr) => tr. script_pubkey ( ) ,
403
420
}
404
421
}
405
422
@@ -421,6 +438,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
421
438
Descriptor :: Wpkh ( ref wpkh) => wpkh. unsigned_script_sig ( ) ,
422
439
Descriptor :: Wsh ( ref wsh) => wsh. unsigned_script_sig ( ) ,
423
440
Descriptor :: Sh ( ref sh) => sh. unsigned_script_sig ( ) ,
441
+ Descriptor :: Tr ( ref tr) => tr. unsigned_script_sig ( ) ,
424
442
}
425
443
}
426
444
@@ -440,6 +458,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
440
458
Descriptor :: Wpkh ( ref wpkh) => wpkh. explicit_script ( ) ,
441
459
Descriptor :: Wsh ( ref wsh) => wsh. explicit_script ( ) ,
442
460
Descriptor :: Sh ( ref sh) => sh. explicit_script ( ) ,
461
+ Descriptor :: Tr ( ref tr) => tr. explicit_script ( ) ,
443
462
}
444
463
}
445
464
@@ -457,6 +476,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
457
476
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
458
477
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
459
478
Descriptor :: Sh ( ref sh) => sh. get_satisfaction ( satisfier) ,
479
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( satisfier) ,
460
480
}
461
481
}
462
482
@@ -474,6 +494,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
474
494
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction_mall ( satisfier) ,
475
495
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction_mall ( satisfier) ,
476
496
Descriptor :: Sh ( ref sh) => sh. get_satisfaction_mall ( satisfier) ,
497
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction_mall ( satisfier) ,
477
498
}
478
499
}
479
500
@@ -488,6 +509,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
488
509
Descriptor :: Wpkh ( ref wpkh) => wpkh. max_satisfaction_weight ( ) ,
489
510
Descriptor :: Wsh ( ref wsh) => wsh. max_satisfaction_weight ( ) ,
490
511
Descriptor :: Sh ( ref sh) => sh. max_satisfaction_weight ( ) ,
512
+ Descriptor :: Tr ( ref tr) => tr. max_satisfaction_weight ( ) ,
491
513
}
492
514
}
493
515
@@ -506,6 +528,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
506
528
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_code ( ) ,
507
529
Descriptor :: Wsh ( ref wsh) => wsh. script_code ( ) ,
508
530
Descriptor :: Sh ( ref sh) => sh. script_code ( ) ,
531
+ Descriptor :: Tr ( ref tr) => tr. script_code ( ) ,
509
532
}
510
533
}
511
534
}
@@ -522,6 +545,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
522
545
Descriptor :: Wpkh ( ref wpkh) => wpkh. for_each_key ( pred) ,
523
546
Descriptor :: Wsh ( ref wsh) => wsh. for_each_key ( pred) ,
524
547
Descriptor :: Sh ( ref sh) => sh. for_each_key ( pred) ,
548
+ Descriptor :: Tr ( ref tr) => tr. for_each_key ( pred) ,
525
549
}
526
550
}
527
551
}
@@ -641,6 +665,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
641
665
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{:?}" , wpkh) ,
642
666
Descriptor :: Sh ( ref sub) => write ! ( f, "{:?}" , sub) ,
643
667
Descriptor :: Wsh ( ref sub) => write ! ( f, "{:?}" , sub) ,
668
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{:?}" , tr) ,
644
669
}
645
670
}
646
671
}
@@ -653,6 +678,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Descriptor<Pk> {
653
678
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{}" , wpkh) ,
654
679
Descriptor :: Sh ( ref sub) => write ! ( f, "{}" , sub) ,
655
680
Descriptor :: Wsh ( ref sub) => write ! ( f, "{}" , sub) ,
681
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{}" , tr) ,
656
682
}
657
683
}
658
684
}
0 commit comments