@@ -29,6 +29,8 @@ use crate::wallet::Wallet;
2929use crate :: FeeRate ;
3030use crate :: Update ;
3131
32+ type LogLevel = bdk_kyoto:: kyoto:: LogLevel ;
33+
3234const TIMEOUT : u64 = 10 ;
3335const DEFAULT_CONNECTIONS : u8 = 2 ;
3436const CWD_PATH : & str = "." ;
@@ -94,6 +96,8 @@ pub struct LightClientBuilder {
9496 connections : u8 ,
9597 data_dir : Option < String > ,
9698 scan_type : ScanType ,
99+ log_level : LogLevel ,
100+ dns_resolver : Option < Arc < IpAddress > > ,
97101 peers : Vec < Peer > ,
98102}
99103
@@ -106,6 +110,8 @@ impl LightClientBuilder {
106110 connections : DEFAULT_CONNECTIONS ,
107111 data_dir : None ,
108112 scan_type : ScanType :: default ( ) ,
113+ log_level : LogLevel :: default ( ) ,
114+ dns_resolver : None ,
109115 peers : Vec :: new ( ) ,
110116 }
111117 }
@@ -135,6 +141,15 @@ impl LightClientBuilder {
135141 } )
136142 }
137143
144+ /// Set the log level for the node. Production applications may want to omit `Debug` messages
145+ /// to avoid heap allocations.
146+ pub fn log_level ( & self , log_level : LogLevel ) -> Arc < Self > {
147+ Arc :: new ( LightClientBuilder {
148+ log_level,
149+ ..self . clone ( )
150+ } )
151+ }
152+
138153 /// Bitcoin full-nodes to attempt a connection with.
139154 pub fn peers ( & self , peers : Vec < Peer > ) -> Arc < Self > {
140155 Arc :: new ( LightClientBuilder {
@@ -143,6 +158,15 @@ impl LightClientBuilder {
143158 } )
144159 }
145160
161+ /// Configure a custom DNS resolver when querying DNS seeds. Default is `1.1.1.1` managed by
162+ /// CloudFlare.
163+ pub fn dns_resolver ( & self , dns_resolver : Arc < IpAddress > ) -> Arc < Self > {
164+ Arc :: new ( LightClientBuilder {
165+ dns_resolver : Some ( dns_resolver) ,
166+ ..self . clone ( )
167+ } )
168+ }
169+
146170 /// Construct a [`LightClient`] for a [`Wallet`].
147171 pub fn build ( & self , wallet : & Wallet ) -> Result < LightClient , LightClientBuilderError > {
148172 let wallet = wallet. get_wallet ( ) ;
@@ -157,13 +181,18 @@ impl LightClientBuilder {
157181 . map ( |path| PathBuf :: from ( & path) )
158182 . unwrap_or ( PathBuf :: from ( CWD_PATH ) ) ;
159183
160- let builder = BDKLightClientBuilder :: new ( )
184+ let mut builder = BDKLightClientBuilder :: new ( )
161185 . connections ( self . connections )
162186 . data_dir ( path_buf)
163187 . scan_type ( self . scan_type . into ( ) )
188+ . log_level ( self . log_level )
164189 . timeout_duration ( Duration :: from_secs ( TIMEOUT ) )
165190 . peers ( trusted_peers) ;
166191
192+ if let Some ( ip_addr) = self . dns_resolver . clone ( ) . map ( |ip| ip. inner ) {
193+ builder = builder. dns_resolver ( ip_addr) ;
194+ }
195+
167196 let BDKLightClient {
168197 requester,
169198 log_subscriber,
@@ -361,6 +390,17 @@ impl From<Warn> for Warning {
361390 }
362391}
363392
393+ /// Select the category of messages for the node to emit.
394+ #[ uniffi:: remote( Enum ) ]
395+ pub enum LogLevel {
396+ /// Send `Log::Debug` messages. These messages are intended for debugging or troubleshooting
397+ /// node operation.
398+ Debug ,
399+ /// Omit `Log::Debug` messages, including their memory allocations. Ideal for a production
400+ /// application that uses minimal logging.
401+ Warning ,
402+ }
403+
364404/// Sync a wallet from the last known block hash, recover a wallet from a specified height,
365405/// or perform an expedited block header download for a new wallet.
366406#[ derive( Debug , Clone , Copy , Default , uniffi:: Enum ) ]
0 commit comments