diff --git a/Cargo.toml b/Cargo.toml index 2731636..6ca1b6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ bitcoin-payment-instructions = { version = "0.5.0", default-features = false, fe "http", ] } # Branch: https://github.com/moneydevkit/ldk-node/commits/lsp-0.6.2/ -ldk-node = { default-features = false, git = "https://github.com/moneydevkit/ldk-node.git", rev = "7dc77ccc5e841dbd3e66a42ac529a30702035774" } -napi = { version = "2", features = ["napi4"] } +ldk-node = { default-features = false, git = "https://github.com/moneydevkit/ldk-node.git", rev = "b70720fa63eb39e7f588a672d0a5faf7729b7a7d" } +napi = { version = "2", features = ["napi4"] } napi-derive = "2" -tokio = { version = "1", features = ["rt-multi-thread"] } +tokio = { version = "1", features = ["rt-multi-thread"] } # Temporary pin: ldk-node pulls in home 0.5.12 which needs edition2024 cargo home = "=0.5.11" # Pin ICU crates to keep MSRV at 1.82.0 diff --git a/index.d.ts b/index.d.ts index 95ffec5..e879dd8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -46,6 +46,13 @@ export declare class MdkNode { syncWallets(): void getBalance(): number listChannels(): Array + /** + * Manually sync the RGS snapshot. + * + * If `do_full_sync` is true, the RGS snapshot will be updated from scratch. Otherwise, the + * snapshot will be updated from the last known sync point. + */ + syncRgs(doFullSync: boolean): number receivePayment(minThresholdMs: number, quietThresholdMs: number): Array getInvoice(amount: number, description: string, expirySecs: number): PaymentMetadata getInvoiceWithScid( diff --git a/src/lib.rs b/src/lib.rs index 38ebad0..7265be4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -407,6 +407,23 @@ impl MdkNode { .collect() } + /// Manually sync the RGS snapshot. + /// + /// If `do_full_sync` is true, the RGS snapshot will be updated from scratch. Otherwise, the + /// snapshot will be updated from the last known sync point. + #[napi] + pub fn sync_rgs(&self, do_full_sync: bool) -> Result { + let rt = tokio::runtime::Runtime::new() + .map_err(|e| napi::Error::from_reason(format!("Failed to create runtime: {}", e)))?; + rt.block_on(async { + self + .node + .sync_rgs(do_full_sync) + .await + .map_err(|e| napi::Error::from_reason(format!("Failed to sync RGS: {}", e))) + }) + } + #[napi] pub fn receive_payment( &self, @@ -988,6 +1005,19 @@ impl MdkNode { ) })?; + // Full RGS sync to get node announcements (addresses/features) needed for BOLT12 + eprintln!("[lightning-js] pay_bolt12_offer doing full RGS sync"); + let rt = tokio::runtime::Runtime::new().expect("Failed to create runtime for RGS sync"); + rt.block_on(async { + match self.node.sync_rgs(true).await { + Ok(ts) => eprintln!( + "[lightning-js] pay_bolt12_offer RGS sync complete, timestamp={}", + ts + ), + Err(e) => eprintln!("[lightning-js] pay_bolt12_offer RGS sync failed: {}", e), + } + }); + eprintln!("[lightning-js] pay_bolt12_offer syncing wallets"); if let Err(err) = self.node.sync_wallets() { eprintln!("[lightning-js] Failed to sync wallets: {err}");