1
1
use bdk_kyoto:: builder:: NodeBuilder as BDKCbfBuilder ;
2
2
use bdk_kyoto:: builder:: NodeBuilderExt ;
3
+ use bdk_kyoto:: kyoto:: lookup_host;
3
4
use bdk_kyoto:: kyoto:: tokio;
4
5
use bdk_kyoto:: kyoto:: AddrV2 ;
5
6
use bdk_kyoto:: kyoto:: ScriptBuf ;
@@ -36,6 +37,7 @@ const DEFAULT_CONNECTIONS: u8 = 2;
36
37
const CWD_PATH : & str = "." ;
37
38
const TCP_HANDSHAKE_TIMEOUT : Duration = Duration :: from_secs ( 2 ) ;
38
39
const MESSAGE_RESPONSE_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
40
+ const CLOUDFLARE_DNS : IpAddr = IpAddr :: V4 ( Ipv4Addr :: new ( 1 , 1 , 1 , 1 ) ) ;
39
41
40
42
/// Receive a [`CbfClient`] and [`CbfNode`].
41
43
#[ derive( Debug , uniffi:: Record ) ]
@@ -54,6 +56,7 @@ pub struct CbfClient {
54
56
info_rx : Mutex < Receiver < bdk_kyoto:: Info > > ,
55
57
warning_rx : Mutex < UnboundedReceiver < bdk_kyoto:: Warning > > ,
56
58
update_rx : Mutex < UpdateSubscriber > ,
59
+ dns_resolver : IpAddr ,
57
60
}
58
61
59
62
/// A [`CbfNode`] gathers transactions for a [`Wallet`].
@@ -187,6 +190,9 @@ impl CbfBuilder {
187
190
} )
188
191
}
189
192
193
+ /// Configure connections to be established through a `Socks5 proxy. The vast majority of the
194
+ /// time, the connection is to a local Tor daemon, which is typically exposed at
195
+ /// `127.0.0.1:9050`.
190
196
pub fn socks5_proxy ( & self , proxy : Socks5Proxy ) -> Arc < Self > {
191
197
Arc :: new ( CbfBuilder {
192
198
socks5_proxy : Some ( proxy) ,
@@ -240,13 +246,19 @@ impl CbfBuilder {
240
246
} ) ?;
241
247
242
248
let node = CbfNode { node } ;
249
+ let client_resolver = self
250
+ . dns_resolver
251
+ . clone ( )
252
+ . map ( |ip| ip. inner )
253
+ . unwrap_or ( CLOUDFLARE_DNS ) ;
243
254
244
255
let client = CbfClient {
245
256
sender : Arc :: new ( requester) ,
246
257
log_rx : Mutex :: new ( log_subscriber) ,
247
258
info_rx : Mutex :: new ( info_subscriber) ,
248
259
warning_rx : Mutex :: new ( warning_subscriber) ,
249
260
update_rx : Mutex :: new ( update_subscriber) ,
261
+ dns_resolver : client_resolver,
250
262
} ;
251
263
252
264
Ok ( CbfComponents {
@@ -328,6 +340,18 @@ impl CbfClient {
328
340
. map ( |fee| Arc :: new ( FeeRate ( fee) ) )
329
341
}
330
342
343
+ /// Query a Bitcoin DNS seeder using the configured resolver.
344
+ ///
345
+ /// This is **not** a generic DNS implementation. Host names are prefixed with a `x849` to filter
346
+ /// for compact block filter nodes from the seeder. For example `dns.myseeder.com` will be queried
347
+ /// as `x849.dns.myseeder.com`. This has no guarantee to return any `IpAddr`.
348
+ pub async fn lookup_host ( & self , hostname : String ) -> Vec < Arc < IpAddress > > {
349
+ let nodes = lookup_host ( hostname, self . dns_resolver ) . await ;
350
+ nodes
351
+ . into_iter ( )
352
+ . map ( |ip| Arc :: new ( IpAddress { inner : ip } ) )
353
+ . collect ( )
354
+ }
331
355
/// Check if the node is still running in the background.
332
356
pub fn is_running ( & self ) -> bool {
333
357
self . sender . is_running ( )
@@ -346,6 +370,10 @@ pub enum Info {
346
370
ConnectionsMet ,
347
371
/// The node was able to successfully connect to a remote peer.
348
372
SuccessfulHandshake ,
373
+ /// The block header chain of most work was extended to this height.
374
+ NewChainHeight { height : u32 } ,
375
+ /// A new fork was advertised to the node, but has not been selected yet.
376
+ NewFork { height : u32 } ,
349
377
/// A percentage value of filters that have been scanned.
350
378
Progress { progress : f32 } ,
351
379
/// A state in the node syncing process.
@@ -360,6 +388,8 @@ impl From<bdk_kyoto::Info> for Info {
360
388
match value {
361
389
bdk_kyoto:: Info :: ConnectionsMet => Info :: ConnectionsMet ,
362
390
bdk_kyoto:: Info :: SuccessfulHandshake => Info :: SuccessfulHandshake ,
391
+ bdk_kyoto:: Info :: NewChainHeight ( height) => Info :: NewChainHeight { height } ,
392
+ bdk_kyoto:: Info :: NewFork { tip } => Info :: NewFork { height : tip. height } ,
363
393
bdk_kyoto:: Info :: Progress ( progress) => Info :: Progress {
364
394
progress : progress. percentage_complete ( ) ,
365
395
} ,
0 commit comments