Skip to content

Commit 533ba8b

Browse files
committed
feat: add proxy to electrum and esplora
1 parent b1d6aca commit 533ba8b

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ interface Descriptor {
921921
/// cache to avoid re-fetching already downloaded transactions.
922922
interface EsploraClient {
923923
/// Creates a new bdk client from a esplora_client::BlockingClient
924-
constructor(string url);
924+
/// Optional: Set the proxy of the builder
925+
constructor(string url, optional string? proxy = null);
925926

926927
/// Scan keychain scripts for transactions against Esplora, returning an update that can be
927928
/// applied to the receiving structures.
@@ -979,8 +980,9 @@ interface EsploraClient {
979980
/// cache to avoid re-fetching already downloaded transactions.
980981
interface ElectrumClient {
981982
/// Creates a new bdk client from a electrum_client::ElectrumApi
983+
/// Optional: Set the proxy of the builder
982984
[Throws=ElectrumError]
983-
constructor(string url);
985+
constructor(string url, optional string? proxy = null);
984986

985987
/// Full scan the keychain scripts specified with the blockchain (via an Electrum client) and
986988
/// returns updates for bdk_chain data structures.

bdk-ffi/src/electrum.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ use std::sync::Arc;
2525
pub struct ElectrumClient(BdkBdkElectrumClient<bdk_electrum::electrum_client::Client>);
2626

2727
impl ElectrumClient {
28-
pub fn new(url: String) -> Result<Self, ElectrumError> {
29-
let inner_client: bdk_electrum::electrum_client::Client =
30-
bdk_electrum::electrum_client::Client::new(url.as_str())?;
28+
pub fn new(url: String, proxy: Option<String>) -> Result<Self, ElectrumError> {
29+
let mut config = bdk_electrum::electrum_client::ConfigBuilder::new();
30+
if let Some(proxy) = proxy {
31+
config = config.socks5(Some(bdk_electrum::electrum_client::Socks5Config::new(
32+
proxy.as_str(),
33+
)));
34+
}
35+
let inner_client =
36+
bdk_electrum::electrum_client::Client::from_config(url.as_str(), config.build())?;
3137
let client = BdkBdkElectrumClient::new(inner_client);
3238
Ok(Self(client))
3339
}

bdk-ffi/src/esplora.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ use std::sync::Arc;
2323
pub struct EsploraClient(BlockingClient);
2424

2525
impl EsploraClient {
26-
pub fn new(url: String) -> Self {
27-
let client = Builder::new(url.as_str()).build_blocking();
28-
Self(client)
26+
pub fn new(url: String, proxy: Option<String>) -> Self {
27+
let mut builder = Builder::new(url.as_str());
28+
if let Some(proxy) = proxy {
29+
builder = builder.proxy(proxy.as_str());
30+
}
31+
Self(builder.build_blocking())
2932
}
3033

3134
pub fn full_scan(

0 commit comments

Comments
 (0)