Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bdk_esplora = { version = "0.22.0", default-features = false, features = ["async
bdk_electrum = { version = "0.23.0", default-features = false, features = ["use-rustls-ring"]}
bdk_wallet = { version = "2.0.0", default-features = false, features = ["std", "keys-bip39"]}

reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls", "blocking"] }
rustls = { version = "0.23", default-features = false }
rusqlite = { version = "0.31.0", features = ["bundled"] }
bitcoin = "0.32.4"
Expand Down
26 changes: 26 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedQrPayment unified_qr_payment();
LSPS1Liquidity lsps1_liquidity();
LSPS5Liquidity lsps5_liquidity();
[Throws=NodeError]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
Expand Down Expand Up @@ -264,6 +265,15 @@ interface LSPS1Liquidity {
LSPS1OrderStatus check_order_status(LSPS1OrderId order_id);
};

interface LSPS5Liquidity {
[Throws=NodeError]
LSPS5SetWebhookResponse set_webhook(string app_name, string webhook_url);
[Throws=NodeError]
LSPS5ListWebhooksResponse list_webhooks();
[Throws=NodeError]
LSPS5RemoveWebhookResponse remove_webhook(string app_name);
};

[Error]
enum NodeError {
"AlreadyRunning",
Expand Down Expand Up @@ -320,6 +330,8 @@ enum NodeError {
"LiquidityFeeTooHigh",
"InvalidBlindedPaths",
"AsyncPaymentServicesDisabled",
"LiquiditySetWebhookFailed",
"LiquidityRemoveWebhookFailed",
};

dictionary NodeStatus {
Expand Down Expand Up @@ -531,6 +543,20 @@ enum LSPS1PaymentState {
"Refunded",
};

dictionary LSPS5SetWebhookResponse {
u32 num_webhooks;
u32 max_webhooks;
boolean no_change;
};

dictionary LSPS5ListWebhooksResponse {
sequence<string> app_names;
u32 max_webhooks;
};

dictionary LSPS5RemoveWebhookResponse {
};

[NonExhaustive]
enum Network {
"Bitcoin",
Expand Down
49 changes: 48 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crate::io::{
self, PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
};
use crate::liquidity::{
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LiquiditySourceBuilder,
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LSPS5ClientConfig,
LSPS5ServiceConfig, LiquiditySourceBuilder,
};
use crate::logger::{log_error, LdkLogger, LogLevel, LogWriter, Logger};
use crate::message_handler::NodeCustomMessageHandler;
Expand Down Expand Up @@ -125,6 +126,10 @@ struct LiquiditySourceConfig {
lsps2_client: Option<LSPS2ClientConfig>,
// Act as an LSPS2 service.
lsps2_service: Option<LSPS2ServiceConfig>,
/// Act as an LSPS5 client connecting to the given service.
lsps5_client: Option<LSPS5ClientConfig>,
// Act as an LSPS5 service.
lsps5_service: Option<LSPS5ServiceConfig>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -738,6 +743,27 @@ impl NodeBuilder {
kv_store,
)
}

/// Configures the [`Node`] instance to source inbound liquidity from the given
pub fn set_liquidity_source_lsps5(
&mut self, node_id: PublicKey, address: SocketAddress,
) -> &mut Self {
let liquidity_source_config =
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
let lsps5_client_config = LSPS5ClientConfig { node_id, address };
liquidity_source_config.lsps5_client = Some(lsps5_client_config);
self
}

/// Configures the [`Node`] instance to provide an LSPS5 service
pub fn set_liquidity_provider_lsps5(
&mut self, service_config: LSPS5ServiceConfig,
) -> &mut Self {
let liquidity_source_config =
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
liquidity_source_config.lsps5_service = Some(service_config);
self
}
}

/// A builder for an [`Node`] instance, allowing to set some configuration and module choices from
Expand Down Expand Up @@ -928,6 +954,20 @@ impl ArcedNodeBuilder {
self.inner.write().unwrap().set_liquidity_provider_lsps2(service_config);
}

/// Configures the [`Node`] instance to source inbound liquidity from the given [LSPS5] LSP.
///
/// [LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
pub fn set_liquidity_source_lsps5(&self, node_id: PublicKey, address: SocketAddress) {
self.inner.write().unwrap().set_liquidity_source_lsps5(node_id, address);
}

/// Configures the [`Node`] instance to provide an LSPS5 service.
///
/// [LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
pub fn set_liquidity_provider_lsps5(&self, service_config: LSPS5ServiceConfig) {
self.inner.write().unwrap().set_liquidity_provider_lsps5(service_config);
}

/// Sets the used storage directory path.
pub fn set_storage_dir_path(&self, storage_dir_path: String) {
self.inner.write().unwrap().set_storage_dir_path(storage_dir_path);
Expand Down Expand Up @@ -1542,6 +1582,13 @@ fn build_with_store_internal(
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
});

lsc.lsps5_client.as_ref().map(|config| {
liquidity_source_builder.lsps5_client(config.node_id, config.address.clone())
});
lsc.lsps5_service
.as_ref()
.map(|config| liquidity_source_builder.lsps5_service(config.clone()));

let liquidity_source = Arc::new(liquidity_source_builder.build());
let custom_message_handler =
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
Expand Down
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ pub enum Error {
InvalidBlindedPaths,
/// Asynchronous payment services are disabled.
AsyncPaymentServicesDisabled,
/// Failed to set a webhook with the LSP.
LiquiditySetWebhookFailed,
/// Failed to remove a webhook with the LSP.
LiquidityRemoveWebhookFailed,
}

impl fmt::Display for Error {
Expand Down Expand Up @@ -201,6 +205,12 @@ impl fmt::Display for Error {
Self::AsyncPaymentServicesDisabled => {
write!(f, "Asynchronous payment services are disabled.")
},
Self::LiquiditySetWebhookFailed => {
write!(f, "Failed to set a webhook with the LSP.")
},
Self::LiquidityRemoveWebhookFailed => {
write!(f, "Failed to remove a webhook with the LSP.")
},
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

#[cfg(feature = "uniffi")]
use crate::liquidity::{
LSPS5Liquidity, LSPS5ListWebhooksResponse, LSPS5RemoveWebhookResponse, LSPS5SetWebhookResponse,
};

#[cfg(not(feature = "uniffi"))]
use crate::liquidity::LSPS5Liquidity;

#[cfg(feature = "uniffi")]
uniffi::include_scaffolding!("ldk_node");

Expand Down Expand Up @@ -958,6 +966,32 @@ impl Node {
))
}

/// Returns a liquidity handler allowing to handle webhooks and notifications via the [bLIP-55 / LSPS5] protocol.
///
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
#[cfg(not(feature = "uniffi"))]
pub fn lsps5_liquidity(&self) -> LSPS5Liquidity {
LSPS5Liquidity::new(
Arc::clone(&self.runtime),
Arc::clone(&self.connection_manager),
self.liquidity_source.clone(),
Arc::clone(&self.logger),
)
}

/// Returns a liquidity handler allowing to handle webhooks and notifications via the [bLIP-55 / LSPS5] protocol.
///
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
#[cfg(feature = "uniffi")]
pub fn lsps5_liquidity(&self) -> Arc<LSPS5Liquidity> {
Arc::new(LSPS5Liquidity::new(
Arc::clone(&self.runtime),
Arc::clone(&self.connection_manager),
self.liquidity_source.clone(),
Arc::clone(&self.logger),
))
}

/// Retrieve a list of known channels.
pub fn list_channels(&self) -> Vec<ChannelDetails> {
self.channel_manager.list_channels().into_iter().map(|c| c.into()).collect()
Expand Down
Loading
Loading