nwc/
options.rs

1// Copyright (c) 2022-2023 Yuki Kishimoto
2// Copyright (c) 2023-2025 Rust Nostr Developers
3// Distributed under the MIT software license
4
5//! NWC Options
6
7use std::time::Duration;
8
9use nostr_relay_pool::monitor::Monitor;
10use nostr_relay_pool::{ConnectionMode, RelayOptions};
11
12/// Default timeout
13pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60);
14
15/// NWC options
16#[derive(Debug, Clone)]
17pub struct NostrWalletConnectOptions {
18    pub(super) relay: RelayOptions,
19    pub(super) timeout: Duration,
20    pub(super) monitor: Option<Monitor>,
21}
22
23impl Default for NostrWalletConnectOptions {
24    fn default() -> Self {
25        Self {
26            relay: RelayOptions::default(),
27            timeout: DEFAULT_TIMEOUT,
28            monitor: None,
29        }
30    }
31}
32
33impl NostrWalletConnectOptions {
34    /// New default NWC options
35    #[inline]
36    pub fn new() -> Self {
37        Self::default()
38    }
39
40    /// Set connection mode
41    #[deprecated(
42        since = "0.43.0",
43        note = "Use `NostrWalletConnectOptions::relay` instead"
44    )]
45    pub fn connection_mode(self, mode: ConnectionMode) -> Self {
46        Self {
47            relay: self.relay.connection_mode(mode),
48            ..self
49        }
50    }
51
52    /// Set NWC requests timeout (default: [`DEFAULT_TIMEOUT`])
53    #[inline]
54    pub fn timeout(mut self, timeout: Duration) -> Self {
55        self.timeout = timeout;
56        self
57    }
58
59    /// Set Relay Pool monitor
60    #[inline]
61    pub fn monitor(mut self, monitor: Monitor) -> Self {
62        self.monitor = Some(monitor);
63        self
64    }
65
66    /// Set relay options
67    pub fn relay(self, opts: RelayOptions) -> Self {
68        Self {
69            relay: opts,
70            ..self
71        }
72    }
73}