Skip to content

Commit 289aa1e

Browse files
committed
fix: align fork with upstream LDK 0.7 architecture
1 parent 13b4053 commit 289aa1e

File tree

13 files changed

+285
-998
lines changed

13 files changed

+285
-998
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ interface Bolt11Payment {
213213
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
214214
[Throws=NodeError]
215215
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
216+
[Throws=NodeError]
216217
u64 estimate_routing_fees([ByRef]Bolt11Invoice invoice);
217218
[Throws=NodeError]
218219
u64 estimate_routing_fees_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);

src/builder.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,9 +1357,6 @@ fn build_with_store_internal(
13571357
Arc::clone(&logger),
13581358
));
13591359

1360-
// Set the wallet in the chain source for event processing
1361-
chain_source.set_onchain_wallet(Arc::clone(&wallet));
1362-
13631360
// Initialize the KeysManager
13641361
let cur_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map_err(|e| {
13651362
log_error!(logger, "Failed to get current time: {}", e);

src/chain/electrum.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const ELECTRUM_CLIENT_TIMEOUT_SECS: u8 = 10;
4848
pub(super) struct ElectrumChainSource {
4949
server_url: String,
5050
pub(super) sync_config: ElectrumSyncConfig,
51-
pub(super) electrum_runtime_status: RwLock<ElectrumRuntimeStatus>,
51+
electrum_runtime_status: RwLock<ElectrumRuntimeStatus>,
5252
onchain_wallet_sync_status: Mutex<WalletSyncStatus>,
5353
lightning_wallet_sync_status: Mutex<WalletSyncStatus>,
5454
fee_estimator: Arc<OnchainFeeEstimator>,
@@ -309,6 +309,16 @@ impl ElectrumChainSource {
309309
electrum_client.broadcast(tx).await;
310310
}
311311
}
312+
313+
pub(super) async fn get_address_balance(&self, address: &bitcoin::Address) -> Option<u64> {
314+
let electrum_client: Arc<ElectrumRuntimeClient> =
315+
if let Some(client) = self.electrum_runtime_status.read().unwrap().client().as_ref() {
316+
Arc::clone(client)
317+
} else {
318+
return None;
319+
};
320+
electrum_client.get_address_balance(address).await
321+
}
312322
}
313323

314324
impl Filter for ElectrumChainSource {
@@ -370,7 +380,7 @@ impl ElectrumRuntimeStatus {
370380
*self = Self::new()
371381
}
372382

373-
pub(super) fn client(&self) -> Option<Arc<ElectrumRuntimeClient>> {
383+
fn client(&self) -> Option<Arc<ElectrumRuntimeClient>> {
374384
match self {
375385
Self::Started(client) => Some(Arc::clone(&client)),
376386
Self::Stopped { .. } => None,
@@ -455,7 +465,7 @@ impl ElectrumRuntimeClient {
455465
}
456466
}
457467

458-
pub(crate) async fn sync_confirmables(
468+
async fn sync_confirmables(
459469
&self, confirmables: Vec<Arc<dyn Confirm + Sync + Send>>,
460470
) -> Result<(), Error> {
461471
let now = Instant::now();

src/chain/esplora.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use bdk_wallet::event::WalletEvent;
3535

3636
pub(super) struct EsploraChainSource {
3737
pub(super) sync_config: EsploraSyncConfig,
38-
pub(super) esplora_client: EsploraAsyncClient,
38+
esplora_client: EsploraAsyncClient,
3939
onchain_wallet_sync_status: Mutex<WalletSyncStatus>,
4040
tx_sync: Arc<EsploraSyncClient<Arc<Logger>>>,
4141
lightning_wallet_sync_status: Mutex<WalletSyncStatus>,
@@ -88,11 +88,13 @@ impl EsploraChainSource {
8888
};
8989
if let Some(mut sync_receiver) = receiver_res {
9090
log_info!(self.logger, "Sync in progress, skipping.");
91-
return sync_receiver.recv().await.map_err(|e| {
91+
sync_receiver.recv().await.map_err(|e| {
9292
debug_assert!(false, "Failed to receive wallet sync result: {:?}", e);
9393
log_error!(self.logger, "Failed to receive wallet sync result: {:?}", e);
9494
Error::WalletOperationFailed
95-
})?;
95+
})??;
96+
// Return empty events since we're just waiting for another sync
97+
return Ok(Vec::new());
9698
}
9799

98100
let res = self.sync_onchain_wallet_inner(onchain_wallet).await;
@@ -435,6 +437,31 @@ impl EsploraChainSource {
435437
}
436438
}
437439
}
440+
441+
pub(super) async fn get_address_balance(&self, address: &bitcoin::Address) -> Option<u64> {
442+
let script = address.script_pubkey();
443+
match self.esplora_client.scripthash_txs(&script, None).await {
444+
Ok(txs) => {
445+
let mut balance = 0i64;
446+
for tx in txs {
447+
for output in &tx.vout {
448+
if output.scriptpubkey == script {
449+
balance += output.value as i64;
450+
}
451+
}
452+
for input in &tx.vin {
453+
if let Some(prevout) = &input.prevout {
454+
if prevout.scriptpubkey == script {
455+
balance -= prevout.value as i64;
456+
}
457+
}
458+
}
459+
}
460+
Some(balance.max(0) as u64)
461+
},
462+
Err(_) => None,
463+
}
464+
}
438465
}
439466

440467
impl Filter for EsploraChainSource {

0 commit comments

Comments
 (0)