@@ -91,6 +91,11 @@ struct LiquiditySourceConfig {
9191 lsps2_service : Option < ( SocketAddress , PublicKey , Option < String > ) > ,
9292}
9393
94+ #[ derive( Debug , Clone ) ]
95+ struct PayjoinConfig {
96+ payjoin_relay : payjoin:: Url ,
97+ }
98+
9499impl Default for LiquiditySourceConfig {
95100 fn default ( ) -> Self {
96101 Self { lsps2_service : None }
@@ -130,6 +135,8 @@ pub enum BuildError {
130135 WalletSetupFailed ,
131136 /// We failed to setup the logger.
132137 LoggerSetupFailed ,
138+ /// Invalid Payjoin configuration.
139+ InvalidPayjoinConfig ,
133140}
134141
135142impl fmt:: Display for BuildError {
@@ -150,6 +157,10 @@ impl fmt::Display for BuildError {
150157 Self :: KVStoreSetupFailed => write ! ( f, "Failed to setup KVStore." ) ,
151158 Self :: WalletSetupFailed => write ! ( f, "Failed to setup onchain wallet." ) ,
152159 Self :: LoggerSetupFailed => write ! ( f, "Failed to setup the logger." ) ,
160+ Self :: InvalidPayjoinConfig => write ! (
161+ f,
162+ "Invalid Payjoin configuration. Make sure the provided arguments are valid URLs."
163+ ) ,
153164 }
154165 }
155166}
@@ -170,6 +181,7 @@ pub struct NodeBuilder {
170181 chain_data_source_config : Option < ChainDataSourceConfig > ,
171182 gossip_source_config : Option < GossipSourceConfig > ,
172183 liquidity_source_config : Option < LiquiditySourceConfig > ,
184+ payjoin_config : Option < PayjoinConfig > ,
173185}
174186
175187impl NodeBuilder {
@@ -185,12 +197,14 @@ impl NodeBuilder {
185197 let chain_data_source_config = None ;
186198 let gossip_source_config = None ;
187199 let liquidity_source_config = None ;
200+ let payjoin_config = None ;
188201 Self {
189202 config,
190203 entropy_source_config,
191204 chain_data_source_config,
192205 gossip_source_config,
193206 liquidity_source_config,
207+ payjoin_config,
194208 }
195209 }
196210
@@ -245,6 +259,14 @@ impl NodeBuilder {
245259 self
246260 }
247261
262+ /// Configures the [`Node`] instance to enable payjoin transactions.
263+ pub fn set_payjoin_config ( & mut self , payjoin_relay : String ) -> Result < & mut Self , BuildError > {
264+ let payjoin_relay =
265+ payjoin:: Url :: parse ( & payjoin_relay) . map_err ( |_| BuildError :: InvalidPayjoinConfig ) ?;
266+ self . payjoin_config = Some ( PayjoinConfig { payjoin_relay } ) ;
267+ Ok ( self )
268+ }
269+
248270 /// Configures the [`Node`] instance to source its inbound liquidity from the given
249271 /// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
250272 /// service.
@@ -363,6 +385,7 @@ impl NodeBuilder {
363385 self . chain_data_source_config . as_ref ( ) ,
364386 self . gossip_source_config . as_ref ( ) ,
365387 self . liquidity_source_config . as_ref ( ) ,
388+ self . payjoin_config . as_ref ( ) ,
366389 seed_bytes,
367390 logger,
368391 vss_store,
@@ -384,6 +407,7 @@ impl NodeBuilder {
384407 self . chain_data_source_config . as_ref ( ) ,
385408 self . gossip_source_config . as_ref ( ) ,
386409 self . liquidity_source_config . as_ref ( ) ,
410+ self . payjoin_config . as_ref ( ) ,
387411 seed_bytes,
388412 logger,
389413 kv_store,
@@ -451,6 +475,11 @@ impl ArcedNodeBuilder {
451475 self . inner . write ( ) . unwrap ( ) . set_gossip_source_p2p ( ) ;
452476 }
453477
478+ /// Configures the [`Node`] instance to enable payjoin transactions.
479+ pub fn set_payjoin_config ( & self , payjoin_relay : String ) -> Result < ( ) , BuildError > {
480+ self . inner . write ( ) . unwrap ( ) . set_payjoin_config ( payjoin_relay) . map ( |_| ( ) )
481+ }
482+
454483 /// Configures the [`Node`] instance to source its gossip data from the given RapidGossipSync
455484 /// server.
456485 pub fn set_gossip_source_rgs ( & self , rgs_server_url : String ) {
@@ -519,8 +548,9 @@ impl ArcedNodeBuilder {
519548fn build_with_store_internal (
520549 config : Arc < Config > , chain_data_source_config : Option < & ChainDataSourceConfig > ,
521550 gossip_source_config : Option < & GossipSourceConfig > ,
522- liquidity_source_config : Option < & LiquiditySourceConfig > , seed_bytes : [ u8 ; 64 ] ,
523- logger : Arc < FilesystemLogger > , kv_store : Arc < DynStore > ,
551+ liquidity_source_config : Option < & LiquiditySourceConfig > ,
552+ payjoin_config : Option < & PayjoinConfig > , seed_bytes : [ u8 ; 64 ] , logger : Arc < FilesystemLogger > ,
553+ kv_store : Arc < DynStore > ,
524554) -> Result < Node , BuildError > {
525555 // Initialize the on-chain wallet and chain access
526556 let xprv = bitcoin:: bip32:: ExtendedPrivKey :: new_master ( config. network . into ( ) , & seed_bytes)
0 commit comments