@@ -98,6 +98,11 @@ struct LiquiditySourceConfig {
9898 lsps2_service : Option < ( SocketAddress , PublicKey , Option < String > ) > ,
9999}
100100
101+ #[ derive( Debug , Clone ) ]
102+ struct PayjoinConfig {
103+ payjoin_relay : payjoin:: Url ,
104+ }
105+
101106impl Default for LiquiditySourceConfig {
102107 fn default ( ) -> Self {
103108 Self { lsps2_service : None }
@@ -139,6 +144,8 @@ pub enum BuildError {
139144 WalletSetupFailed ,
140145 /// We failed to setup the logger.
141146 LoggerSetupFailed ,
147+ /// Invalid Payjoin configuration.
148+ InvalidPayjoinConfig ,
142149}
143150
144151impl fmt:: Display for BuildError {
@@ -160,6 +167,10 @@ impl fmt::Display for BuildError {
160167 Self :: WalletSetupFailed => write ! ( f, "Failed to setup onchain wallet." ) ,
161168 Self :: LoggerSetupFailed => write ! ( f, "Failed to setup the logger." ) ,
162169 Self :: InvalidNodeAlias => write ! ( f, "Given node alias is invalid." ) ,
170+ Self :: InvalidPayjoinConfig => write ! (
171+ f,
172+ "Invalid Payjoin configuration. Make sure the provided arguments are valid URLs."
173+ ) ,
163174 }
164175 }
165176}
@@ -180,6 +191,7 @@ pub struct NodeBuilder {
180191 chain_data_source_config : Option < ChainDataSourceConfig > ,
181192 gossip_source_config : Option < GossipSourceConfig > ,
182193 liquidity_source_config : Option < LiquiditySourceConfig > ,
194+ payjoin_config : Option < PayjoinConfig > ,
183195}
184196
185197impl NodeBuilder {
@@ -195,12 +207,14 @@ impl NodeBuilder {
195207 let chain_data_source_config = None ;
196208 let gossip_source_config = None ;
197209 let liquidity_source_config = None ;
210+ let payjoin_config = None ;
198211 Self {
199212 config,
200213 entropy_source_config,
201214 chain_data_source_config,
202215 gossip_source_config,
203216 liquidity_source_config,
217+ payjoin_config,
204218 }
205219 }
206220
@@ -271,6 +285,14 @@ impl NodeBuilder {
271285 self
272286 }
273287
288+ /// Configures the [`Node`] instance to enable payjoin transactions.
289+ pub fn set_payjoin_config ( & mut self , payjoin_relay : String ) -> Result < & mut Self , BuildError > {
290+ let payjoin_relay =
291+ payjoin:: Url :: parse ( & payjoin_relay) . map_err ( |_| BuildError :: InvalidPayjoinConfig ) ?;
292+ self . payjoin_config = Some ( PayjoinConfig { payjoin_relay } ) ;
293+ Ok ( self )
294+ }
295+
274296 /// Configures the [`Node`] instance to source its inbound liquidity from the given
275297 /// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
276298 /// service.
@@ -478,6 +500,7 @@ impl NodeBuilder {
478500 self . chain_data_source_config . as_ref ( ) ,
479501 self . gossip_source_config . as_ref ( ) ,
480502 self . liquidity_source_config . as_ref ( ) ,
503+ self . payjoin_config . as_ref ( ) ,
481504 seed_bytes,
482505 logger,
483506 Arc :: new ( vss_store) ,
@@ -499,6 +522,7 @@ impl NodeBuilder {
499522 self . chain_data_source_config . as_ref ( ) ,
500523 self . gossip_source_config . as_ref ( ) ,
501524 self . liquidity_source_config . as_ref ( ) ,
525+ self . payjoin_config . as_ref ( ) ,
502526 seed_bytes,
503527 logger,
504528 kv_store,
@@ -584,6 +608,11 @@ impl ArcedNodeBuilder {
584608 self . inner . write ( ) . unwrap ( ) . set_gossip_source_p2p ( ) ;
585609 }
586610
611+ /// Configures the [`Node`] instance to enable payjoin transactions.
612+ pub fn set_payjoin_config ( & self , payjoin_relay : String ) -> Result < ( ) , BuildError > {
613+ self . inner . write ( ) . unwrap ( ) . set_payjoin_config ( payjoin_relay) . map ( |_| ( ) )
614+ }
615+
587616 /// Configures the [`Node`] instance to source its gossip data from the given RapidGossipSync
588617 /// server.
589618 pub fn set_gossip_source_rgs ( & self , rgs_server_url : String ) {
@@ -731,8 +760,9 @@ impl ArcedNodeBuilder {
731760fn build_with_store_internal (
732761 config : Arc < Config > , chain_data_source_config : Option < & ChainDataSourceConfig > ,
733762 gossip_source_config : Option < & GossipSourceConfig > ,
734- liquidity_source_config : Option < & LiquiditySourceConfig > , seed_bytes : [ u8 ; 64 ] ,
735- logger : Arc < FilesystemLogger > , kv_store : Arc < DynStore > ,
763+ liquidity_source_config : Option < & LiquiditySourceConfig > ,
764+ payjoin_config : Option < & PayjoinConfig > , seed_bytes : [ u8 ; 64 ] , logger : Arc < FilesystemLogger > ,
765+ kv_store : Arc < DynStore > ,
736766) -> Result < Node , BuildError > {
737767 // Initialize the status fields.
738768 let is_listening = Arc :: new ( AtomicBool :: new ( false ) ) ;
0 commit comments