Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,8 @@ interface Descriptor {
/// cache to avoid re-fetching already downloaded transactions.
interface EsploraClient {
/// Creates a new bdk client from a esplora_client::BlockingClient
constructor(string url);
/// Optional: Set the proxy of the builder
constructor(string url, optional string? proxy = null);

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

/// Full scan the keychain scripts specified with the blockchain (via an Electrum client) and
/// returns updates for bdk_chain data structures.
Expand Down
12 changes: 9 additions & 3 deletions bdk-ffi/src/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ use std::sync::Arc;
pub struct ElectrumClient(BdkBdkElectrumClient<bdk_electrum::electrum_client::Client>);

impl ElectrumClient {
pub fn new(url: String) -> Result<Self, ElectrumError> {
let inner_client: bdk_electrum::electrum_client::Client =
bdk_electrum::electrum_client::Client::new(url.as_str())?;
pub fn new(url: String, socks5: Option<String>) -> Result<Self, ElectrumError> {
let mut config = bdk_electrum::electrum_client::ConfigBuilder::new();
if let Some(socks5) = socks5 {
config = config.socks5(Some(bdk_electrum::electrum_client::Socks5Config::new(
socks5.as_str(),
)));
}
let inner_client =
bdk_electrum::electrum_client::Client::from_config(url.as_str(), config.build())?;
let client = BdkBdkElectrumClient::new(inner_client);
Ok(Self(client))
}
Expand Down
9 changes: 6 additions & 3 deletions bdk-ffi/src/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ use std::sync::Arc;
pub struct EsploraClient(BlockingClient);

impl EsploraClient {
pub fn new(url: String) -> Self {
let client = Builder::new(url.as_str()).build_blocking();
Self(client)
pub fn new(url: String, proxy: Option<String>) -> Self {
let mut builder = Builder::new(url.as_str());
if let Some(proxy) = proxy {
builder = builder.proxy(proxy.as_str());
}
Self(builder.build_blocking())
}

pub fn full_scan(
Expand Down
2 changes: 1 addition & 1 deletion bdk-ffi/src/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ mod tests {
Arc::new(Connection::new_in_memory().unwrap()),
)
.unwrap();
let client = EsploraClient::new("https://mutinynet.com/api/".to_string());
let client = EsploraClient::new("https://mutinynet.com/api/".to_string(), None);
let full_scan_builder = wallet.start_full_scan();
let full_scan_request = full_scan_builder
.inspect_spks_for_all_keychains(Arc::new(FullScanInspector))
Expand Down
Loading