@@ -58,7 +58,7 @@ pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
58
58
///Additional information helpful for extra analysis.
59
59
pub ext : types:: extra_props:: ExtData ,
60
60
/// Context PhantomData. Only accessible inside this crate
61
- pub ( crate ) phantom : PhantomData < Ctx > ,
61
+ phantom : PhantomData < Ctx > ,
62
62
}
63
63
64
64
/// `PartialOrd` of `Miniscript` must depend only on node and not the type information.
@@ -117,6 +117,24 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
117
117
phantom : PhantomData ,
118
118
} )
119
119
}
120
+
121
+ /// Create a new `Miniscript` from a `Terminal` node and a `Type` annotation
122
+ /// This does not check the typing rules. The user is responsible for ensuring
123
+ /// that the type provided is correct.
124
+ ///
125
+ /// You should almost always use `Miniscript::from_ast` instead of this function.
126
+ pub fn from_components_unchecked (
127
+ node : Terminal < Pk , Ctx > ,
128
+ ty : types:: Type ,
129
+ ext : types:: extra_props:: ExtData ,
130
+ ) -> Miniscript < Pk , Ctx > {
131
+ Miniscript {
132
+ node,
133
+ ty,
134
+ ext,
135
+ phantom : PhantomData ,
136
+ }
137
+ }
120
138
}
121
139
122
140
impl < Pk : MiniscriptKey , Ctx : ScriptContext > fmt:: Display for Miniscript < Pk , Ctx > {
@@ -318,15 +336,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
318
336
T : Translator < Pk , Q , FuncError > ,
319
337
{
320
338
let inner = self . node . real_translate_pk ( t) ?;
321
- let ms = Miniscript {
322
- //directly copying the type and ext is safe because translating public
323
- //key should not change any properties
324
- ty : self . ty ,
325
- ext : self . ext ,
326
- node : inner,
327
- phantom : PhantomData ,
328
- } ;
329
- Ok ( ms)
339
+ Ok ( Miniscript :: from_ast ( inner) . expect ( "This will be removed in the next commit" ) )
330
340
}
331
341
}
332
342
@@ -435,12 +445,7 @@ impl_from_tree!(
435
445
/// should not be called directly; rather go through the descriptor API.
436
446
fn from_tree( top: & expression:: Tree ) -> Result <Miniscript <Pk , Ctx >, Error > {
437
447
let inner: Terminal <Pk , Ctx > = expression:: FromTree :: from_tree( top) ?;
438
- Ok ( Miniscript {
439
- ty: Type :: type_check( & inner, |_| None ) ?,
440
- ext: ExtData :: type_check( & inner, |_| None ) ?,
441
- node: inner,
442
- phantom: PhantomData ,
443
- } )
448
+ Miniscript :: from_ast( inner)
444
449
}
445
450
) ;
446
451
@@ -659,30 +664,22 @@ mod tests {
659
664
. unwrap ( ) ;
660
665
let hash = hash160:: Hash :: from_inner ( [ 17 ; 20 ] ) ;
661
666
662
- let pkk_ms: Miniscript < String , Segwitv0 > = Miniscript {
663
- node : Terminal :: Check ( Arc :: new ( Miniscript {
664
- node : Terminal :: PkK ( String :: from ( "" ) ) ,
665
- ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
666
- ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
667
- phantom : PhantomData ,
668
- } ) ) ,
669
- ty : Type :: cast_check ( Type :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
670
- ext : ExtData :: cast_check ( ExtData :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
667
+ let pk_node = Terminal :: Check ( Arc :: new ( Miniscript {
668
+ node : Terminal :: PkK ( String :: from ( "" ) ) ,
669
+ ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
670
+ ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
671
671
phantom : PhantomData ,
672
- } ;
672
+ } ) ) ;
673
+ let pkk_ms: Miniscript < String , Segwitv0 > = Miniscript :: from_ast ( pk_node) . unwrap ( ) ;
673
674
dummy_string_rtt ( pkk_ms, "[B/onduesm]c:[K/onduesm]pk_k(\" \" )" , "pk()" ) ;
674
675
675
- let pkh_ms: Miniscript < String , Segwitv0 > = Miniscript {
676
- node : Terminal :: Check ( Arc :: new ( Miniscript {
677
- node : Terminal :: PkH ( String :: from ( "" ) ) ,
678
- ty : Type :: from_pk_h :: < Segwitv0 > ( ) ,
679
- ext : types:: extra_props:: ExtData :: from_pk_h :: < Segwitv0 > ( ) ,
680
- phantom : PhantomData ,
681
- } ) ) ,
682
- ty : Type :: cast_check ( Type :: from_pk_h :: < Segwitv0 > ( ) ) . unwrap ( ) ,
683
- ext : ExtData :: cast_check ( ExtData :: from_pk_h :: < Segwitv0 > ( ) ) . unwrap ( ) ,
676
+ let pkh_node = Terminal :: Check ( Arc :: new ( Miniscript {
677
+ node : Terminal :: PkH ( String :: from ( "" ) ) ,
678
+ ty : Type :: from_pk_h :: < Segwitv0 > ( ) ,
679
+ ext : types:: extra_props:: ExtData :: from_pk_h :: < Segwitv0 > ( ) ,
684
680
phantom : PhantomData ,
685
- } ;
681
+ } ) ) ;
682
+ let pkh_ms: Miniscript < String , Segwitv0 > = Miniscript :: from_ast ( pkh_node) . unwrap ( ) ;
686
683
687
684
let expected_debug = "[B/nduesm]c:[K/nduesm]pk_h(\" \" )" ;
688
685
let expected_display = "pkh()" ;
@@ -697,17 +694,13 @@ mod tests {
697
694
assert_eq ! ( display, expected) ;
698
695
}
699
696
700
- let pkk_ms: Segwitv0Script = Miniscript {
701
- node : Terminal :: Check ( Arc :: new ( Miniscript {
702
- node : Terminal :: PkK ( pk) ,
703
- ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
704
- ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
705
- phantom : PhantomData ,
706
- } ) ) ,
707
- ty : Type :: cast_check ( Type :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
708
- ext : ExtData :: cast_check ( ExtData :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
697
+ let pkk_node = Terminal :: Check ( Arc :: new ( Miniscript {
698
+ node : Terminal :: PkK ( pk) ,
699
+ ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
700
+ ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
709
701
phantom : PhantomData ,
710
- } ;
702
+ } ) ) ;
703
+ let pkk_ms: Segwitv0Script = Miniscript :: from_ast ( pkk_node) . unwrap ( ) ;
711
704
712
705
script_rtt (
713
706
pkk_ms,
0 commit comments