@@ -23,11 +23,17 @@ use super::{ExtendedDescriptor, IntoWalletDescriptor, KeyMap};
2323use crate :: descriptor:: DescriptorError ;
2424use crate :: keys:: { DerivableKey , IntoDescriptorKey , ValidNetworks } ;
2525use crate :: wallet:: utils:: SecpCtx ;
26- use crate :: { descriptor, KeychainKind } ;
26+ use crate :: descriptor;
2727
2828/// Type alias for the return type of [`DescriptorTemplate`], [`descriptor!`](crate::descriptor!) and others
2929pub type DescriptorTemplateOut = ( ExtendedDescriptor , KeyMap , ValidNetworks ) ;
3030
31+ #[ derive( Clone , Debug ) ]
32+ pub enum TemplateKeychainKind {
33+ External ,
34+ Internal ,
35+ }
36+
3137/// Trait for descriptor templates that can be built into a full descriptor
3238///
3339/// Since [`IntoWalletDescriptor`] is implemented for any [`DescriptorTemplate`], they can also be
@@ -232,7 +238,7 @@ impl<K: IntoDescriptorKey<Tap>> DescriptorTemplate for P2TR<K> {
232238/// # Ok::<_, Box<dyn std::error::Error>>(())
233239/// ```
234240#[ derive( Debug , Clone ) ]
235- pub struct Bip44 < K : DerivableKey < Legacy > > ( pub K , pub KeychainKind ) ;
241+ pub struct Bip44 < K : DerivableKey < Legacy > > ( pub K , pub TemplateKeychainKind ) ;
236242
237243impl < K : DerivableKey < Legacy > > DescriptorTemplate for Bip44 < K > {
238244 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -271,7 +277,7 @@ impl<K: DerivableKey<Legacy>> DescriptorTemplate for Bip44<K> {
271277/// # Ok::<_, Box<dyn std::error::Error>>(())
272278/// ```
273279#[ derive( Debug , Clone ) ]
274- pub struct Bip44Public < K : DerivableKey < Legacy > > ( pub K , pub bip32:: Fingerprint , pub KeychainKind ) ;
280+ pub struct Bip44Public < K : DerivableKey < Legacy > > ( pub K , pub bip32:: Fingerprint , pub TemplateKeychainKind ) ;
275281
276282impl < K : DerivableKey < Legacy > > DescriptorTemplate for Bip44Public < K > {
277283 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -309,7 +315,7 @@ impl<K: DerivableKey<Legacy>> DescriptorTemplate for Bip44Public<K> {
309315/// # Ok::<_, Box<dyn std::error::Error>>(())
310316/// ```
311317#[ derive( Debug , Clone ) ]
312- pub struct Bip49 < K : DerivableKey < Segwitv0 > > ( pub K , pub KeychainKind ) ;
318+ pub struct Bip49 < K : DerivableKey < Segwitv0 > > ( pub K , pub TemplateKeychainKind ) ;
313319
314320impl < K : DerivableKey < Segwitv0 > > DescriptorTemplate for Bip49 < K > {
315321 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -348,7 +354,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip49<K> {
348354/// # Ok::<_, Box<dyn std::error::Error>>(())
349355/// ```
350356#[ derive( Debug , Clone ) ]
351- pub struct Bip49Public < K : DerivableKey < Segwitv0 > > ( pub K , pub bip32:: Fingerprint , pub KeychainKind ) ;
357+ pub struct Bip49Public < K : DerivableKey < Segwitv0 > > ( pub K , pub bip32:: Fingerprint , pub TemplateKeychainKind ) ;
352358
353359impl < K : DerivableKey < Segwitv0 > > DescriptorTemplate for Bip49Public < K > {
354360 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -386,7 +392,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip49Public<K> {
386392/// # Ok::<_, Box<dyn std::error::Error>>(())
387393/// ```
388394#[ derive( Debug , Clone ) ]
389- pub struct Bip84 < K : DerivableKey < Segwitv0 > > ( pub K , pub KeychainKind ) ;
395+ pub struct Bip84 < K : DerivableKey < Segwitv0 > > ( pub K , pub TemplateKeychainKind ) ;
390396
391397impl < K : DerivableKey < Segwitv0 > > DescriptorTemplate for Bip84 < K > {
392398 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -425,7 +431,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip84<K> {
425431/// # Ok::<_, Box<dyn std::error::Error>>(())
426432/// ```
427433#[ derive( Debug , Clone ) ]
428- pub struct Bip84Public < K : DerivableKey < Segwitv0 > > ( pub K , pub bip32:: Fingerprint , pub KeychainKind ) ;
434+ pub struct Bip84Public < K : DerivableKey < Segwitv0 > > ( pub K , pub bip32:: Fingerprint , pub TemplateKeychainKind ) ;
429435
430436impl < K : DerivableKey < Segwitv0 > > DescriptorTemplate for Bip84Public < K > {
431437 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -463,7 +469,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip84Public<K> {
463469/// # Ok::<_, Box<dyn std::error::Error>>(())
464470/// ```
465471#[ derive( Debug , Clone ) ]
466- pub struct Bip86 < K : DerivableKey < Tap > > ( pub K , pub KeychainKind ) ;
472+ pub struct Bip86 < K : DerivableKey < Tap > > ( pub K , pub TemplateKeychainKind ) ;
467473
468474impl < K : DerivableKey < Tap > > DescriptorTemplate for Bip86 < K > {
469475 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -502,7 +508,7 @@ impl<K: DerivableKey<Tap>> DescriptorTemplate for Bip86<K> {
502508/// # Ok::<_, Box<dyn std::error::Error>>(())
503509/// ```
504510#[ derive( Debug , Clone ) ]
505- pub struct Bip86Public < K : DerivableKey < Tap > > ( pub K , pub bip32:: Fingerprint , pub KeychainKind ) ;
511+ pub struct Bip86Public < K : DerivableKey < Tap > > ( pub K , pub bip32:: Fingerprint , pub TemplateKeychainKind ) ;
506512
507513impl < K : DerivableKey < Tap > > DescriptorTemplate for Bip86Public < K > {
508514 fn build ( self , network : Network ) -> Result < DescriptorTemplateOut , DescriptorError > {
@@ -521,7 +527,7 @@ macro_rules! expand_make_bipxx {
521527 pub ( super ) fn make_bipxx_private<K : DerivableKey <$ctx>>(
522528 bip: u32 ,
523529 key: K ,
524- keychain: KeychainKind ,
530+ keychain: TemplateKeychainKind ,
525531 network: Network ,
526532 ) -> Result <impl IntoDescriptorKey <$ctx>, DescriptorError > {
527533 let mut derivation_path = alloc:: vec:: Vec :: with_capacity( 4 ) ;
@@ -538,10 +544,10 @@ macro_rules! expand_make_bipxx {
538544 derivation_path. push( bip32:: ChildNumber :: from_hardened_idx( 0 ) ?) ;
539545
540546 match keychain {
541- KeychainKind :: External => {
547+ TemplateKeychainKind :: External => {
542548 derivation_path. push( bip32:: ChildNumber :: from_normal_idx( 0 ) ?)
543549 }
544- KeychainKind :: Internal => {
550+ TemplateKeychainKind :: Internal => {
545551 derivation_path. push( bip32:: ChildNumber :: from_normal_idx( 1 ) ?)
546552 }
547553 } ;
@@ -554,12 +560,12 @@ macro_rules! expand_make_bipxx {
554560 bip: u32 ,
555561 key: K ,
556562 parent_fingerprint: bip32:: Fingerprint ,
557- keychain: KeychainKind ,
563+ keychain: TemplateKeychainKind ,
558564 network: Network ,
559565 ) -> Result <impl IntoDescriptorKey <$ctx>, DescriptorError > {
560566 let derivation_path: bip32:: DerivationPath = match keychain {
561- KeychainKind :: External => vec![ bip32:: ChildNumber :: from_normal_idx( 0 ) ?] . into( ) ,
562- KeychainKind :: Internal => vec![ bip32:: ChildNumber :: from_normal_idx( 1 ) ?] . into( ) ,
567+ TemplateKeychainKind :: External => vec![ bip32:: ChildNumber :: from_normal_idx( 0 ) ?] . into( ) ,
568+ TemplateKeychainKind :: Internal => vec![ bip32:: ChildNumber :: from_normal_idx( 1 ) ?] . into( ) ,
563569 } ;
564570
565571 let source_path = bip32:: DerivationPath :: from( vec![
0 commit comments