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