Skip to content

Commit f046eaf

Browse files
committed
f Impl client() and from_client()
1 parent c17369d commit f046eaf

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

lightning-transaction-sync/src/esplora.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ where
4545
last_sync_hash: std::sync::Mutex<Option<BlockHash>>,
4646
#[cfg(feature = "async-interface")]
4747
last_sync_hash: futures::lock::Mutex<Option<BlockHash>>,
48-
#[cfg(not(feature = "async-interface"))]
49-
client: BlockingClient,
50-
#[cfg(feature = "async-interface")]
51-
client: AsyncClient,
48+
client: EsploraClientType,
5249
logger: L,
5350
}
5451

@@ -150,6 +147,17 @@ where
150147

151148
/// Returns a new [`EsploraSyncClient`] object.
152149
pub fn new(server_url: String, logger: L) -> Self {
150+
let builder = Builder::new(&server_url);
151+
#[cfg(not(feature = "async-interface"))]
152+
let client = builder.build_blocking().unwrap();
153+
#[cfg(feature = "async-interface")]
154+
let client = builder.build_async().unwrap();
155+
156+
EsploraSyncClient::from_client(client, logger)
157+
}
158+
159+
/// Returns a new [`EsploraSyncClient`] object using the given esplora client.
160+
pub fn from_client(client: EsploraClientType, logger: L) -> Self {
153161
let watched_transactions = Mutex::new(HashSet::new());
154162
let queued_transactions = Mutex::new(HashSet::new());
155163
let watched_outputs = Mutex::new(HashSet::new());
@@ -159,11 +167,6 @@ where
159167
let last_sync_hash = Mutex::new(None);
160168
#[cfg(feature = "async-interface")]
161169
let last_sync_hash = futures::lock::Mutex::new(None);
162-
let builder = Builder::new(&server_url);
163-
#[cfg(not(feature = "async-interface"))]
164-
let client = builder.build_blocking().unwrap();
165-
#[cfg(feature = "async-interface")]
166-
let client = builder.build_async().unwrap();
167170
Self {
168171
queued_transactions,
169172
watched_transactions,
@@ -370,8 +373,20 @@ where
370373

371374
Ok(())
372375
}
376+
377+
/// Returns a reference to the underlying esplora client.
378+
pub fn client(&self) -> &EsploraClientType {
379+
&self.client
380+
}
373381
}
374382

383+
/// The underlying client type.
384+
#[cfg(feature = "async-interface")]
385+
pub type EsploraClientType = AsyncClient;
386+
#[cfg(not(feature = "async-interface"))]
387+
pub type EsploraClientType = BlockingClient;
388+
389+
375390
struct ConfirmedTx {
376391
tx: Transaction,
377392
block_header: BlockHeader,

lightning-transaction-sync/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
1313

14+
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
1415
#[macro_use]
1516
extern crate bdk_macros;
1617

0 commit comments

Comments
 (0)