@@ -77,6 +77,7 @@ use vss_client::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvide
7777
7878const VSS_HARDENED_CHILD_INDEX : u32 = 877 ;
7979const VSS_LNURL_AUTH_HARDENED_CHILD_INDEX : u32 = 138 ;
80+ const LSPS_HARDENED_CHILD_INDEX : u32 = 577 ;
8081
8182#[ derive( Debug , Clone ) ]
8283enum ChainDataSourceConfig {
@@ -103,6 +104,8 @@ struct LiquiditySourceConfig {
103104 lsps1_client : Option < LSPS1ClientConfig > ,
104105 // Act as an LSPS2 client connecting to the given service.
105106 lsps2_client : Option < LSPS2ClientConfig > ,
107+ // Act as an LSPS2 service.
108+ lsps2_service : Option < LSPS2ServiceConfig > ,
106109}
107110
108111#[ derive( Debug , Clone ) ]
@@ -119,6 +122,12 @@ struct LSPS2ClientConfig {
119122 token : Option < String > ,
120123}
121124
125+ #[ derive( Debug , Clone ) ]
126+ struct LSPS2ServiceConfig {
127+ token : Option < String > ,
128+ advertise_service : bool ,
129+ }
130+
122131#[ derive( Clone ) ]
123132enum LogWriterConfig {
124133 File {
@@ -374,6 +383,26 @@ impl NodeBuilder {
374383 self
375384 }
376385
386+ /// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time
387+ /// channels to clients.
388+ ///
389+ /// If a `token` is provided, only requests matching this token will be accepted.
390+ ///
391+ /// If `advertise_service` is set, the LSPS service will be announced via the gossip network.
392+ ///
393+ /// **Caution**: LSP service support is in **alpha** and is considered an experimental feature.
394+ ///
395+ /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
396+ pub fn set_liquidity_provider_lsps2 (
397+ & mut self , token : Option < String > , advertise_service : bool ,
398+ ) -> & mut Self {
399+ let liquidity_source_config =
400+ self . liquidity_source_config . get_or_insert ( LiquiditySourceConfig :: default ( ) ) ;
401+ let lsps2_service_config = LSPS2ServiceConfig { token, advertise_service } ;
402+ liquidity_source_config. lsps2_service = Some ( lsps2_service_config) ;
403+ self
404+ }
405+
377406 /// Sets the used storage directory path.
378407 pub fn set_storage_dir_path ( & mut self , storage_dir_path : String ) -> & mut Self {
379408 self . config . storage_dir_path = storage_dir_path;
@@ -724,6 +753,20 @@ impl ArcedNodeBuilder {
724753 self . inner . write ( ) . unwrap ( ) . set_liquidity_source_lsps2 ( node_id, address, token) ;
725754 }
726755
756+ /// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time
757+ /// channels to clients.
758+ ///
759+ /// If a `token` is provided, only requests matching this token will be accepted.
760+ ///
761+ /// If `advertise_service` is set, the LSPS service will be announced via the gossip network.
762+ ///
763+ /// **Caution**: LSP service support is in **alpha** and is considered an experimental feature.
764+ ///
765+ /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
766+ pub fn set_liquidity_provider_lsps2 ( & self , token : Option < String > , advertise_service : bool ) {
767+ self . inner . write ( ) . unwrap ( ) . set_liquidity_provider_lsps2 ( token, advertise_service) ;
768+ }
769+
727770 /// Sets the used storage directory path.
728771 pub fn set_storage_dir_path ( & self , storage_dir_path : String ) {
729772 self . inner . write ( ) . unwrap ( ) . set_storage_dir_path ( storage_dir_path) ;
@@ -1186,39 +1229,56 @@ fn build_with_store_internal(
11861229 } ,
11871230 } ;
11881231
1189- let liquidity_source = liquidity_source_config. as_ref ( ) . map ( |lsc| {
1190- let mut liquidity_source_builder = LiquiditySourceBuilder :: new (
1191- Arc :: clone ( & channel_manager) ,
1192- Arc :: clone ( & keys_manager) ,
1193- Arc :: clone ( & chain_source) ,
1194- Arc :: clone ( & config) ,
1195- Arc :: clone ( & logger) ,
1196- ) ;
1232+ let ( liquidity_source, custom_message_handler) =
1233+ if let Some ( lsc) = liquidity_source_config. as_ref ( ) {
1234+ let mut liquidity_source_builder = LiquiditySourceBuilder :: new (
1235+ Arc :: clone ( & channel_manager) ,
1236+ Arc :: clone ( & keys_manager) ,
1237+ Arc :: clone ( & chain_source) ,
1238+ Arc :: clone ( & config) ,
1239+ Arc :: clone ( & logger) ,
1240+ ) ;
11971241
1198- lsc. lsps1_client . as_ref ( ) . map ( |config| {
1199- liquidity_source_builder. lsps1_client (
1200- config. node_id ,
1201- config. address . clone ( ) ,
1202- config. token . clone ( ) ,
1203- )
1204- } ) ;
1242+ lsc. lsps1_client . as_ref ( ) . map ( |config| {
1243+ liquidity_source_builder. lsps1_client (
1244+ config. node_id ,
1245+ config. address . clone ( ) ,
1246+ config. token . clone ( ) ,
1247+ )
1248+ } ) ;
12051249
1206- lsc. lsps2_client . as_ref ( ) . map ( |config| {
1207- liquidity_source_builder. lsps2_client (
1208- config. node_id ,
1209- config. address . clone ( ) ,
1210- config. token . clone ( ) ,
1211- )
1212- } ) ;
1250+ lsc. lsps2_client . as_ref ( ) . map ( |config| {
1251+ liquidity_source_builder. lsps2_client (
1252+ config. node_id ,
1253+ config. address . clone ( ) ,
1254+ config. token . clone ( ) ,
1255+ )
1256+ } ) ;
12131257
1214- Arc :: new ( liquidity_source_builder. build ( ) )
1215- } ) ;
1258+ let promise_secret = {
1259+ let lsps_xpriv = derive_xprv (
1260+ Arc :: clone ( & config) ,
1261+ & seed_bytes,
1262+ LSPS_HARDENED_CHILD_INDEX ,
1263+ Arc :: clone ( & logger) ,
1264+ ) ?;
1265+ lsps_xpriv. private_key . secret_bytes ( )
1266+ } ;
1267+ lsc. lsps2_service . as_ref ( ) . map ( |config| {
1268+ liquidity_source_builder. lsps2_service (
1269+ promise_secret,
1270+ config. token . clone ( ) ,
1271+ config. advertise_service ,
1272+ )
1273+ } ) ;
12161274
1217- let custom_message_handler = if let Some ( liquidity_source) = liquidity_source. as_ref ( ) {
1218- Arc :: new ( NodeCustomMessageHandler :: new_liquidity ( Arc :: clone ( & liquidity_source) ) )
1219- } else {
1220- Arc :: new ( NodeCustomMessageHandler :: new_ignoring ( ) )
1221- } ;
1275+ let liquidity_source = Arc :: new ( liquidity_source_builder. build ( ) ) ;
1276+ let custom_message_handler =
1277+ Arc :: new ( NodeCustomMessageHandler :: new_liquidity ( Arc :: clone ( & liquidity_source) ) ) ;
1278+ ( Some ( liquidity_source) , custom_message_handler)
1279+ } else {
1280+ ( None , Arc :: new ( NodeCustomMessageHandler :: new_ignoring ( ) ) )
1281+ } ;
12221282
12231283 let msg_handler = match gossip_source. as_gossip_sync ( ) {
12241284 GossipSync :: P2P ( p2p_gossip_sync) => MessageHandler {
0 commit comments