@@ -69,7 +69,7 @@ pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
69
69
///Additional information helpful for extra analysis.
70
70
pub ext : types:: extra_props:: ExtData ,
71
71
/// Context PhantomData. Only accessible inside this crate
72
- pub ( crate ) phantom : PhantomData < Ctx > ,
72
+ phantom : PhantomData < Ctx > ,
73
73
}
74
74
75
75
/// `PartialOrd` of `Miniscript` must depend only on node and not the type information.
@@ -128,6 +128,24 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
128
128
phantom : PhantomData ,
129
129
} )
130
130
}
131
+
132
+ /// Create a new `Miniscript` from a `Terminal` node and a `Type` annotation
133
+ /// This does not check the typing rules. The user is responsible for ensuring
134
+ /// that the type provided is correct.
135
+ ///
136
+ /// You should almost always use `Miniscript::from_ast` instead of this function.
137
+ pub fn from_components_unchecked (
138
+ node : Terminal < Pk , Ctx > ,
139
+ ty : types:: Type ,
140
+ ext : types:: extra_props:: ExtData ,
141
+ ) -> Miniscript < Pk , Ctx > {
142
+ Miniscript {
143
+ node,
144
+ ty,
145
+ ext,
146
+ phantom : PhantomData ,
147
+ }
148
+ }
131
149
}
132
150
133
151
impl < Pk : MiniscriptKey , Ctx : ScriptContext > fmt:: Display for Miniscript < Pk , Ctx > {
@@ -329,15 +347,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
329
347
T : Translator < Pk , Q , FuncError > ,
330
348
{
331
349
let inner = self . node . real_translate_pk ( t) ?;
332
- let ms = Miniscript {
333
- //directly copying the type and ext is safe because translating public
334
- //key should not change any properties
335
- ty : self . ty ,
336
- ext : self . ext ,
337
- node : inner,
338
- phantom : PhantomData ,
339
- } ;
340
- Ok ( ms)
350
+ Ok ( Miniscript :: from_ast ( inner) . expect ( "This will be removed in the next commit" ) )
341
351
}
342
352
}
343
353
@@ -446,12 +456,7 @@ impl_from_tree!(
446
456
/// should not be called directly; rather go through the descriptor API.
447
457
fn from_tree( top: & expression:: Tree ) -> Result <Miniscript <Pk , Ctx >, Error > {
448
458
let inner: Terminal <Pk , Ctx > = expression:: FromTree :: from_tree( top) ?;
449
- Ok ( Miniscript {
450
- ty: Type :: type_check( & inner, |_| None ) ?,
451
- ext: ExtData :: type_check( & inner, |_| None ) ?,
452
- node: inner,
453
- phantom: PhantomData ,
454
- } )
459
+ Miniscript :: from_ast( inner)
455
460
}
456
461
) ;
457
462
@@ -670,30 +675,22 @@ mod tests {
670
675
. unwrap ( ) ;
671
676
let hash = hash160:: Hash :: from_inner ( [ 17 ; 20 ] ) ;
672
677
673
- let pkk_ms: Miniscript < DummyKey , Segwitv0 > = Miniscript {
674
- node : Terminal :: Check ( Arc :: new ( Miniscript {
675
- node : Terminal :: PkK ( DummyKey ) ,
676
- ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
677
- ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
678
- phantom : PhantomData ,
679
- } ) ) ,
680
- ty : Type :: cast_check ( Type :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
681
- ext : ExtData :: cast_check ( ExtData :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
678
+ let pk_node = Terminal :: Check ( Arc :: new ( Miniscript {
679
+ node : Terminal :: PkK ( DummyKey ) ,
680
+ ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
681
+ ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
682
682
phantom : PhantomData ,
683
- } ;
683
+ } ) ) ;
684
+ let pkk_ms: Miniscript < DummyKey , Segwitv0 > = Miniscript :: from_ast ( pk_node) . unwrap ( ) ;
684
685
dummy_string_rtt ( pkk_ms, "[B/onduesm]c:[K/onduesm]pk_k(DummyKey)" , "pk()" ) ;
685
686
686
- let pkh_ms: Miniscript < DummyKey , Segwitv0 > = Miniscript {
687
- node : Terminal :: Check ( Arc :: new ( Miniscript {
688
- node : Terminal :: PkH ( DummyKey ) ,
689
- ty : Type :: from_pk_h :: < Segwitv0 > ( ) ,
690
- ext : types:: extra_props:: ExtData :: from_pk_h :: < Segwitv0 > ( ) ,
691
- phantom : PhantomData ,
692
- } ) ) ,
693
- ty : Type :: cast_check ( Type :: from_pk_h :: < Segwitv0 > ( ) ) . unwrap ( ) ,
694
- ext : ExtData :: cast_check ( ExtData :: from_pk_h :: < Segwitv0 > ( ) ) . unwrap ( ) ,
687
+ let pkh_node = Terminal :: Check ( Arc :: new ( Miniscript {
688
+ node : Terminal :: PkH ( DummyKey ) ,
689
+ ty : Type :: from_pk_h :: < Segwitv0 > ( ) ,
690
+ ext : types:: extra_props:: ExtData :: from_pk_h :: < Segwitv0 > ( ) ,
695
691
phantom : PhantomData ,
696
- } ;
692
+ } ) ) ;
693
+ let pkh_ms: Miniscript < DummyKey , Segwitv0 > = Miniscript :: from_ast ( pkh_node) . unwrap ( ) ;
697
694
698
695
let expected_debug = "[B/nduesm]c:[K/nduesm]pk_h(DummyKey)" ;
699
696
let expected_display = "pkh()" ;
@@ -708,17 +705,13 @@ mod tests {
708
705
assert_eq ! ( display, expected) ;
709
706
}
710
707
711
- let pkk_ms: Segwitv0Script = Miniscript {
712
- node : Terminal :: Check ( Arc :: new ( Miniscript {
713
- node : Terminal :: PkK ( pk) ,
714
- ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
715
- ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
716
- phantom : PhantomData ,
717
- } ) ) ,
718
- ty : Type :: cast_check ( Type :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
719
- ext : ExtData :: cast_check ( ExtData :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
708
+ let pkk_node = Terminal :: Check ( Arc :: new ( Miniscript {
709
+ node : Terminal :: PkK ( pk) ,
710
+ ty : Type :: from_pk_k :: < Segwitv0 > ( ) ,
711
+ ext : types:: extra_props:: ExtData :: from_pk_k :: < Segwitv0 > ( ) ,
720
712
phantom : PhantomData ,
721
- } ;
713
+ } ) ) ;
714
+ let pkk_ms: Segwitv0Script = Miniscript :: from_ast ( pkk_node) . unwrap ( ) ;
722
715
723
716
script_rtt (
724
717
pkk_ms,
0 commit comments