Skip to content

Commit 9f67e64

Browse files
committed
fix: Let the examples start the network monitoring
1 parent a605406 commit 9f67e64

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

dash-spv/examples/filter_sync.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
88
use key_wallet_manager::wallet_manager::WalletManager;
99
use std::str::FromStr;
1010
use std::sync::Arc;
11+
use tokio::signal;
1112
use tokio::sync::RwLock;
1213

1314
#[tokio::main]
@@ -44,7 +45,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4445
// Full sync including filters
4546
let progress = client.sync_to_tip().await?;
4647

47-
println!("Synchronization completed!");
48+
tokio::select! {
49+
result = client.monitor_network() => {
50+
println!("monitor_network result {:?}", result);
51+
},
52+
_ = signal::ctrl_c() => {
53+
println!("monitor_network canceled");
54+
}
55+
}
56+
4857
println!("Headers synced: {}", progress.header_height);
4958
println!("Filter headers synced: {}", progress.filter_header_height);
5059

dash-spv/examples/simple_sync.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
77

88
use key_wallet_manager::wallet_manager::WalletManager;
99
use std::sync::Arc;
10+
use tokio::signal;
1011
use tokio::sync::RwLock;
1112

1213
#[tokio::main]
@@ -47,6 +48,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4748
println!("Headers downloaded: {}", stats.headers_downloaded);
4849
println!("Bytes received: {}", stats.bytes_received);
4950

51+
tokio::select! {
52+
result = client.monitor_network() => {
53+
println!("monitor_network result {:?}", result);
54+
},
55+
_ = signal::ctrl_c() => {
56+
println!("monitor_network canceled");
57+
}
58+
}
59+
5060
// Stop the client
5161
client.stop().await?;
5262

dash-spv/examples/spv_with_wallet.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use dash_spv::{ClientConfig, DashSpvClient};
88
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
99
use key_wallet_manager::wallet_manager::WalletManager;
1010
use std::sync::Arc;
11+
use tokio::signal;
1112
use tokio::sync::RwLock;
1213

1314
#[tokio::main]
@@ -47,6 +48,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4748
// - Mempool transactions via process_mempool_transaction()
4849
// - Reorgs via handle_reorg()
4950
// - Compact filter checks via check_compact_filter()
51+
tokio::select! {
52+
result = client.monitor_network() => {
53+
println!("monitor_network result {:?}", result);
54+
},
55+
_ = signal::ctrl_c() => {
56+
println!("monitor_network canceled");
57+
}
58+
}
5059

5160
// Stop the client
5261
println!("Stopping SPV client...");

0 commit comments

Comments
 (0)