Skip to content

Commit ce87a44

Browse files
committed
Add NodeBuilder::PayjoinConfig to allow ..
Payjoin transactions
1 parent 9dec96d commit ce87a44

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/builder.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ struct LiquiditySourceConfig {
100100
lsps2_service: Option<(SocketAddress, PublicKey, Option<String>)>,
101101
}
102102

103+
#[derive(Debug, Clone)]
104+
struct PayjoinConfig {
105+
payjoin_relay: payjoin::Url,
106+
}
107+
103108
impl Default for LiquiditySourceConfig {
104109
fn default() -> Self {
105110
Self { lsps2_service: None }
@@ -141,6 +146,8 @@ pub enum BuildError {
141146
WalletSetupFailed,
142147
/// We failed to setup the logger.
143148
LoggerSetupFailed,
149+
/// Invalid Payjoin configuration.
150+
InvalidPayjoinConfig,
144151
}
145152

146153
impl fmt::Display for BuildError {
@@ -162,6 +169,10 @@ impl fmt::Display for BuildError {
162169
Self::WalletSetupFailed => write!(f, "Failed to setup onchain wallet."),
163170
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
164171
Self::InvalidNodeAlias => write!(f, "Given node alias is invalid."),
172+
Self::InvalidPayjoinConfig => write!(
173+
f,
174+
"Invalid Payjoin configuration. Make sure the provided arguments are valid URLs."
175+
),
165176
}
166177
}
167178
}
@@ -182,6 +193,7 @@ pub struct NodeBuilder {
182193
chain_data_source_config: Option<ChainDataSourceConfig>,
183194
gossip_source_config: Option<GossipSourceConfig>,
184195
liquidity_source_config: Option<LiquiditySourceConfig>,
196+
payjoin_config: Option<PayjoinConfig>,
185197
}
186198

187199
impl NodeBuilder {
@@ -197,12 +209,14 @@ impl NodeBuilder {
197209
let chain_data_source_config = None;
198210
let gossip_source_config = None;
199211
let liquidity_source_config = None;
212+
let payjoin_config = None;
200213
Self {
201214
config,
202215
entropy_source_config,
203216
chain_data_source_config,
204217
gossip_source_config,
205218
liquidity_source_config,
219+
payjoin_config,
206220
}
207221
}
208222

@@ -273,6 +287,14 @@ impl NodeBuilder {
273287
self
274288
}
275289

290+
/// Configures the [`Node`] instance to enable payjoin transactions.
291+
pub fn set_payjoin_config(&mut self, payjoin_relay: String) -> Result<&mut Self, BuildError> {
292+
let payjoin_relay =
293+
payjoin::Url::parse(&payjoin_relay).map_err(|_| BuildError::InvalidPayjoinConfig)?;
294+
self.payjoin_config = Some(PayjoinConfig { payjoin_relay });
295+
Ok(self)
296+
}
297+
276298
/// Configures the [`Node`] instance to source its inbound liquidity from the given
277299
/// [LSPS2](https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md)
278300
/// service.
@@ -480,6 +502,7 @@ impl NodeBuilder {
480502
self.chain_data_source_config.as_ref(),
481503
self.gossip_source_config.as_ref(),
482504
self.liquidity_source_config.as_ref(),
505+
self.payjoin_config.as_ref(),
483506
seed_bytes,
484507
logger,
485508
Arc::new(vss_store),
@@ -501,6 +524,7 @@ impl NodeBuilder {
501524
self.chain_data_source_config.as_ref(),
502525
self.gossip_source_config.as_ref(),
503526
self.liquidity_source_config.as_ref(),
527+
self.payjoin_config.as_ref(),
504528
seed_bytes,
505529
logger,
506530
kv_store,
@@ -586,6 +610,11 @@ impl ArcedNodeBuilder {
586610
self.inner.write().unwrap().set_gossip_source_p2p();
587611
}
588612

613+
/// Configures the [`Node`] instance to enable payjoin transactions.
614+
pub fn set_payjoin_config(&self, payjoin_relay: String) -> Result<(), BuildError> {
615+
self.inner.write().unwrap().set_payjoin_config(payjoin_relay).map(|_| ())
616+
}
617+
589618
/// Configures the [`Node`] instance to source its gossip data from the given RapidGossipSync
590619
/// server.
591620
pub fn set_gossip_source_rgs(&self, rgs_server_url: String) {
@@ -733,8 +762,9 @@ impl ArcedNodeBuilder {
733762
fn build_with_store_internal(
734763
config: Arc<Config>, chain_data_source_config: Option<&ChainDataSourceConfig>,
735764
gossip_source_config: Option<&GossipSourceConfig>,
736-
liquidity_source_config: Option<&LiquiditySourceConfig>, seed_bytes: [u8; 64],
737-
logger: Arc<FilesystemLogger>, kv_store: Arc<DynStore>,
765+
liquidity_source_config: Option<&LiquiditySourceConfig>,
766+
payjoin_config: Option<&PayjoinConfig>, seed_bytes: [u8; 64], logger: Arc<FilesystemLogger>,
767+
kv_store: Arc<DynStore>,
738768
) -> Result<Node, BuildError> {
739769
// Initialize the status fields.
740770
let is_listening = Arc::new(AtomicBool::new(false));

0 commit comments

Comments
 (0)