11use std:: { net, thread} ;
2+ use core:: fmt:: Debug ;
23
34use bdk_chain:: keychain:: DerivationAdditions ;
45use nakamoto:: client:: network:: Services ;
56use nakamoto:: client:: Handle ;
67use nakamoto:: client:: traits:: Handle as HandleTrait ;
78use nakamoto:: client:: { chan, Client , Config , Error , Event } ;
8- use nakamoto:: common:: block:: Height ;
99use nakamoto:: net:: poll;
1010
1111pub use nakamoto:: client:: network:: Network ;
12+ pub use nakamoto:: common:: block:: Height ;
1213
1314use bdk_chain:: {
1415 bitcoin:: { Script , Transaction } ,
@@ -18,10 +19,13 @@ use bdk_chain::{
1819 BlockId , ChainOracle , ConfirmationHeightAnchor , TxGraph ,
1920} ;
2021
21- use core:: fmt:: Debug ;
22-
2322type Reactor = poll:: Reactor < net:: TcpStream > ;
2423
24+ #[ derive( Clone ) ]
25+ pub struct CBFClient {
26+ handle : Handle < poll:: reactor:: Waker > ,
27+ }
28+
2529impl ChainOracle for CBFClient {
2630 type Error = nakamoto:: client:: Error ;
2731
@@ -56,11 +60,6 @@ impl ChainOracle for CBFClient {
5660 }
5761}
5862
59- #[ derive( Clone ) ]
60- pub struct CBFClient {
61- handle : Handle < poll:: reactor:: Waker > ,
62- }
63-
6463#[ derive( Debug , Clone ) ]
6564pub enum CBFUpdate {
6665 Synced {
@@ -97,7 +96,11 @@ impl Iterator for CBFUpdateIterator {
9796}
9897
9998impl CBFClient {
100- pub fn start_client ( cfg : Config , peer_count : usize ) -> Result < Self , Error > {
99+ pub fn start_client ( network : Network , peer_count : usize ) -> Result < Self , Error > {
100+ let cfg = Config {
101+ network,
102+ ..Default :: default ( )
103+ } ;
101104 let client = Client :: < Reactor > :: new ( ) ?;
102105 let handle = client. handle ( ) ;
103106
@@ -112,7 +115,7 @@ impl CBFClient {
112115 Ok ( Self { handle } )
113116 }
114117
115- //create a function to watch
118+ /// Given a list of scripts, start scanning the chain from the given height.
116119 pub fn start_scanning (
117120 & self ,
118121 start_height : Height ,
@@ -123,7 +126,7 @@ impl CBFClient {
123126 Ok ( ( ) )
124127 }
125128
126- // Watch for Block events that match the scripts we're interested in
129+ /// Listen for nakamoto events that are relevant to scripts we are watching.
127130 pub fn watch_events ( & self ) -> Result < CBFUpdate , Error > {
128131 let events_chan = self . handle . events ( ) ;
129132 loop {
@@ -158,7 +161,7 @@ impl CBFClient {
158161 }
159162 }
160163
161- // Turns a CBFUpdate into a TxGraph update
164+ /// Given a list of tuples of block and their transactions, create a TxGraph update.
162165 pub fn into_tx_graph_update (
163166 & self ,
164167 block_txs : Vec < ( BlockId , Vec < Transaction > ) > ,
@@ -201,7 +204,7 @@ impl CBFClient {
201204
202205 while let Some ( keychains) = Self :: check_stop_gap ( stop_gap, & empty_scripts_counter) {
203206 keychains. iter ( ) . for_each ( |k| {
204- /*let (_, _) =*/ indexed_tx_graph. index . set_lookahead ( k, watch_per_keychain) ;
207+ indexed_tx_graph. index . set_lookahead ( k, watch_per_keychain) ;
205208 } ) ;
206209
207210 let mut spk_watchlist = BTreeMap :: < K , Vec < Script > > :: new ( ) ;
@@ -244,7 +247,7 @@ impl CBFClient {
244247 for ( k, scripts) in spk_watchlist. iter ( ) {
245248 for script in scripts {
246249 let counter = empty_scripts_counter. get_mut ( k) . unwrap ( ) ;
247- if Self :: is_script_in_udpate ( script. clone ( ) , & updates) {
250+ if Self :: is_script_in_udpates ( script. clone ( ) , & updates) {
248251 * counter = 0 ;
249252 } else {
250253 * counter += 1 ;
@@ -262,7 +265,7 @@ impl CBFClient {
262265 Ok ( additions)
263266 }
264267
265- fn is_script_in_udpate ( script : Script , updates : & Vec < ( BlockId , Vec < Transaction > ) > ) -> bool {
268+ fn is_script_in_udpates ( script : Script , updates : & Vec < ( BlockId , Vec < Transaction > ) > ) -> bool {
266269 for update in updates {
267270 for tx in update. 1 . iter ( ) {
268271 for output in tx. output . iter ( ) {
0 commit comments