File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 28
28
### Added
29
29
30
30
- Add notification support for real-time payment updates (https://github.com/rust-nostr/nostr/pull/953 )
31
+ - Add Monitor to NostrWalletConnectOptions (https://github.com/rust-nostr/nostr/pull/989 )
31
32
32
33
## v0.42.0 - 2025/05/20
33
34
Original file line number Diff line number Diff line change @@ -20,7 +20,18 @@ async fn main() -> Result<()> {
20
20
// Parse URI and compose NWC client
21
21
let uri: NostrWalletConnectURI =
22
22
NostrWalletConnectURI :: from_str ( & nwc_uri_string) . expect ( "Failed to parse NWC URI" ) ;
23
- let nwc: NWC = NWC :: new ( uri) ;
23
+
24
+ // Create monitor and subscribe to it
25
+ let monitor = Monitor :: new ( 100 ) ;
26
+ let mut monitor_sub = monitor. subscribe ( ) ;
27
+ tokio:: spawn ( async move {
28
+ while let Ok ( notification) = monitor_sub. recv ( ) . await {
29
+ println ! ( "Notification: {notification:?}" ) ;
30
+ }
31
+ } ) ;
32
+
33
+ // Create NWC client with monitor
34
+ let nwc: NWC = NWC :: with_opts ( uri, NostrWalletConnectOptions :: default ( ) . monitor ( monitor) ) ;
24
35
25
36
// Get balance
26
37
let balance = nwc. get_balance ( ) . await ?;
Original file line number Diff line number Diff line change @@ -53,9 +53,14 @@ impl NWC {
53
53
54
54
/// New `NWC` client with custom [`NostrWalletConnectOptions`].
55
55
pub fn with_opts ( uri : NostrWalletConnectURI , opts : NostrWalletConnectOptions ) -> Self {
56
+ let pool = match opts. monitor . as_ref ( ) {
57
+ Some ( monitor) => RelayPool :: builder ( ) . monitor ( monitor. clone ( ) ) . build ( ) ,
58
+ None => RelayPool :: default ( ) ,
59
+ } ;
60
+
56
61
Self {
57
62
uri,
58
- pool : RelayPool :: default ( ) ,
63
+ pool,
59
64
opts,
60
65
bootstrapped : Arc :: new ( AtomicBool :: new ( false ) ) ,
61
66
notifications_subscribed : Arc :: new ( AtomicBool :: new ( false ) ) ,
Original file line number Diff line number Diff line change 6
6
7
7
use std:: time:: Duration ;
8
8
9
+ use nostr_relay_pool:: monitor:: Monitor ;
9
10
use nostr_relay_pool:: { ConnectionMode , RelayOptions } ;
10
11
11
12
/// Default timeout
@@ -16,13 +17,15 @@ pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60);
16
17
pub struct NostrWalletConnectOptions {
17
18
pub ( super ) relay : RelayOptions ,
18
19
pub ( super ) timeout : Duration ,
20
+ pub ( super ) monitor : Option < Monitor > ,
19
21
}
20
22
21
23
impl Default for NostrWalletConnectOptions {
22
24
fn default ( ) -> Self {
23
25
Self {
24
26
relay : RelayOptions :: default ( ) ,
25
27
timeout : DEFAULT_TIMEOUT ,
28
+ monitor : None ,
26
29
}
27
30
}
28
31
}
@@ -48,4 +51,11 @@ impl NostrWalletConnectOptions {
48
51
self . timeout = timeout;
49
52
self
50
53
}
54
+
55
+ /// Set Relay Pool monitor
56
+ #[ inline]
57
+ pub fn monitor ( mut self , monitor : Monitor ) -> Self {
58
+ self . monitor = Some ( monitor) ;
59
+ self
60
+ }
51
61
}
You can’t perform that action at this time.
0 commit comments