Skip to content

Commit 78cf4fd

Browse files
committed
feat: add proxy to electrum and esplora
1 parent bb89233 commit 78cf4fd

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
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? socks5 = 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, socks5: Option<String>) -> Result<Self, ElectrumError> {
29+
let mut config = bdk_electrum::electrum_client::ConfigBuilder::new();
30+
if let Some(socks5) = socks5 {
31+
config = config.socks5(Some(bdk_electrum::electrum_client::Socks5Config::new(
32+
socks5.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(

bdk-ffi/src/tx_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ mod tests {
608608
Arc::new(Connection::new_in_memory().unwrap()),
609609
)
610610
.unwrap();
611-
let client = EsploraClient::new("https://mutinynet.com/api/".to_string());
611+
let client = EsploraClient::new("https://mutinynet.com/api/".to_string(), None);
612612
let full_scan_builder = wallet.start_full_scan();
613613
let full_scan_request = full_scan_builder
614614
.inspect_spks_for_all_keychains(Arc::new(FullScanInspector))

0 commit comments

Comments
 (0)