@@ -63,6 +63,40 @@ pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
63
63
phantom : PhantomData < Ctx > ,
64
64
}
65
65
66
+ impl < Pk : MiniscriptKey , Ctx : ScriptContext > Miniscript < Pk , Ctx > {
67
+ /// Add type information(Type and Extdata) to Miniscript based on
68
+ /// `AstElem` fragment. Dependent on display and clone because of Error
69
+ /// Display code of type_check.
70
+ pub fn from_ast ( t : Terminal < Pk , Ctx > ) -> Result < Miniscript < Pk , Ctx > , Error > {
71
+ let res = Miniscript {
72
+ ty : Type :: type_check ( & t, |_| None ) ?,
73
+ ext : ExtData :: type_check ( & t, |_| None ) ?,
74
+ node : t,
75
+ phantom : PhantomData ,
76
+ } ;
77
+ Ctx :: check_global_consensus_validity ( & res) ?;
78
+ Ok ( res)
79
+ }
80
+
81
+ /// Create a new `Miniscript` from a `Terminal` node and a `Type` annotation
82
+ /// This does not check the typing rules. The user is responsible for ensuring
83
+ /// that the type provided is correct.
84
+ ///
85
+ /// You should almost always use `Miniscript::from_ast` instead of this function.
86
+ pub fn from_components_unchecked (
87
+ node : Terminal < Pk , Ctx > ,
88
+ ty : types:: Type ,
89
+ ext : types:: extra_props:: ExtData ,
90
+ ) -> Miniscript < Pk , Ctx > {
91
+ Miniscript {
92
+ node,
93
+ ty,
94
+ ext,
95
+ phantom : PhantomData ,
96
+ }
97
+ }
98
+ }
99
+
66
100
/// `PartialOrd` of `Miniscript` must depend only on node and not the type information.
67
101
///
68
102
/// The type information and extra properties are implied by the AST.
@@ -110,40 +144,6 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Debug for Miniscript<Pk, Ctx> {
110
144
}
111
145
}
112
146
113
- impl < Pk : MiniscriptKey , Ctx : ScriptContext > Miniscript < Pk , Ctx > {
114
- /// Add type information(Type and Extdata) to Miniscript based on
115
- /// `AstElem` fragment. Dependent on display and clone because of Error
116
- /// Display code of type_check.
117
- pub fn from_ast ( t : Terminal < Pk , Ctx > ) -> Result < Miniscript < Pk , Ctx > , Error > {
118
- let res = Miniscript {
119
- ty : Type :: type_check ( & t, |_| None ) ?,
120
- ext : ExtData :: type_check ( & t, |_| None ) ?,
121
- node : t,
122
- phantom : PhantomData ,
123
- } ;
124
- Ctx :: check_global_consensus_validity ( & res) ?;
125
- Ok ( res)
126
- }
127
-
128
- /// Create a new `Miniscript` from a `Terminal` node and a `Type` annotation
129
- /// This does not check the typing rules. The user is responsible for ensuring
130
- /// that the type provided is correct.
131
- ///
132
- /// You should almost always use `Miniscript::from_ast` instead of this function.
133
- pub fn from_components_unchecked (
134
- node : Terminal < Pk , Ctx > ,
135
- ty : types:: Type ,
136
- ext : types:: extra_props:: ExtData ,
137
- ) -> Miniscript < Pk , Ctx > {
138
- Miniscript {
139
- node,
140
- ty,
141
- ext,
142
- phantom : PhantomData ,
143
- }
144
- }
145
- }
146
-
147
147
impl < Pk : MiniscriptKey , Ctx : ScriptContext > fmt:: Display for Miniscript < Pk , Ctx > {
148
148
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
149
149
write ! ( f, "{}" , self . node)
0 commit comments