extend sync status interface to sync provider

This commit is contained in:
Nikolay Volf
2016-03-10 20:32:17 +04:00
parent 8dd41bfe0c
commit 25a63611f8
4 changed files with 20 additions and 18 deletions

View File

@@ -95,9 +95,11 @@ impl Default for SyncConfig {
}
/// Current sync status
pub trait SyncStatusProvider: Send + Sync {
pub trait SyncProvider: Send + Sync {
/// Get sync status
fn status(&self) -> SyncStatus;
/// Insert transaction in the sync transaction queue
fn insert_transaction(&self, transaction: ethcore::transaction::SignedTransaction);
}
/// Ethereum network protocol handler
@@ -130,9 +132,16 @@ impl EthSync {
pub fn restart(&mut self, io: &mut NetworkContext<SyncMessage>) {
self.sync.write().unwrap().restart(&mut NetSyncIo::new(io, self.chain.deref()));
}
}
impl SyncProvider for EthSync {
/// Get sync status
fn status(&self) -> SyncStatus {
self.sync.read().unwrap().status()
}
/// Insert transaction in transaction queue
pub fn insert_transaction(&self, transaction: ethcore::transaction::SignedTransaction) {
fn insert_transaction(&self, transaction: ethcore::transaction::SignedTransaction) {
use util::numbers::*;
let nonce_fn = |a: &Address| self.chain.state().nonce(a) + U256::one();
@@ -141,13 +150,6 @@ impl EthSync {
}
}
impl SyncStatusProvider for EthSync {
/// Get sync status
fn status(&self) -> SyncStatus {
self.sync.read().unwrap().status()
}
}
impl NetworkProtocolHandler<SyncMessage> for EthSync {
fn initialize(&self, io: &NetworkContext<SyncMessage>) {
io.register_timer(0, 1000).expect("Error registering sync timer");