@@ -46,6 +46,7 @@ mod segwitv0;
46
46
mod sh;
47
47
mod sortedmulti;
48
48
mod tr;
49
+
49
50
// Descriptor Exports
50
51
pub use self :: bare:: { Bare , Pkh } ;
51
52
pub use self :: segwitv0:: { Wpkh , Wsh , WshInner } ;
@@ -177,6 +178,8 @@ pub enum Descriptor<Pk: MiniscriptKey> {
177
178
Sh ( Sh < Pk > ) ,
178
179
/// Pay-to-Witness-ScriptHash with Segwitv0 context
179
180
Wsh ( Wsh < Pk > ) ,
181
+ /// Pay-to-Taproot
182
+ Tr ( Tr < Pk > ) ,
180
183
}
181
184
182
185
/// Descriptor Type of the descriptor
@@ -202,6 +205,8 @@ pub enum DescriptorType {
202
205
WshSortedMulti ,
203
206
/// Sh Wsh Sorted Multi
204
207
ShWshSortedMulti ,
208
+ /// Tr Descriptor
209
+ Tr ,
205
210
}
206
211
207
212
impl < Pk : MiniscriptKey > Descriptor < Pk > {
@@ -288,6 +293,12 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
288
293
Ok ( Descriptor :: Wsh ( Wsh :: new_sortedmulti ( k, pks) ?) )
289
294
}
290
295
296
+ /// Create new tr descriptor
297
+ /// Errors when miniscript exceeds resource limits under Segwitv0 context
298
+ pub fn new_tr ( key : Pk , script : Option < tr:: TapTree < Pk > > ) -> Result < Self , Error > {
299
+ Ok ( Descriptor :: Tr ( Tr :: new ( key, script) ?) )
300
+ }
301
+
291
302
/// Get the [DescriptorType] of [Descriptor]
292
303
pub fn desc_type ( & self ) -> DescriptorType {
293
304
match * self {
@@ -307,6 +318,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
307
318
WshInner :: SortedMulti ( ref _smv) => DescriptorType :: WshSortedMulti ,
308
319
WshInner :: Ms ( ref _ms) => DescriptorType :: Wsh ,
309
320
} ,
321
+ Descriptor :: Tr ( ref _tr) => DescriptorType :: Tr ,
310
322
}
311
323
}
312
324
}
@@ -343,6 +355,9 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Descriptor<P> {
343
355
Descriptor :: Wsh ( ref wsh) => {
344
356
Descriptor :: Wsh ( wsh. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
345
357
}
358
+ Descriptor :: Tr ( ref tr) => {
359
+ Descriptor :: Tr ( tr. translate_pk ( & mut translatefpk, & mut translatefpkh) ?)
360
+ }
346
361
} ;
347
362
Ok ( desc)
348
363
}
@@ -364,6 +379,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
364
379
Descriptor :: Wpkh ( ref wpkh) => wpkh. sanity_check ( ) ,
365
380
Descriptor :: Wsh ( ref wsh) => wsh. sanity_check ( ) ,
366
381
Descriptor :: Sh ( ref sh) => sh. sanity_check ( ) ,
382
+ Descriptor :: Tr ( ref tr) => tr. sanity_check ( ) ,
367
383
}
368
384
}
369
385
/// Computes the Bitcoin address of the descriptor, if one exists
@@ -377,6 +393,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
377
393
Descriptor :: Wpkh ( ref wpkh) => wpkh. address ( network) ,
378
394
Descriptor :: Wsh ( ref wsh) => wsh. address ( network) ,
379
395
Descriptor :: Sh ( ref sh) => sh. address ( network) ,
396
+ Descriptor :: Tr ( ref tr) => tr. address ( network) ,
380
397
}
381
398
}
382
399
@@ -391,6 +408,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
391
408
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_pubkey ( ) ,
392
409
Descriptor :: Wsh ( ref wsh) => wsh. script_pubkey ( ) ,
393
410
Descriptor :: Sh ( ref sh) => sh. script_pubkey ( ) ,
411
+ Descriptor :: Tr ( ref tr) => tr. script_pubkey ( ) ,
394
412
}
395
413
}
396
414
@@ -412,6 +430,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
412
430
Descriptor :: Wpkh ( ref wpkh) => wpkh. unsigned_script_sig ( ) ,
413
431
Descriptor :: Wsh ( ref wsh) => wsh. unsigned_script_sig ( ) ,
414
432
Descriptor :: Sh ( ref sh) => sh. unsigned_script_sig ( ) ,
433
+ Descriptor :: Tr ( ref tr) => tr. unsigned_script_sig ( ) ,
415
434
}
416
435
}
417
436
@@ -431,6 +450,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
431
450
Descriptor :: Wpkh ( ref wpkh) => wpkh. explicit_script ( ) ,
432
451
Descriptor :: Wsh ( ref wsh) => wsh. explicit_script ( ) ,
433
452
Descriptor :: Sh ( ref sh) => sh. explicit_script ( ) ,
453
+ Descriptor :: Tr ( ref tr) => tr. explicit_script ( ) ,
434
454
}
435
455
}
436
456
@@ -448,6 +468,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
448
468
Descriptor :: Wpkh ( ref wpkh) => wpkh. get_satisfaction ( satisfier) ,
449
469
Descriptor :: Wsh ( ref wsh) => wsh. get_satisfaction ( satisfier) ,
450
470
Descriptor :: Sh ( ref sh) => sh. get_satisfaction ( satisfier) ,
471
+ Descriptor :: Tr ( ref tr) => tr. get_satisfaction ( satisfier) ,
451
472
}
452
473
}
453
474
@@ -462,6 +483,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
462
483
Descriptor :: Wpkh ( ref wpkh) => wpkh. max_satisfaction_weight ( ) ,
463
484
Descriptor :: Wsh ( ref wsh) => wsh. max_satisfaction_weight ( ) ,
464
485
Descriptor :: Sh ( ref sh) => sh. max_satisfaction_weight ( ) ,
486
+ Descriptor :: Tr ( ref tr) => tr. max_satisfaction_weight ( ) ,
465
487
}
466
488
}
467
489
@@ -480,6 +502,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
480
502
Descriptor :: Wpkh ( ref wpkh) => wpkh. script_code ( ) ,
481
503
Descriptor :: Wsh ( ref wsh) => wsh. script_code ( ) ,
482
504
Descriptor :: Sh ( ref sh) => sh. script_code ( ) ,
505
+ Descriptor :: Tr ( ref tr) => tr. script_code ( ) ,
483
506
}
484
507
}
485
508
}
@@ -496,6 +519,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
496
519
Descriptor :: Wpkh ( ref wpkh) => wpkh. for_each_key ( pred) ,
497
520
Descriptor :: Wsh ( ref wsh) => wsh. for_each_key ( pred) ,
498
521
Descriptor :: Sh ( ref sh) => sh. for_each_key ( pred) ,
522
+ Descriptor :: Tr ( ref tr) => tr. for_each_key ( pred) ,
499
523
}
500
524
}
501
525
}
@@ -615,6 +639,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
615
639
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{:?}" , wpkh) ,
616
640
Descriptor :: Sh ( ref sub) => write ! ( f, "{:?}" , sub) ,
617
641
Descriptor :: Wsh ( ref sub) => write ! ( f, "{:?}" , sub) ,
642
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{:?}" , tr) ,
618
643
}
619
644
}
620
645
}
@@ -627,6 +652,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Descriptor<Pk> {
627
652
Descriptor :: Wpkh ( ref wpkh) => write ! ( f, "{}" , wpkh) ,
628
653
Descriptor :: Sh ( ref sub) => write ! ( f, "{}" , sub) ,
629
654
Descriptor :: Wsh ( ref sub) => write ! ( f, "{}" , sub) ,
655
+ Descriptor :: Tr ( ref tr) => write ! ( f, "{}" , tr) ,
630
656
}
631
657
}
632
658
}
0 commit comments