@@ -47,8 +47,8 @@ mod sh;
4747mod sortedmulti;
4848// Descriptor Exports
4949pub use self :: bare:: { Bare , Pkh } ;
50- pub use self :: segwitv0:: { Wpkh , Wsh } ;
51- pub use self :: sh:: Sh ;
50+ pub use self :: segwitv0:: { Wpkh , Wsh , WshInner } ;
51+ pub use self :: sh:: { Sh , ShInner } ;
5252pub use self :: sortedmulti:: SortedMultiVec ;
5353
5454mod checksum;
@@ -168,6 +168,31 @@ pub enum Descriptor<Pk: MiniscriptKey> {
168168 Wsh ( Wsh < Pk > ) ,
169169}
170170
171+ /// Descriptor Type of the descriptor
172+ #[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
173+ pub enum DescriptorType {
174+ /// Bare descriptor(Contains the native P2pk)
175+ Bare ,
176+ /// Pure Sh Descriptor. Does not contain nested Wsh/Wpkh
177+ Sh ,
178+ /// Pkh Descriptor
179+ Pkh ,
180+ /// Wpkh Descriptor
181+ Wpkh ,
182+ /// Wsh
183+ Wsh ,
184+ /// Sh Wrapped Wsh
185+ ShWsh ,
186+ /// Sh wrapped Wpkh
187+ ShWpkh ,
188+ /// Sh Sorted Multi
189+ ShSortedMulti ,
190+ /// Wsh Sorted Multi
191+ WshSortedMulti ,
192+ /// Sh Wsh Sorted Multi
193+ ShWshSortedMulti ,
194+ }
195+
171196impl < Pk : MiniscriptKey > Descriptor < Pk > {
172197 // Keys
173198
@@ -251,6 +276,28 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
251276 pub fn new_wsh_sortedmulti ( k : usize , pks : Vec < Pk > ) -> Result < Self , Error > {
252277 Ok ( Descriptor :: Wsh ( Wsh :: new_sortedmulti ( k, pks) ?) )
253278 }
279+
280+ /// Get the [DescriptorType] of [Descriptor]
281+ pub fn desc_type ( & self ) -> DescriptorType {
282+ match * self {
283+ Descriptor :: Bare ( ref _bare) => DescriptorType :: Bare ,
284+ Descriptor :: Pkh ( ref _pkh) => DescriptorType :: Pkh ,
285+ Descriptor :: Wpkh ( ref _wpkh) => DescriptorType :: Wpkh ,
286+ Descriptor :: Sh ( ref sh) => match sh. as_inner ( ) {
287+ ShInner :: Wsh ( ref wsh) => match wsh. as_inner ( ) {
288+ WshInner :: SortedMulti ( ref _smv) => DescriptorType :: ShWshSortedMulti ,
289+ WshInner :: Ms ( ref _ms) => DescriptorType :: ShWsh ,
290+ } ,
291+ ShInner :: Wpkh ( ref _wpkh) => DescriptorType :: ShWpkh ,
292+ ShInner :: SortedMulti ( ref _smv) => DescriptorType :: ShSortedMulti ,
293+ ShInner :: Ms ( ref _ms) => DescriptorType :: Sh ,
294+ } ,
295+ Descriptor :: Wsh ( ref wsh) => match wsh. as_inner ( ) {
296+ WshInner :: SortedMulti ( ref _smv) => DescriptorType :: WshSortedMulti ,
297+ WshInner :: Ms ( ref _ms) => DescriptorType :: Wsh ,
298+ } ,
299+ }
300+ }
254301}
255302
256303impl < P : MiniscriptKey , Q : MiniscriptKey > TranslatePk < P , Q > for Descriptor < P > {
0 commit comments