1010// licenses.
1111
1212use alloc:: boxed:: Box ;
13- use chain:: { ChainPosition , ConfirmationBlockTime , DescriptorExt , DescriptorId } ;
13+ use chain:: { ChainPosition , ConfirmationBlockTime , DescriptorId } ;
1414use std:: hash:: { Hash , Hasher } ;
15- use std:: prelude:: rust_2021:: Vec ;
1615use bitcoin:: transaction:: { OutPoint , Sequence , TxOut } ;
1716use bitcoin:: { psbt, Network , Weight } ;
18- use miniscript:: { Descriptor , DescriptorPublicKey } ;
19- use miniscript:: descriptor:: KeyMap ;
2017use serde:: { Deserialize , Serialize } ;
21- use crate :: descriptor:: { IntoWalletDescriptor } ;
22- use crate :: DescriptorToExtract ;
23- use crate :: wallet:: make_descriptor_to_extract;
24- use crate :: wallet:: utils:: SecpCtx ;
2518
2619/// Types of keychains
2720// #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
@@ -32,6 +25,7 @@ use crate::wallet::utils::SecpCtx;
3225// Internal = 1,
3326// }
3427
28+ // TODO #226: Figure out why these are there and implement them on the new KeychainKind.
3529// impl KeychainKind {
3630// /// Return [`KeychainKind`] as a byte
3731// pub fn as_byte(&self) -> u8 {
@@ -58,99 +52,6 @@ pub enum KeychainKind {
5852 Other ( DescriptorId ) ,
5953}
6054
61- // pub type KeychainIdentifier = (KeychainKind, Option<DescriptorId>);
62-
63- pub type WalletKeychain = ( KeychainKind , ( Descriptor < DescriptorPublicKey > , KeyMap ) ) ;
64-
65- /// A `WalletKeychain` is mostly a descriptor with metadata associated with it. It states whether the
66- /// keychain is the default keychain for the wallet, and provides an identifier for it which can be
67- /// used for retrieval.
68- // #[derive(Clone, Debug, Eq, PartialEq)]
69- // pub struct WalletKeychain {
70- // pub keychain_kind: KeychainKind,
71- // pub public_descriptor: Descriptor<DescriptorPublicKey>,
72- // pub keymap: KeyMap,
73- // }
74-
75- #[ derive( Debug , Clone ) ]
76- pub struct KeyRing {
77- keychains : Vec < WalletKeychain > ,
78- network : Network ,
79- }
80-
81- impl KeyRing {
82- pub fn new < D : IntoWalletDescriptor + Send + ' static > (
83- default_descriptor : D ,
84- network : Network ,
85- ) -> Self {
86- let secp = SecpCtx :: new ( ) ;
87- let descriptor_to_extract: DescriptorToExtract = make_descriptor_to_extract ( default_descriptor) ;
88- let public_descriptor: ( Descriptor < DescriptorPublicKey > , KeyMap ) = descriptor_to_extract ( & secp, network) . unwrap ( ) ;
89- let descriptor_id: DescriptorId = public_descriptor. 0 . descriptor_id ( ) ;
90- // Using the type alias
91- let wallet_keychain = ( ( KeychainKind :: Default ) , public_descriptor) ;
92-
93- // Using the struct
94- // let wallet_keychain = WalletKeychain {
95- // keychain_kind: KeychainKind::Default(descriptor_id),
96- // public_descriptor,
97- // keymap: KeyMap::default()
98- // };
99-
100- KeyRing {
101- keychains : vec ! [ wallet_keychain] ,
102- network,
103- }
104- }
105-
106- // TODO: This needs to never fail because there is always a default keychain.
107- pub fn get_default_keychain ( & self ) -> WalletKeychain {
108- self . keychains . iter ( ) . find ( |keychain| matches ! ( keychain. 0 , KeychainKind :: Default ) ) . unwrap ( ) . clone ( )
109- }
110-
111- pub fn get_change_keychain ( & self ) -> Option < WalletKeychain > {
112- self . keychains . iter ( ) . find ( |keychain| matches ! ( keychain. 0 , KeychainKind :: Change ) ) . cloned ( )
113- }
114-
115- pub fn add_other_descriptor < D : IntoWalletDescriptor + Send + ' static > (
116- & mut self ,
117- other_descriptor : D
118- ) -> & mut KeyRing {
119- let secp = SecpCtx :: new ( ) ;
120- let descriptor_to_extract: DescriptorToExtract = make_descriptor_to_extract ( other_descriptor) ;
121- let public_descriptor = descriptor_to_extract ( & secp, self . network ) . unwrap ( ) ;
122- let descriptor_id = public_descriptor. 0 . descriptor_id ( ) ;
123-
124- let wallet_keychain = ( ( KeychainKind :: Other ( descriptor_id) ) , public_descriptor) ;
125-
126- self . keychains . push ( wallet_keychain) ;
127- self
128- }
129-
130- pub fn list_keychains ( & self ) -> & Vec < WalletKeychain > {
131- & self . keychains
132- }
133-
134- pub fn list_keychain_ids ( & self ) -> Vec < DescriptorId > {
135- self . keychains
136- . iter ( )
137- . map ( |keychain| match keychain. 0 {
138- KeychainKind :: Other ( descriptor_id) => descriptor_id,
139- KeychainKind :: Default => keychain. 1 . 0 . descriptor_id ( ) ,
140- KeychainKind :: Change => keychain. 1 . 0 . descriptor_id ( ) ,
141- } )
142- . collect ( )
143- }
144-
145- // pub fn add_change_keychain(&mut self, keychain: (DescriptorToExtract, KeyMap), keychain_identifier: KeychainIdentifier) {
146- //
147- // }
148- // pub fn add_wallet_keychain<D: IntoWalletDescriptor + Send + 'static>(
149- // &mut self,
150- // descriptor: D,
151- // )
152- }
153-
15455/// An unspent output owned by a [`Wallet`].
15556///
15657/// [`Wallet`]: crate::Wallet
0 commit comments