@@ -32,7 +32,7 @@ use expression;
3232use miniscript:: types:: { self , Property } ;
3333use miniscript:: ScriptContext ;
3434use script_num_size;
35- use { Error , Miniscript , MiniscriptKey , Terminal , ToPublicKey , TranslatePk } ;
35+ use { Error , ForEach , ForEachKey , Miniscript , MiniscriptKey , Terminal , ToPublicKey , TranslatePk } ;
3636
3737impl < Pk : MiniscriptKey , Ctx : ScriptContext > Terminal < Pk , Ctx > {
3838 /// Internal helper function for displaying wrapper types; returns
@@ -77,6 +77,49 @@ impl<Pk: MiniscriptKey, Q: MiniscriptKey, Ctx: ScriptContext> TranslatePk<Pk, Q>
7777}
7878
7979impl < Pk : MiniscriptKey , Ctx : ScriptContext > Terminal < Pk , Ctx > {
80+ pub ( super ) fn real_for_each_key < ' a , F : FnMut ( ForEach < ' a , Pk > ) -> bool > (
81+ & ' a self ,
82+ pred : & mut F ,
83+ ) -> bool
84+ where
85+ Pk : ' a ,
86+ Pk :: Hash : ' a ,
87+ {
88+ match * self {
89+ Terminal :: PkK ( ref p) => pred ( ForEach :: Key ( p) ) ,
90+ Terminal :: PkH ( ref p) => pred ( ForEach :: Hash ( p) ) ,
91+ Terminal :: After ( ..)
92+ | Terminal :: Older ( ..)
93+ | Terminal :: Sha256 ( ..)
94+ | Terminal :: Hash256 ( ..)
95+ | Terminal :: Ripemd160 ( ..)
96+ | Terminal :: Hash160 ( ..)
97+ | Terminal :: True
98+ | Terminal :: False => true ,
99+ Terminal :: Alt ( ref sub)
100+ | Terminal :: Swap ( ref sub)
101+ | Terminal :: Check ( ref sub)
102+ | Terminal :: DupIf ( ref sub)
103+ | Terminal :: Verify ( ref sub)
104+ | Terminal :: NonZero ( ref sub)
105+ | Terminal :: ZeroNotEqual ( ref sub) => sub. real_for_each_key ( pred) ,
106+ Terminal :: AndV ( ref left, ref right)
107+ | Terminal :: AndB ( ref left, ref right)
108+ | Terminal :: OrB ( ref left, ref right)
109+ | Terminal :: OrD ( ref left, ref right)
110+ | Terminal :: OrC ( ref left, ref right)
111+ | Terminal :: OrI ( ref left, ref right) => {
112+ left. real_for_each_key ( & mut * pred) && right. real_for_each_key ( pred)
113+ }
114+ Terminal :: AndOr ( ref a, ref b, ref c) => {
115+ a. real_for_each_key ( & mut * pred)
116+ && b. real_for_each_key ( & mut * pred)
117+ && c. real_for_each_key ( pred)
118+ }
119+ Terminal :: Thresh ( _, ref subs) => subs. iter ( ) . all ( |sub| sub. real_for_each_key ( pred) ) ,
120+ Terminal :: Multi ( _, ref keys) => keys. iter ( ) . all ( |key| pred ( ForEach :: Key ( key) ) ) ,
121+ }
122+ }
80123 pub ( super ) fn real_translate_pk < FPk , FPkh , Q , Error > (
81124 & self ,
82125 translatefpk : & mut FPk ,
@@ -169,6 +212,16 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
169212 }
170213}
171214
215+ impl < Pk : MiniscriptKey , Ctx : ScriptContext > ForEachKey < Pk > for Terminal < Pk , Ctx > {
216+ fn for_each_key < ' a , F : FnMut ( ForEach < ' a , Pk > ) -> bool > ( & ' a self , mut pred : F ) -> bool
217+ where
218+ Pk : ' a ,
219+ Pk :: Hash : ' a ,
220+ {
221+ self . real_for_each_key ( & mut pred)
222+ }
223+ }
224+
172225impl < Pk : MiniscriptKey , Ctx : ScriptContext > fmt:: Debug for Terminal < Pk , Ctx > {
173226 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
174227 f. write_str ( "[" ) ?;
0 commit comments