Skip to content

Commit e433fe9

Browse files
authored
feat(kyoto): update to latest version
1 parent fc69d85 commit e433fe9

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

bdk-ffi/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bdk-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ default = ["uniffi/cli"]
2121
bdk_wallet = { version = "2.0.0", features = ["all-keys", "keys-bip39", "rusqlite"] }
2222
bdk_esplora = { version = "0.22.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
2323
bdk_electrum = { version = "0.23.0", default-features = false, features = ["use-rustls-ring"] }
24-
bdk_kyoto = { version = "0.11.0" }
24+
bdk_kyoto = { version = "0.13.0" }
2525

2626
uniffi = { version = "=0.29.1" }
2727
thiserror = "1.0.58"

bdk-ffi/src/kyoto.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use bdk_kyoto::builder::NodeBuilder as BDKCbfBuilder;
22
use bdk_kyoto::builder::NodeBuilderExt;
3+
use bdk_kyoto::kyoto::lookup_host;
34
use bdk_kyoto::kyoto::tokio;
45
use bdk_kyoto::kyoto::AddrV2;
56
use bdk_kyoto::kyoto::ScriptBuf;
@@ -36,6 +37,7 @@ const DEFAULT_CONNECTIONS: u8 = 2;
3637
const CWD_PATH: &str = ".";
3738
const TCP_HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(2);
3839
const MESSAGE_RESPONSE_TIMEOUT: Duration = Duration::from_secs(5);
40+
const CLOUDFLARE_DNS: IpAddr = IpAddr::V4(Ipv4Addr::new(1, 1, 1, 1));
3941

4042
/// Receive a [`CbfClient`] and [`CbfNode`].
4143
#[derive(Debug, uniffi::Record)]
@@ -54,6 +56,7 @@ pub struct CbfClient {
5456
info_rx: Mutex<Receiver<bdk_kyoto::Info>>,
5557
warning_rx: Mutex<UnboundedReceiver<bdk_kyoto::Warning>>,
5658
update_rx: Mutex<UpdateSubscriber>,
59+
dns_resolver: IpAddr,
5760
}
5861

5962
/// A [`CbfNode`] gathers transactions for a [`Wallet`].
@@ -187,6 +190,9 @@ impl CbfBuilder {
187190
})
188191
}
189192

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`.
190196
pub fn socks5_proxy(&self, proxy: Socks5Proxy) -> Arc<Self> {
191197
Arc::new(CbfBuilder {
192198
socks5_proxy: Some(proxy),
@@ -240,13 +246,19 @@ impl CbfBuilder {
240246
})?;
241247

242248
let node = CbfNode { node };
249+
let client_resolver = self
250+
.dns_resolver
251+
.clone()
252+
.map(|ip| ip.inner)
253+
.unwrap_or(CLOUDFLARE_DNS);
243254

244255
let client = CbfClient {
245256
sender: Arc::new(requester),
246257
log_rx: Mutex::new(log_subscriber),
247258
info_rx: Mutex::new(info_subscriber),
248259
warning_rx: Mutex::new(warning_subscriber),
249260
update_rx: Mutex::new(update_subscriber),
261+
dns_resolver: client_resolver,
250262
};
251263

252264
Ok(CbfComponents {
@@ -328,6 +340,18 @@ impl CbfClient {
328340
.map(|fee| Arc::new(FeeRate(fee)))
329341
}
330342

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+
}
331355
/// Check if the node is still running in the background.
332356
pub fn is_running(&self) -> bool {
333357
self.sender.is_running()
@@ -346,6 +370,10 @@ pub enum Info {
346370
ConnectionsMet,
347371
/// The node was able to successfully connect to a remote peer.
348372
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 },
349377
/// A percentage value of filters that have been scanned.
350378
Progress { progress: f32 },
351379
/// A state in the node syncing process.
@@ -360,6 +388,8 @@ impl From<bdk_kyoto::Info> for Info {
360388
match value {
361389
bdk_kyoto::Info::ConnectionsMet => Info::ConnectionsMet,
362390
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 },
363393
bdk_kyoto::Info::Progress(progress) => Info::Progress {
364394
progress: progress.percentage_complete(),
365395
},

0 commit comments

Comments
 (0)