Skip to content

Commit 98e0e6a

Browse files
chore: run cargo fmt
1 parent 38fce8e commit 98e0e6a

File tree

11 files changed

+196
-106
lines changed

11 files changed

+196
-106
lines changed

dash-spv/src/client/block_processor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl<W: WalletInterface + Send + Sync + 'static, S: StorageManager + Send + Sync
349349
stats.blocks_with_relevant_transactions += 1;
350350
}
351351
352-
tracing::info!("🚨 BLOCK MATCH DETECTED! Block {} at height {} contains {} transactions affecting watched addresses/scripts",
352+
tracing::info!("🚨 BLOCK MATCH DETECTED! Block {} at height {} contains {} transactions affecting watched addresses/scripts",
353353
block_hash, block_height, relevant_transactions);
354354
355355
// Report balance changes
@@ -433,7 +433,7 @@ impl<W: WalletInterface + Send + Sync + 'static, S: StorageManager + Send + Sync
433433
// Create and store UTXO if we have an address
434434
if let Some(address) = matched_address {
435435
let balance_impact = amount.to_sat() as i64;
436-
tracing::info!("💰 TX {} output {}:{} to {:?} (value: {}) - Address {} balance impact: +{}",
436+
tracing::info!("💰 TX {} output {}:{} to {:?} (value: {}) - Address {} balance impact: +{}",
437437
txid, txid, vout, watch_item, amount, address, balance_impact);
438438
439439
// WalletInterface doesn't have add_utxo method - this will be handled by process_block
@@ -444,7 +444,7 @@ impl<W: WalletInterface + Send + Sync + 'static, S: StorageManager + Send + Sync
444444
*balance_changes.entry(address.clone()).or_insert(0) += balance_impact;
445445
*tx_balance_changes.entry(address.clone()).or_insert(0) += balance_impact;
446446
} else {
447-
tracing::info!("💰 TX {} output {}:{} to {:?} (value: {}) - No address to track balance",
447+
tracing::info!("💰 TX {} output {}:{} to {:?} (value: {}) - No address to track balance",
448448
txid, txid, vout, watch_item, amount);
449449
}
450450

dash-spv/src/client/config.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub struct ClientConfig {
5353
/// Read timeout for TCP socket operations.
5454
pub read_timeout: Duration,
5555

56-
5756
/// Whether to enable filter syncing.
5857
pub enable_filters: bool,
5958

@@ -276,7 +275,6 @@ impl ClientConfig {
276275
self
277276
}
278277

279-
280278
/// Disable filters.
281279
pub fn without_filters(mut self) -> Self {
282280
self.enable_filters = false;

dash-spv/src/client/filter_sync.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! Filter synchronization and management for the Dash SPV client.
22
3-
use std::sync::Arc;
4-
use tokio::sync::RwLock;
5-
use key_wallet_manager::wallet_interface::WalletInterface;
63
use crate::error::{Result, SpvError};
74
use crate::network::NetworkManager;
85
use crate::storage::StorageManager;
96
use crate::sync::sequential::SequentialSyncManager;
10-
use crate::types::SpvStats;
117
use crate::types::FilterMatch;
8+
use crate::types::SpvStats;
9+
use key_wallet_manager::wallet_interface::WalletInterface;
10+
use std::sync::Arc;
11+
use tokio::sync::RwLock;
1212

1313
/// Filter synchronization manager for coordinating filter downloads and checking.
1414
pub struct FilterSyncCoordinator<'a, S: StorageManager, N: NetworkManager, W: WalletInterface> {
@@ -19,8 +19,12 @@ pub struct FilterSyncCoordinator<'a, S: StorageManager, N: NetworkManager, W: Wa
1919
running: &'a Arc<RwLock<bool>>,
2020
}
2121

22-
impl<'a, S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync + 'static, W: WalletInterface>
23-
FilterSyncCoordinator<'a, S, N, W>
22+
impl<
23+
'a,
24+
S: StorageManager + Send + Sync + 'static,
25+
N: NetworkManager + Send + Sync + 'static,
26+
W: WalletInterface,
27+
> FilterSyncCoordinator<'a, S, N, W>
2428
{
2529
/// Create a new filter sync coordinator.
2630
pub fn new(
@@ -143,5 +147,4 @@ impl<'a, S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + S
143147

144148
Ok(())
145149
}
146-
147150
}

dash-spv/src/client/message_handler.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! Network message handling for the Dash SPV client.
22
3-
use std::sync::Arc;
4-
use tokio::sync::RwLock;
5-
use key_wallet_manager::wallet_interface::WalletInterface;
63
use crate::client::ClientConfig;
74
use crate::error::{Result, SpvError};
85
use crate::mempool_filter::MempoolFilter;
96
use crate::network::NetworkManager;
107
use crate::storage::StorageManager;
118
use crate::sync::sequential::SequentialSyncManager;
129
use crate::types::{MempoolState, SpvEvent, SpvStats};
10+
use key_wallet_manager::wallet_interface::WalletInterface;
11+
use std::sync::Arc;
12+
use tokio::sync::RwLock;
1313

1414
/// Network message handler for processing incoming Dash protocol messages.
1515
pub struct MessageHandler<'a, S: StorageManager, N: NetworkManager, W: WalletInterface> {
@@ -24,8 +24,12 @@ pub struct MessageHandler<'a, S: StorageManager, N: NetworkManager, W: WalletInt
2424
event_tx: &'a tokio::sync::mpsc::UnboundedSender<SpvEvent>,
2525
}
2626

27-
impl<'a, S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync + 'static, W: WalletInterface>
28-
MessageHandler<'a, S, N, W>
27+
impl<
28+
'a,
29+
S: StorageManager + Send + Sync + 'static,
30+
N: NetworkManager + Send + Sync + 'static,
31+
W: WalletInterface,
32+
> MessageHandler<'a, S, N, W>
2933
{
3034
/// Create a new message handler.
3135
pub fn new(

dash-spv/src/client/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ impl<
135135
)
136136
}
137137

138-
139138
/// Helper to process balance changes with error handling.
140139
async fn process_address_balance<T, F>(
141140
&self,
@@ -210,7 +209,8 @@ impl<
210209
let received_filter_heights = stats.read().await.received_filter_heights.clone();
211210
tracing::info!("Creating sequential sync manager");
212211
let mut sync_manager =
213-
SequentialSyncManager::new(&config, received_filter_heights, wallet.clone()).map_err(SpvError::Sync)?;
212+
SequentialSyncManager::new(&config, received_filter_heights, wallet.clone())
213+
.map_err(SpvError::Sync)?;
214214

215215
// Create validation manager
216216
let validation = ValidationManager::new(config.validation_mode);
@@ -2325,7 +2325,6 @@ impl<
23252325
Ok(())
23262326
}
23272327

2328-
23292328
/// Load wallet data from storage.
23302329
async fn load_wallet_data(&self) -> Result<()> {
23312330
tracing::info!("Loading wallet data from storage...");
@@ -2402,9 +2401,6 @@ impl<
24022401
#[cfg(test)]
24032402
mod config_test;
24042403

2405-
#[cfg(test)]
2406-
mod watch_manager_test;
2407-
24082404
#[cfg(test)]
24092405
mod block_processor_test;
24102406

dash-spv/src/client/status_display.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
8787

8888
// Get filter header height from storage
8989
let storage = self.storage.lock().await;
90-
let filter_header_height = storage.get_filter_tip_height().await
91-
.ok().flatten().unwrap_or(0);
90+
let filter_header_height =
91+
storage.get_filter_tip_height().await.ok().flatten().unwrap_or(0);
9292
drop(storage);
9393

9494
Ok(SyncProgress {
@@ -130,8 +130,7 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
130130

131131
// Get filter header height from storage
132132
let storage = self.storage.lock().await;
133-
let filter_height = storage.get_filter_tip_height().await
134-
.ok().flatten().unwrap_or(0);
133+
let filter_height = storage.get_filter_tip_height().await.ok().flatten().unwrap_or(0);
135134
drop(storage);
136135

137136
// Get latest chainlock height from state
@@ -182,8 +181,7 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
182181

183182
// Get filter header height from storage
184183
let storage = self.storage.lock().await;
185-
let filter_height = storage.get_filter_tip_height().await
186-
.ok().flatten().unwrap_or(0);
184+
let filter_height = storage.get_filter_tip_height().await.ok().flatten().unwrap_or(0);
187185
drop(storage);
188186

189187
let chainlock_height = {
@@ -213,5 +211,4 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
213211
);
214212
}
215213
}
216-
217214
}

dash-spv/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ pub mod validation;
7474
// Re-export main types for convenience
7575
pub use client::{ClientConfig, DashSpvClient};
7676
pub use error::{NetworkError, SpvError, StorageError, SyncError, ValidationError};
77-
pub use types::{
78-
ChainState, FilterMatch, PeerInfo, SpvStats, SyncProgress, ValidationMode,
79-
};
77+
pub use types::{ChainState, FilterMatch, PeerInfo, SpvStats, SyncProgress, ValidationMode};
8078

8179
// Re-export commonly used dashcore types
8280
pub use dashcore::{Address, BlockHash, Network, OutPoint, QuorumHash, ScriptBuf};

dash-spv/src/main.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,20 @@ async fn run_client<S: dash_spv::storage::StorageManager + Send + Sync + 'static
310310
matches: &clap::ArgMatches,
311311
) -> Result<(), Box<dyn std::error::Error>> {
312312
// Create and start the client
313-
let mut client = match DashSpvClient::<
314-
key_wallet_manager::spv_wallet_manager::SPVWalletManager,
315-
dash_spv::network::multi_peer::MultiPeerNetworkManager,
316-
S,
317-
>::new(config.clone(), network_manager, storage_manager, wallet.clone())
318-
.await
319-
{
320-
Ok(client) => client,
321-
Err(e) => {
322-
eprintln!("Failed to create SPV client: {}", e);
323-
process::exit(1);
324-
}
325-
};
313+
let mut client =
314+
match DashSpvClient::<
315+
key_wallet_manager::spv_wallet_manager::SPVWalletManager,
316+
dash_spv::network::multi_peer::MultiPeerNetworkManager,
317+
S,
318+
>::new(config.clone(), network_manager, storage_manager, wallet.clone())
319+
.await
320+
{
321+
Ok(client) => client,
322+
Err(e) => {
323+
eprintln!("Failed to create SPV client: {}", e);
324+
process::exit(1);
325+
}
326+
};
326327

327328
// Enable terminal UI in the client if requested
328329
let _terminal_guard = if enable_terminal_ui {
@@ -375,7 +376,10 @@ async fn run_client<S: dash_spv::storage::StorageManager + Send + Sync + 'static
375376
Ok(valid_addr) => {
376377
// TODO: Add address to wallet for monitoring
377378
// For now, just log that we would watch this address
378-
tracing::info!("Would watch address: {} (wallet integration pending)", valid_addr);
379+
tracing::info!(
380+
"Would watch address: {} (wallet integration pending)",
381+
valid_addr
382+
);
379383
}
380384
Err(e) => {
381385
tracing::error!("Invalid address for network: {}", e);

dash-spv/src/storage/disk.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ impl DiskStorageManager {
284284
tracing::info!("Index file not found, rebuilding from segments...");
285285

286286
// Load chain state to get sync_base_height for proper height calculation
287-
let sync_base_height = if let Ok(Some(chain_state)) = self.load_chain_state().await {
287+
let sync_base_height = if let Ok(Some(chain_state)) = self.load_chain_state().await
288+
{
288289
chain_state.sync_base_height
289290
} else {
290291
0 // Assume genesis sync if no chain state
@@ -1200,8 +1201,11 @@ impl StorageManager for DiskStorageManager {
12001201
next_blockchain_height - sync_base_height
12011202
} else {
12021203
// This shouldn't happen in normal operation
1203-
tracing::warn!("Attempting to store filter header at height {} below sync_base_height {}",
1204-
next_blockchain_height, sync_base_height);
1204+
tracing::warn!(
1205+
"Attempting to store filter header at height {} below sync_base_height {}",
1206+
next_blockchain_height,
1207+
sync_base_height
1208+
);
12051209
next_blockchain_height
12061210
}
12071211
} else {
@@ -1296,7 +1300,10 @@ impl StorageManager for DiskStorageManager {
12961300
Ok(filter_headers)
12971301
}
12981302

1299-
async fn get_filter_header(&self, blockchain_height: u32) -> StorageResult<Option<FilterHeader>> {
1303+
async fn get_filter_header(
1304+
&self,
1305+
blockchain_height: u32,
1306+
) -> StorageResult<Option<FilterHeader>> {
13001307
let sync_base_height = *self.sync_base_height.read().await;
13011308

13021309
// Convert blockchain height to storage index
@@ -1306,8 +1313,11 @@ impl StorageManager for DiskStorageManager {
13061313
blockchain_height - sync_base_height
13071314
} else {
13081315
// This shouldn't happen in normal operation, but handle it gracefully
1309-
tracing::warn!("Attempting to get filter header at height {} below sync_base_height {}",
1310-
blockchain_height, sync_base_height);
1316+
tracing::warn!(
1317+
"Attempting to get filter header at height {} below sync_base_height {}",
1318+
blockchain_height,
1319+
sync_base_height
1320+
);
13111321
return Ok(None);
13121322
}
13131323
} else {
@@ -1904,8 +1914,8 @@ mod tests {
19041914
#[tokio::test]
19051915
async fn test_checkpoint_storage_indexing() -> StorageResult<()> {
19061916
use crate::types::ChainState;
1907-
use tempfile::tempdir;
19081917
use dashcore::TxMerkleNode;
1918+
use tempfile::tempdir;
19091919

19101920
let temp_dir = tempdir().expect("Failed to create temp dir");
19111921
let mut storage = DiskStorageManager::new(temp_dir.path().to_path_buf()).await?;
@@ -1940,11 +1950,19 @@ mod tests {
19401950
// Test the reverse index (hash -> blockchain height)
19411951
let hash_0 = headers[0].block_hash();
19421952
let height_0 = storage.get_header_height_by_hash(&hash_0).await?;
1943-
assert_eq!(height_0, Some(checkpoint_height), "Hash should map to blockchain height 1,100,000");
1953+
assert_eq!(
1954+
height_0,
1955+
Some(checkpoint_height),
1956+
"Hash should map to blockchain height 1,100,000"
1957+
);
19441958

19451959
let hash_99 = headers[99].block_hash();
19461960
let height_99 = storage.get_header_height_by_hash(&hash_99).await?;
1947-
assert_eq!(height_99, Some(checkpoint_height + 99), "Hash should map to blockchain height 1,100,099");
1961+
assert_eq!(
1962+
height_99,
1963+
Some(checkpoint_height + 99),
1964+
"Hash should map to blockchain height 1,100,099"
1965+
);
19481966

19491967
// Store chain state to persist sync_base_height
19501968
let mut chain_state = ChainState::new();
@@ -1961,12 +1979,18 @@ mod tests {
19611979

19621980
// Verify the index was rebuilt correctly
19631981
let height_after_rebuild = storage2.get_header_height_by_hash(&hash_0).await?;
1964-
assert_eq!(height_after_rebuild, Some(checkpoint_height),
1965-
"After index rebuild, hash should still map to blockchain height 1,100,000");
1982+
assert_eq!(
1983+
height_after_rebuild,
1984+
Some(checkpoint_height),
1985+
"After index rebuild, hash should still map to blockchain height 1,100,000"
1986+
);
19661987

19671988
// Verify headers can still be retrieved by storage index
19681989
let header_after_reload = storage2.get_header(0).await?;
1969-
assert!(header_after_reload.is_some(), "Header at storage index 0 should exist after reload");
1990+
assert!(
1991+
header_after_reload.is_some(),
1992+
"Header at storage index 0 should exist after reload"
1993+
);
19701994
assert_eq!(header_after_reload.unwrap(), headers[0]);
19711995

19721996
Ok(())

0 commit comments

Comments
 (0)