@@ -15,7 +15,7 @@ pub use tree::{
1515} ;
1616
1717use crate :: sync:: Arc ;
18- use crate :: { Miniscript , MiniscriptKey , ScriptContext , Terminal } ;
18+ use crate :: { policy , Miniscript , MiniscriptKey , ScriptContext , Terminal } ;
1919
2020impl < ' a , Pk : MiniscriptKey , Ctx : ScriptContext > TreeLike for & ' a Miniscript < Pk , Ctx > {
2121 fn as_node ( & self ) -> Tree < Self > {
@@ -68,3 +68,29 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for Arc<Miniscript<Pk, Ctx>
6868 }
6969 }
7070}
71+
72+ impl < ' a , Pk : MiniscriptKey > TreeLike for & ' a policy:: Concrete < Pk > {
73+ fn as_node ( & self ) -> Tree < Self > {
74+ use policy:: Concrete :: * ;
75+ match * self {
76+ Unsatisfiable | Trivial | Key ( _) | After ( _) | Older ( _) | Sha256 ( _) | Hash256 ( _)
77+ | Ripemd160 ( _) | Hash160 ( _) => Tree :: Nullary ,
78+ And ( ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: as_ref) . collect ( ) ) ,
79+ Or ( ref v) => Tree :: Nary ( v. iter ( ) . map ( |( _, p) | p. as_ref ( ) ) . collect ( ) ) ,
80+ Threshold ( _, ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: as_ref) . collect ( ) ) ,
81+ }
82+ }
83+ }
84+
85+ impl < ' a , Pk : MiniscriptKey > TreeLike for Arc < policy:: Concrete < Pk > > {
86+ fn as_node ( & self ) -> Tree < Self > {
87+ use policy:: Concrete :: * ;
88+ match self . as_ref ( ) {
89+ Unsatisfiable | Trivial | Key ( _) | After ( _) | Older ( _) | Sha256 ( _) | Hash256 ( _)
90+ | Ripemd160 ( _) | Hash160 ( _) => Tree :: Nullary ,
91+ And ( ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: clone) . collect ( ) ) ,
92+ Or ( ref v) => Tree :: Nary ( v. iter ( ) . map ( |( _, p) | Arc :: clone ( p) ) . collect ( ) ) ,
93+ Threshold ( _, ref subs) => Tree :: Nary ( subs. iter ( ) . map ( Arc :: clone) . collect ( ) ) ,
94+ }
95+ }
96+ }
0 commit comments