Skip to content

Commit a81fa26

Browse files
fix(dash-spv): update ClientConfig and tests after watch API removal; adjust BlockProcessor and sync_manager generics; fix example to compile; all tests green (#117)
* fix(dash-spv): update ClientConfig and tests after watch API removal; adjust BlockProcessor and sync_manager generics; fix example to compile; all tests green * chore: run cargo fmt
1 parent 674325e commit a81fa26

File tree

7 files changed

+7
-43
lines changed

7 files changed

+7
-43
lines changed

dash-spv/examples/filter_sync.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2222
)?;
2323

2424
// Create configuration with filter support
25-
let config = ClientConfig::mainnet()
26-
.watch_address(watch_address.clone().require_network(Network::Dash).unwrap())
27-
.without_masternodes(); // Skip masternode sync for this example
25+
let config = ClientConfig::mainnet().without_masternodes(); // Skip masternode sync for this example
2826

2927
// Create network manager
3028
let network_manager = MultiPeerNetworkManager::new(&config).await?;

dash-spv/src/client/block_processor_test.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,10 @@ mod tests {
8585
let stats = Arc::new(RwLock::new(SpvStats::default()));
8686
let wallet = Arc::new(RwLock::new(MockWallet::new(Network::Dash)));
8787
let storage = Arc::new(Mutex::new(MemoryStorageManager::new().await.unwrap()));
88-
let watch_items = Arc::new(RwLock::new(HashSet::new()));
89-
9088
let processor = BlockProcessor::new(
9189
task_rx,
9290
wallet.clone(),
9391
storage.clone(),
94-
watch_items,
9592
stats,
9693
event_tx,
9794
Network::Dash,
@@ -265,17 +262,9 @@ mod tests {
265262
network: Network::Dash,
266263
}));
267264
let storage = Arc::new(Mutex::new(MemoryStorageManager::new().await.unwrap()));
268-
let watch_items = Arc::new(RwLock::new(HashSet::new()));
269265

270-
let processor = BlockProcessor::new(
271-
task_rx,
272-
wallet,
273-
storage,
274-
watch_items,
275-
stats,
276-
event_tx,
277-
Network::Dash,
278-
);
266+
let processor =
267+
BlockProcessor::new(task_rx, wallet, storage, stats, event_tx, Network::Dash);
279268

280269
let block_hash = create_test_block(Network::Dash).block_hash();
281270
let filter_data = vec![1, 2, 3, 4, 5];

dash-spv/src/client/config_test.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ mod tests {
2323
assert_eq!(config.message_timeout, Duration::from_secs(60));
2424
assert_eq!(config.sync_timeout, Duration::from_secs(300));
2525
assert_eq!(config.read_timeout, Duration::from_millis(100));
26-
assert!(config.watch_items.is_empty());
2726
assert!(config.enable_filters);
2827
assert!(config.enable_masternodes);
2928
assert_eq!(config.max_peers, 8);
@@ -114,23 +113,6 @@ mod tests {
114113
assert_eq!(config.peers[1], addr2);
115114
}
116115

117-
#[test]
118-
fn test_watch_items() {
119-
let mut config = ClientConfig::default();
120-
121-
// Create a dummy P2PKH address for testing
122-
use dashcore::hashes::Hash;
123-
let pubkey_hash = dashcore::PubkeyHash::from_byte_array([0u8; 20]);
124-
let address =
125-
Address::new(Network::Testnet, dashcore::address::Payload::PubkeyHash(pubkey_hash));
126-
config = config.watch_address(address);
127-
assert_eq!(config.watch_items.len(), 1);
128-
129-
let script = dashcore::ScriptBuf::new();
130-
config = config.watch_script(script);
131-
assert_eq!(config.watch_items.len(), 2);
132-
}
133-
134116
#[test]
135117
fn test_disable_features() {
136118
let config = ClientConfig::default().without_filters().without_masternodes();

dash-spv/src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ impl<
23832383

23842384
/// Get mutable reference to sync manager (for testing)
23852385
#[cfg(test)]
2386-
pub fn sync_manager_mut(&mut self) -> &mut SequentialSyncManager<S, N> {
2386+
pub fn sync_manager_mut(&mut self) -> &mut SequentialSyncManager<S, N, W> {
23872387
&mut self.sync_manager
23882388
}
23892389

dash-spv/src/network/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ mod multi_peer_tests {
135135
message_timeout: Duration::from_secs(30),
136136
sync_timeout: Duration::from_secs(60),
137137
read_timeout: Duration::from_millis(15),
138-
watch_items: vec![],
139138
enable_filters: false,
140139
enable_masternodes: false,
141140
max_peers: 3,

dash-spv/src/sync/filters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! Filter synchronization functionality.
22
33
use dashcore::{
4-
BlockHash, ScriptBuf,
54
bip158::{BlockFilterReader, Error as Bip158Error},
65
hash_types::FilterHeader,
76
network::message::NetworkMessage,
87
network::message_blockdata::Inventory,
98
network::message_filter::{CFHeaders, GetCFHeaders, GetCFilters},
9+
BlockHash, ScriptBuf,
1010
};
11-
use dashcore_hashes::{Hash, sha256d};
11+
use dashcore_hashes::{sha256d, Hash};
1212
use std::collections::{HashMap, HashSet, VecDeque};
1313
use tokio::sync::mpsc;
1414

dash-spv/src/sync/sequential/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ use transitions::TransitionManager;
3737
const CHAINLOCK_VALIDATION_MASTERNODE_OFFSET: u32 = 8;
3838

3939
/// Manages sequential synchronization of all data types
40-
pub struct SequentialSyncManager<
41-
S: StorageManager,
42-
N: NetworkManager,
43-
W: WalletInterface,
44-
> {
40+
pub struct SequentialSyncManager<S: StorageManager, N: NetworkManager, W: WalletInterface> {
4541
_phantom_s: std::marker::PhantomData<S>,
4642
_phantom_n: std::marker::PhantomData<N>,
4743
/// Current synchronization phase

0 commit comments

Comments
 (0)