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: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export declare class MdkNode {
syncWallets(): void
getBalance(): number
listChannels(): Array<NodeChannel>
/**
* 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<ReceivedPayment>
getInvoice(amount: number, description: string, expirySecs: number): PaymentMetadata
getInvoiceWithScid(
Expand Down
30 changes: 30 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32, napi::Error> {
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,
Expand Down Expand Up @@ -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}");
Expand Down