Skip to content

Commit fd81e5b

Browse files
committed
Add LSPS5 webhook notification support
Integrates LSPS5 (BLIP-0055) from lightning-liquidity to enable webhook-based push notifications for clients. - Add event system integration for LSPS5 events - Expose public API for webhook management This allows client developers to register webhook endpoints with their LSP to receive notifications when their app is offline.
1 parent 5d0fb14 commit fd81e5b

File tree

5 files changed

+945
-10
lines changed

5 files changed

+945
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bdk_esplora = { version = "0.22.0", default-features = false, features = ["async
5656
bdk_electrum = { version = "0.23.0", default-features = false, features = ["use-rustls-ring"]}
5757
bdk_wallet = { version = "2.2.0", default-features = false, features = ["std", "keys-bip39"]}
5858

59-
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
59+
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls", "blocking"] }
6060
rustls = { version = "0.23", default-features = false }
6161
rusqlite = { version = "0.31.0", features = ["bundled"] }
6262
bitcoin = "0.32.7"

src/builder.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ use crate::io::{
6161
self, PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
6262
};
6363
use crate::liquidity::{
64-
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LiquiditySourceBuilder,
64+
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LSPS5ClientConfig,
65+
LSPS5ServiceConfig, LiquiditySourceBuilder,
6566
};
6667
use crate::logger::{log_error, LdkLogger, LogLevel, LogWriter, Logger};
6768
use crate::message_handler::NodeCustomMessageHandler;
@@ -119,6 +120,10 @@ struct LiquiditySourceConfig {
119120
lsps2_client: Option<LSPS2ClientConfig>,
120121
// Act as an LSPS2 service.
121122
lsps2_service: Option<LSPS2ServiceConfig>,
123+
// Act as an LSPS5 client connecting to the given service.
124+
lsps5_client: Option<LSPS5ClientConfig>,
125+
// Act as an LSPS5 service.
126+
lsps5_service: Option<LSPS5ServiceConfig>,
122127
}
123128

124129
#[derive(Clone)]
@@ -444,6 +449,30 @@ impl NodeBuilder {
444449
self
445450
}
446451

452+
/// Configures the [`Node`] instance to source inbound liquidity from the given
453+
/// [bLIP-137 / LSPS5] service.
454+
///
455+
/// [bLIP-137 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
456+
pub fn set_liquidity_source_lsps5(
457+
&mut self, node_id: PublicKey, address: SocketAddress,
458+
) -> &mut Self {
459+
let liquidity_source_config =
460+
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
461+
let lsps5_client_config = LSPS5ClientConfig { node_id, address };
462+
liquidity_source_config.lsps5_client = Some(lsps5_client_config);
463+
self
464+
}
465+
466+
/// Configures the [`Node`] instance to provide an LSPS5 service
467+
pub fn set_liquidity_provider_lsps5(
468+
&mut self, service_config: LSPS5ServiceConfig,
469+
) -> &mut Self {
470+
let liquidity_source_config =
471+
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
472+
liquidity_source_config.lsps5_service = Some(service_config);
473+
self
474+
}
475+
447476
/// Sets the used storage directory path.
448477
pub fn set_storage_dir_path(&mut self, storage_dir_path: String) -> &mut Self {
449478
self.config.storage_dir_path = storage_dir_path;
@@ -1547,6 +1576,14 @@ fn build_with_store_internal(
15471576
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
15481577
});
15491578

1579+
lsc.lsps5_client.as_ref().map(|config| {
1580+
liquidity_source_builder.lsps5_client(config.node_id, config.address.clone())
1581+
});
1582+
1583+
lsc.lsps5_service
1584+
.as_ref()
1585+
.map(|config| liquidity_source_builder.lsps5_service(config.clone()));
1586+
15501587
let liquidity_source = runtime
15511588
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
15521589
let custom_message_handler =

src/error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ pub enum Error {
127127
InvalidBlindedPaths,
128128
/// Asynchronous payment services are disabled.
129129
AsyncPaymentServicesDisabled,
130+
/// Failed to set a webhook with the LSP.
131+
LiquiditySetWebhookFailed,
132+
/// Failed to remove a webhook with the LSP.
133+
LiquidityRemoveWebhookFailed,
130134
}
131135

132136
impl fmt::Display for Error {
@@ -205,6 +209,12 @@ impl fmt::Display for Error {
205209
Self::AsyncPaymentServicesDisabled => {
206210
write!(f, "Asynchronous payment services are disabled.")
207211
},
212+
Self::LiquiditySetWebhookFailed => {
213+
write!(f, "Failed to set a webhook with the LSP.")
214+
},
215+
Self::LiquidityRemoveWebhookFailed => {
216+
write!(f, "Failed to remove a webhook with the LSP.")
217+
},
208218
}
209219
}
210220
}

src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ use lightning::ln::msgs::SocketAddress;
146146
use lightning::routing::gossip::NodeAlias;
147147
use lightning::util::persist::KVStoreSync;
148148
use lightning_background_processor::process_events_async;
149-
use liquidity::{LSPS1Liquidity, LiquiditySource};
149+
use liquidity::{LSPS1Liquidity, LSPS5Liquidity, LiquiditySource};
150150
use logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
151151
use payment::asynchronous::om_mailbox::OnionMessageMailbox;
152152
use payment::asynchronous::static_invoice_store::StaticInvoiceStore;
@@ -1004,6 +1004,32 @@ impl Node {
10041004
))
10051005
}
10061006

1007+
/// Returns a liquidity handler allowing to handle webhooks and notifications via the [bLIP-55 / LSPS5] protocol.
1008+
///
1009+
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
1010+
#[cfg(not(feature = "uniffi"))]
1011+
pub fn lsps5_liquidity(&self) -> LSPS5Liquidity {
1012+
LSPS5Liquidity::new(
1013+
Arc::clone(&self.runtime),
1014+
Arc::clone(&self.connection_manager),
1015+
self.liquidity_source.clone(),
1016+
Arc::clone(&self.logger),
1017+
)
1018+
}
1019+
1020+
/// Returns a liquidity handler allowing to handle webhooks and notifications via the [bLIP-55 / LSPS5] protocol.
1021+
///
1022+
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
1023+
#[cfg(feature = "uniffi")]
1024+
pub fn lsps5_liquidity(&self) -> Arc<LSPS5Liquidity> {
1025+
Arc::new(LSPS5Liquidity::new(
1026+
Arc::clone(&self.runtime),
1027+
Arc::clone(&self.connection_manager),
1028+
self.liquidity_source.clone(),
1029+
Arc::clone(&self.logger),
1030+
))
1031+
}
1032+
10071033
/// Retrieve a list of known channels.
10081034
pub fn list_channels(&self) -> Vec<ChannelDetails> {
10091035
self.channel_manager.list_channels().into_iter().map(|c| c.into()).collect()

0 commit comments

Comments
 (0)