1- use bdk_kyoto:: builder:: LightClientBuilder as BDKLightClientBuilder ;
1+ use bdk_kyoto:: builder:: LightClientBuilder as BDKCbfBuilder ;
22use bdk_kyoto:: builder:: ServiceFlags ;
33use bdk_kyoto:: builder:: TrustedPeer ;
44use bdk_kyoto:: kyoto:: tokio;
@@ -24,7 +24,7 @@ use std::time::Duration;
2424use tokio:: sync:: Mutex ;
2525
2626use crate :: bitcoin:: Transaction ;
27- use crate :: error:: { LightClientBuilderError , LightClientError } ;
27+ use crate :: error:: { CbfBuilderError , CbfError } ;
2828use crate :: wallet:: Wallet ;
2929use crate :: FeeRate ;
3030use crate :: Update ;
@@ -35,35 +35,35 @@ const TIMEOUT: u64 = 10;
3535const DEFAULT_CONNECTIONS : u8 = 2 ;
3636const CWD_PATH : & str = "." ;
3737
38- /// Receive a [`Client `] and [`LightNode `].
38+ /// Receive a [`CbfClient `] and [`CbfNode `].
3939#[ derive( Debug , uniffi:: Record ) ]
40- pub struct LightClient {
40+ pub struct CbfComponents {
4141 /// Publish events to the node, like broadcasting transactions or adding scripts.
42- pub client : Arc < Client > ,
42+ pub client : Arc < CbfClient > ,
4343 /// The node to run and fetch transactions for a [`Wallet`].
44- pub node : Arc < LightNode > ,
44+ pub node : Arc < CbfNode > ,
4545}
4646
47- /// A [`Client `] handles wallet updates from a [`LightNode `].
47+ /// A [`CbfClient `] handles wallet updates from a [`CbfNode `].
4848#[ derive( Debug , uniffi:: Object ) ]
49- pub struct Client {
49+ pub struct CbfClient {
5050 sender : Arc < Requester > ,
5151 log_rx : Mutex < Receiver < bdk_kyoto:: Log > > ,
5252 warning_rx : Mutex < UnboundedReceiver < bdk_kyoto:: Warning > > ,
5353 update_rx : Mutex < UpdateSubscriber > ,
5454}
5555
56- /// A [`LightNode `] gathers transactions for a [`Wallet`].
56+ /// A [`CbfNode `] gathers transactions for a [`Wallet`].
5757/// To receive [`Update`] for [`Wallet`], refer to the
58- /// [`Client `]. The [`LightNode `] will run until instructed
58+ /// [`CbfClient `]. The [`CbfNode `] will run until instructed
5959/// to stop.
6060#[ derive( Debug , uniffi:: Object ) ]
61- pub struct LightNode {
61+ pub struct CbfNode {
6262 node : NodeDefault ,
6363}
6464
6565#[ uniffi:: export]
66- impl LightNode {
66+ impl CbfNode {
6767 /// Start the node on a detached OS thread and immediately return.
6868 pub fn run ( self : Arc < Self > ) {
6969 std:: thread:: spawn ( || {
@@ -92,7 +92,7 @@ impl LightNode {
9292/// `lookahead` value will be used. To ensure all transactions are recovered, the
9393/// `lookahead` should be roughly the number of transactions in the wallet history.
9494#[ derive( Clone , uniffi:: Object ) ]
95- pub struct LightClientBuilder {
95+ pub struct CbfBuilder {
9696 connections : u8 ,
9797 data_dir : Option < String > ,
9898 scan_type : ScanType ,
@@ -102,11 +102,11 @@ pub struct LightClientBuilder {
102102}
103103
104104#[ uniffi:: export]
105- impl LightClientBuilder {
106- /// Start a new [`LightClientBuilder `]
105+ impl CbfBuilder {
106+ /// Start a new [`CbfBuilder `]
107107 #[ uniffi:: constructor]
108108 pub fn new ( ) -> Self {
109- LightClientBuilder {
109+ CbfBuilder {
110110 connections : DEFAULT_CONNECTIONS ,
111111 data_dir : None ,
112112 scan_type : ScanType :: default ( ) ,
@@ -118,7 +118,7 @@ impl LightClientBuilder {
118118
119119 /// The number of connections for the light client to maintain. Default is two.
120120 pub fn connections ( & self , connections : u8 ) -> Arc < Self > {
121- Arc :: new ( LightClientBuilder {
121+ Arc :: new ( CbfBuilder {
122122 connections,
123123 ..self . clone ( )
124124 } )
@@ -127,15 +127,15 @@ impl LightClientBuilder {
127127 /// Directory to store block headers and peers. If none is provided, the current
128128 /// working directory will be used.
129129 pub fn data_dir ( & self , data_dir : String ) -> Arc < Self > {
130- Arc :: new ( LightClientBuilder {
130+ Arc :: new ( CbfBuilder {
131131 data_dir : Some ( data_dir) ,
132132 ..self . clone ( )
133133 } )
134134 }
135135
136136 /// Select between syncing, recovering, or scanning for new wallets.
137137 pub fn scan_type ( & self , scan_type : ScanType ) -> Arc < Self > {
138- Arc :: new ( LightClientBuilder {
138+ Arc :: new ( CbfBuilder {
139139 scan_type,
140140 ..self . clone ( )
141141 } )
@@ -144,15 +144,15 @@ impl LightClientBuilder {
144144 /// Set the log level for the node. Production applications may want to omit `Debug` messages
145145 /// to avoid heap allocations.
146146 pub fn log_level ( & self , log_level : LogLevel ) -> Arc < Self > {
147- Arc :: new ( LightClientBuilder {
147+ Arc :: new ( CbfBuilder {
148148 log_level,
149149 ..self . clone ( )
150150 } )
151151 }
152152
153153 /// Bitcoin full-nodes to attempt a connection with.
154154 pub fn peers ( & self , peers : Vec < Peer > ) -> Arc < Self > {
155- Arc :: new ( LightClientBuilder {
155+ Arc :: new ( CbfBuilder {
156156 peers,
157157 ..self . clone ( )
158158 } )
@@ -161,14 +161,14 @@ impl LightClientBuilder {
161161 /// Configure a custom DNS resolver when querying DNS seeds. Default is `1.1.1.1` managed by
162162 /// CloudFlare.
163163 pub fn dns_resolver ( & self , dns_resolver : Arc < IpAddress > ) -> Arc < Self > {
164- Arc :: new ( LightClientBuilder {
164+ Arc :: new ( CbfBuilder {
165165 dns_resolver : Some ( dns_resolver) ,
166166 ..self . clone ( )
167167 } )
168168 }
169169
170- /// Construct a [`LightClient `] for a [`Wallet`].
171- pub fn build ( & self , wallet : & Wallet ) -> Result < LightClient , LightClientBuilderError > {
170+ /// Construct a [`CbfComponents `] for a [`Wallet`].
171+ pub fn build ( & self , wallet : & Wallet ) -> Result < CbfComponents , CbfBuilderError > {
172172 let wallet = wallet. get_wallet ( ) ;
173173
174174 let mut trusted_peers = Vec :: new ( ) ;
@@ -181,7 +181,7 @@ impl LightClientBuilder {
181181 . map ( |path| PathBuf :: from ( & path) )
182182 . unwrap_or ( PathBuf :: from ( CWD_PATH ) ) ;
183183
184- let mut builder = BDKLightClientBuilder :: new ( )
184+ let mut builder = BDKCbfBuilder :: new ( )
185185 . connections ( self . connections )
186186 . data_dir ( path_buf)
187187 . scan_type ( self . scan_type . into ( ) )
@@ -201,42 +201,42 @@ impl LightClientBuilder {
201201 node,
202202 } = builder. build ( & wallet) ?;
203203
204- let node = LightNode { node } ;
204+ let node = CbfNode { node } ;
205205
206- let client = Client {
206+ let client = CbfClient {
207207 sender : Arc :: new ( requester) ,
208208 log_rx : Mutex :: new ( log_subscriber) ,
209209 warning_rx : Mutex :: new ( warning_subscriber) ,
210210 update_rx : Mutex :: new ( update_subscriber) ,
211211 } ;
212212
213- Ok ( LightClient {
213+ Ok ( CbfComponents {
214214 client : Arc :: new ( client) ,
215215 node : Arc :: new ( node) ,
216216 } )
217217 }
218218}
219219
220220#[ uniffi:: export]
221- impl Client {
221+ impl CbfClient {
222222 /// Return the next available log message from a node. If none is returned, the node has stopped.
223- pub async fn next_log ( & self ) -> Result < Log , LightClientError > {
223+ pub async fn next_log ( & self ) -> Result < Log , CbfError > {
224224 let mut log_rx = self . log_rx . lock ( ) . await ;
225225 log_rx
226226 . recv ( )
227227 . await
228228 . map ( |log| log. into ( ) )
229- . ok_or ( LightClientError :: NodeStopped )
229+ . ok_or ( CbfError :: NodeStopped )
230230 }
231231
232232 /// Return the next available warning message from a node. If none is returned, the node has stopped.
233- pub async fn next_warning ( & self ) -> Result < Warning , LightClientError > {
233+ pub async fn next_warning ( & self ) -> Result < Warning , CbfError > {
234234 let mut warn_rx = self . warning_rx . lock ( ) . await ;
235235 warn_rx
236236 . recv ( )
237237 . await
238238 . map ( |warn| warn. into ( ) )
239- . ok_or ( LightClientError :: NodeStopped )
239+ . ok_or ( CbfError :: NodeStopped )
240240 }
241241
242242 /// Return an [`Update`]. This is method returns once the node syncs to the rest of
@@ -250,7 +250,7 @@ impl Client {
250250 /// a transaction or revealing a receive address.
251251 ///
252252 /// Note that only future blocks will be checked for these scripts, not past blocks.
253- pub async fn add_revealed_scripts ( & self , wallet : & Wallet ) -> Result < ( ) , LightClientError > {
253+ pub async fn add_revealed_scripts ( & self , wallet : & Wallet ) -> Result < ( ) , CbfError > {
254254 let script_iter: Vec < ScriptBuf > = {
255255 let wallet_lock = wallet. get_wallet ( ) ;
256256 wallet_lock. peek_revealed_plus_lookahead ( ) . collect ( )
@@ -259,23 +259,23 @@ impl Client {
259259 self . sender
260260 . add_script ( script)
261261 . await
262- . map_err ( |_| LightClientError :: NodeStopped ) ?
262+ . map_err ( |_| CbfError :: NodeStopped ) ?
263263 }
264264 Ok ( ( ) )
265265 }
266266
267267 /// Broadcast a transaction to the network, erroring if the node has stopped running.
268- pub async fn broadcast ( & self , transaction : & Transaction ) -> Result < ( ) , LightClientError > {
268+ pub async fn broadcast ( & self , transaction : & Transaction ) -> Result < ( ) , CbfError > {
269269 let tx = transaction. into ( ) ;
270270 self . sender . broadcast_random ( tx) . await . map_err ( From :: from)
271271 }
272272
273273 /// The minimum fee rate required to broadcast a transcation to all connected peers.
274- pub async fn min_broadcast_feerate ( & self ) -> Result < Arc < FeeRate > , LightClientError > {
274+ pub async fn min_broadcast_feerate ( & self ) -> Result < Arc < FeeRate > , CbfError > {
275275 self . sender
276276 . broadcast_min_feerate ( )
277277 . await
278- . map_err ( |_| LightClientError :: NodeStopped )
278+ . map_err ( |_| CbfError :: NodeStopped )
279279 . map ( |fee| Arc :: new ( FeeRate ( fee) ) )
280280 }
281281
@@ -284,8 +284,8 @@ impl Client {
284284 self . sender . is_running ( ) . await
285285 }
286286
287- /// Stop the [`LightNode `]. Errors if the node is already stopped.
288- pub async fn shutdown ( & self ) -> Result < ( ) , LightClientError > {
287+ /// Stop the [`CbfNode `]. Errors if the node is already stopped.
288+ pub async fn shutdown ( & self ) -> Result < ( ) , CbfError > {
289289 self . sender . shutdown ( ) . await . map_err ( From :: from)
290290 }
291291}
0 commit comments