@@ -23,7 +23,7 @@ pub use self::semantic::Policy as Semantic;
2323use crate :: descriptor:: Descriptor ;
2424use crate :: miniscript:: { Miniscript , ScriptContext } ;
2525use crate :: sync:: Arc ;
26- use crate :: { Error , MiniscriptKey , Terminal } ;
26+ use crate :: { Error , MiniscriptKey , Terminal , Vec } ;
2727
2828/// Policy entailment algorithm maximum number of terminals allowed.
2929const ENTAILMENT_MAX_TERMINALS : usize = 20 ;
@@ -136,28 +136,40 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
136136 | Terminal :: NonZero ( ref sub)
137137 | Terminal :: ZeroNotEqual ( ref sub) => sub. node . lift ( ) ?,
138138 Terminal :: AndV ( ref left, ref right) | Terminal :: AndB ( ref left, ref right) => {
139- Semantic :: Threshold ( 2 , vec ! [ left. node. lift( ) ?, right. node. lift( ) ?] )
139+ Semantic :: Threshold (
140+ 2 ,
141+ vec ! [ Arc :: new( left. node. lift( ) ?) , Arc :: new( right. node. lift( ) ?) ] ,
142+ )
140143 }
141144 Terminal :: AndOr ( ref a, ref b, ref c) => Semantic :: Threshold (
142145 1 ,
143146 vec ! [
144- Semantic :: Threshold ( 2 , vec![ a. node. lift( ) ?, b. node. lift( ) ?] ) ,
145- c. node. lift( ) ?,
147+ Arc :: new( Semantic :: Threshold (
148+ 2 ,
149+ vec![ Arc :: new( a. node. lift( ) ?) , Arc :: new( b. node. lift( ) ?) ] ,
150+ ) ) ,
151+ Arc :: new( c. node. lift( ) ?) ,
146152 ] ,
147153 ) ,
148154 Terminal :: OrB ( ref left, ref right)
149155 | Terminal :: OrD ( ref left, ref right)
150156 | Terminal :: OrC ( ref left, ref right)
151- | Terminal :: OrI ( ref left, ref right) => {
152- Semantic :: Threshold ( 1 , vec ! [ left. node. lift( ) ?, right. node. lift( ) ?] )
153- }
157+ | Terminal :: OrI ( ref left, ref right) => Semantic :: Threshold (
158+ 1 ,
159+ vec ! [ Arc :: new( left. node. lift( ) ?) , Arc :: new( right. node. lift( ) ?) ] ,
160+ ) ,
154161 Terminal :: Thresh ( k, ref subs) => {
155- let semantic_subs: Result < _ , Error > = subs. iter ( ) . map ( |s| s. node . lift ( ) ) . collect ( ) ;
156- Semantic :: Threshold ( k, semantic_subs?)
157- }
158- Terminal :: Multi ( k, ref keys) | Terminal :: MultiA ( k, ref keys) => {
159- Semantic :: Threshold ( k, keys. iter ( ) . map ( |k| Semantic :: Key ( k. clone ( ) ) ) . collect ( ) )
162+ let semantic_subs: Result < Vec < Semantic < Pk > > , Error > =
163+ subs. iter ( ) . map ( |s| s. node . lift ( ) ) . collect ( ) ;
164+ let semantic_subs = semantic_subs?. into_iter ( ) . map ( Arc :: new) . collect ( ) ;
165+ Semantic :: Threshold ( k, semantic_subs)
160166 }
167+ Terminal :: Multi ( k, ref keys) | Terminal :: MultiA ( k, ref keys) => Semantic :: Threshold (
168+ k,
169+ keys. iter ( )
170+ . map ( |k| Arc :: new ( Semantic :: Key ( k. clone ( ) ) ) )
171+ . collect ( ) ,
172+ ) ,
161173 }
162174 . normalized ( ) ;
163175 Ok ( ret)
@@ -197,17 +209,22 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk> {
197209 Concrete :: Ripemd160 ( ref h) => Semantic :: Ripemd160 ( h. clone ( ) ) ,
198210 Concrete :: Hash160 ( ref h) => Semantic :: Hash160 ( h. clone ( ) ) ,
199211 Concrete :: And ( ref subs) => {
200- let semantic_subs: Result < _ , Error > = subs. iter ( ) . map ( Liftable :: lift) . collect ( ) ;
201- Semantic :: Threshold ( 2 , semantic_subs?)
212+ let semantic_subs: Result < Vec < Semantic < Pk > > , Error > =
213+ subs. iter ( ) . map ( Liftable :: lift) . collect ( ) ;
214+ let semantic_subs = semantic_subs?. into_iter ( ) . map ( Arc :: new) . collect ( ) ;
215+ Semantic :: Threshold ( 2 , semantic_subs)
202216 }
203217 Concrete :: Or ( ref subs) => {
204- let semantic_subs: Result < _ , Error > =
218+ let semantic_subs: Result < Vec < Semantic < Pk > > , Error > =
205219 subs. iter ( ) . map ( |( _p, sub) | sub. lift ( ) ) . collect ( ) ;
206- Semantic :: Threshold ( 1 , semantic_subs?)
220+ let semantic_subs = semantic_subs?. into_iter ( ) . map ( Arc :: new) . collect ( ) ;
221+ Semantic :: Threshold ( 1 , semantic_subs)
207222 }
208223 Concrete :: Threshold ( k, ref subs) => {
209- let semantic_subs: Result < _ , Error > = subs. iter ( ) . map ( Liftable :: lift) . collect ( ) ;
210- Semantic :: Threshold ( k, semantic_subs?)
224+ let semantic_subs: Result < Vec < Semantic < Pk > > , Error > =
225+ subs. iter ( ) . map ( Liftable :: lift) . collect ( ) ;
226+ let semantic_subs = semantic_subs?. into_iter ( ) . map ( Arc :: new) . collect ( ) ;
227+ Semantic :: Threshold ( k, semantic_subs)
211228 }
212229 }
213230 . normalized ( ) ;
@@ -346,14 +363,14 @@ mod tests {
346363 Semantic :: Threshold (
347364 1 ,
348365 vec![
349- Semantic :: Threshold (
366+ Arc :: new ( Semantic :: Threshold (
350367 2 ,
351368 vec![
352- Semantic :: Key ( key_a) ,
353- Semantic :: Older ( Sequence :: from_height( 42 ) )
369+ Arc :: new ( Semantic :: Key ( key_a) ) ,
370+ Arc :: new ( Semantic :: Older ( Sequence :: from_height( 42 ) ) )
354371 ]
355- ) ,
356- Semantic :: Key ( key_b)
372+ ) ) ,
373+ Arc :: new ( Semantic :: Key ( key_b) )
357374 ]
358375 ) ,
359376 ms_str. lift( ) . unwrap( )
0 commit comments