checking for signals in the light client
This commit is contained in:
@@ -30,7 +30,7 @@ use util::kvdb::{Database, DatabaseConfig};
|
||||
use cache::Cache;
|
||||
use util::Mutex;
|
||||
|
||||
use super::{Client, Config as ClientConfig};
|
||||
use super::{ChainDataFetcher, Client, Config as ClientConfig};
|
||||
|
||||
/// Errors on service initialization.
|
||||
#[derive(Debug)]
|
||||
@@ -51,14 +51,14 @@ impl fmt::Display for Error {
|
||||
}
|
||||
|
||||
/// Light client service.
|
||||
pub struct Service {
|
||||
client: Arc<Client>,
|
||||
pub struct Service<T> {
|
||||
client: Arc<Client<T>>,
|
||||
io_service: IoService<ClientIoMessage>,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
impl<T: ChainDataFetcher> Service<T> {
|
||||
/// Start the service: initialize I/O workers and client itself.
|
||||
pub fn start(config: ClientConfig, spec: &Spec, path: &Path, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
|
||||
pub fn start(config: ClientConfig, spec: &Spec, fetcher: T, path: &Path, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
|
||||
|
||||
// initialize database.
|
||||
let mut db_config = DatabaseConfig::with_columns(db::NUM_COLUMNS);
|
||||
@@ -81,6 +81,7 @@ impl Service {
|
||||
db,
|
||||
db::COL_LIGHT_CHAIN,
|
||||
spec,
|
||||
fetcher,
|
||||
io_service.channel(),
|
||||
cache,
|
||||
).map_err(Error::Database)?);
|
||||
@@ -97,14 +98,14 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Get a handle to the client.
|
||||
pub fn client(&self) -> &Arc<Client> {
|
||||
pub fn client(&self) -> &Arc<Client<T>> {
|
||||
&self.client
|
||||
}
|
||||
}
|
||||
|
||||
struct ImportBlocks(Arc<Client>);
|
||||
struct ImportBlocks<T>(Arc<Client<T>>);
|
||||
|
||||
impl IoHandler<ClientIoMessage> for ImportBlocks {
|
||||
impl<T: ChainDataFetcher> IoHandler<ClientIoMessage> for ImportBlocks<T> {
|
||||
fn message(&self, _io: &IoContext<ClientIoMessage>, message: &ClientIoMessage) {
|
||||
if let ClientIoMessage::BlockVerified = *message {
|
||||
self.0.import_verified();
|
||||
@@ -117,9 +118,10 @@ mod tests {
|
||||
use super::Service;
|
||||
use devtools::RandomTempPath;
|
||||
use ethcore::spec::Spec;
|
||||
|
||||
|
||||
use std::sync::Arc;
|
||||
use cache::Cache;
|
||||
use client::fetch;
|
||||
use time::Duration;
|
||||
use util::Mutex;
|
||||
|
||||
@@ -129,6 +131,6 @@ mod tests {
|
||||
let temp_path = RandomTempPath::new();
|
||||
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::hours(6))));
|
||||
|
||||
Service::start(Default::default(), &spec, temp_path.as_path(), cache).unwrap();
|
||||
Service::start(Default::default(), &spec, fetch::unavailable(), temp_path.as_path(), cache).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user