@@ -91,6 +91,11 @@ struct LiquiditySourceConfig {
91
91
lsps2_service : Option < ( SocketAddress , PublicKey , Option < String > ) > ,
92
92
}
93
93
94
+ #[ derive( Debug , Clone ) ]
95
+ struct PayjoinConfig {
96
+ payjoin_relay : payjoin:: Url ,
97
+ }
98
+
94
99
impl Default for LiquiditySourceConfig {
95
100
fn default ( ) -> Self {
96
101
Self { lsps2_service : None }
@@ -130,6 +135,8 @@ pub enum BuildError {
130
135
WalletSetupFailed ,
131
136
/// We failed to setup the logger.
132
137
LoggerSetupFailed ,
138
+ /// Invalid Payjoin configuration.
139
+ InvalidPayjoinConfig ,
133
140
}
134
141
135
142
impl fmt:: Display for BuildError {
@@ -150,6 +157,10 @@ impl fmt::Display for BuildError {
150
157
Self :: KVStoreSetupFailed => write ! ( f, "Failed to setup KVStore." ) ,
151
158
Self :: WalletSetupFailed => write ! ( f, "Failed to setup onchain wallet." ) ,
152
159
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
+ ) ,
153
164
}
154
165
}
155
166
}
@@ -170,6 +181,7 @@ pub struct NodeBuilder {
170
181
chain_data_source_config : Option < ChainDataSourceConfig > ,
171
182
gossip_source_config : Option < GossipSourceConfig > ,
172
183
liquidity_source_config : Option < LiquiditySourceConfig > ,
184
+ payjoin_config : Option < PayjoinConfig > ,
173
185
}
174
186
175
187
impl NodeBuilder {
@@ -185,12 +197,14 @@ impl NodeBuilder {
185
197
let chain_data_source_config = None ;
186
198
let gossip_source_config = None ;
187
199
let liquidity_source_config = None ;
200
+ let payjoin_config = None ;
188
201
Self {
189
202
config,
190
203
entropy_source_config,
191
204
chain_data_source_config,
192
205
gossip_source_config,
193
206
liquidity_source_config,
207
+ payjoin_config,
194
208
}
195
209
}
196
210
@@ -245,6 +259,14 @@ impl NodeBuilder {
245
259
self
246
260
}
247
261
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
+
248
270
/// Configures the [`Node`] instance to source its inbound liquidity from the given
249
271
/// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
250
272
/// service.
@@ -363,6 +385,7 @@ impl NodeBuilder {
363
385
self . chain_data_source_config . as_ref ( ) ,
364
386
self . gossip_source_config . as_ref ( ) ,
365
387
self . liquidity_source_config . as_ref ( ) ,
388
+ self . payjoin_config . as_ref ( ) ,
366
389
seed_bytes,
367
390
logger,
368
391
vss_store,
@@ -384,6 +407,7 @@ impl NodeBuilder {
384
407
self . chain_data_source_config . as_ref ( ) ,
385
408
self . gossip_source_config . as_ref ( ) ,
386
409
self . liquidity_source_config . as_ref ( ) ,
410
+ self . payjoin_config . as_ref ( ) ,
387
411
seed_bytes,
388
412
logger,
389
413
kv_store,
@@ -451,6 +475,11 @@ impl ArcedNodeBuilder {
451
475
self . inner . write ( ) . unwrap ( ) . set_gossip_source_p2p ( ) ;
452
476
}
453
477
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
+
454
483
/// Configures the [`Node`] instance to source its gossip data from the given RapidGossipSync
455
484
/// server.
456
485
pub fn set_gossip_source_rgs ( & self , rgs_server_url : String ) {
@@ -519,8 +548,9 @@ impl ArcedNodeBuilder {
519
548
fn build_with_store_internal (
520
549
config : Arc < Config > , chain_data_source_config : Option < & ChainDataSourceConfig > ,
521
550
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 > ,
524
554
) -> Result < Node , BuildError > {
525
555
// Initialize the on-chain wallet and chain access
526
556
let xprv = bitcoin:: bip32:: ExtendedPrivKey :: new_master ( config. network . into ( ) , & seed_bytes)
0 commit comments