Client now takes Spec instead of Engine

This commit is contained in:
arkpar 2016-01-11 12:28:59 +01:00
parent 33d3a4d633
commit 3a2663ce93
4 changed files with 12 additions and 17 deletions

View File

@ -11,16 +11,15 @@ use util::network::{NetworkService};
use ethcore::client::Client;
use ethcore::sync::EthSync;
use ethcore::ethereum;
use ethcore::ethereum::ethash::Ethash;
fn main() {
::env_logger::init().ok();
let mut service = NetworkService::start().unwrap();
//TODO: replace with proper genesis and chain params.
let engine = Ethash::new_arc(ethereum::new_frontier());
let spec = ethereum::new_frontier();
let mut dir = env::temp_dir();
dir.push(H32::random().hex());
let client = Arc::new(Client::new(engine, &dir));
let client = Arc::new(Client::new(spec, &dir).unwrap());
EthSync::register(&mut service, client);
loop {
let mut cmd = String::new();

View File

@ -1,8 +1,9 @@
use util::*;
use blockchain::BlockChain;
use views::BlockView;
use error::ImportError;
use error::*;
use header::BlockNumber;
use spec::Spec;
use engine::Engine;
/// General block status
@ -95,16 +96,17 @@ pub trait BlockChainClient : Sync {
/// Blockchain database client backed by a persistent database. Owns and manages a blockchain and a block queue.
pub struct Client {
chain: Arc<BlockChain>,
_engine: Arc<Engine>,
_engine: Arc<Box<Engine>>,
}
impl Client {
pub fn new(engine: Arc<Engine>, path: &Path) -> Client {
let chain = Arc::new(BlockChain::new(&engine.spec().genesis_block(), path));
Client {
pub fn new(spec: Spec, path: &Path) -> Result<Client, Error> {
let chain = Arc::new(BlockChain::new(&spec.genesis_block(), path));
let engine = Arc::new(try!(spec.to_engine()));
Ok(Client {
chain: chain.clone(),
_engine: engine.clone(),
}
_engine: engine,
})
}
}

View File

@ -13,10 +13,6 @@ impl Ethash {
pub fn new_boxed(spec: Spec) -> Box<Engine> {
Box::new(Ethash{spec: spec})
}
pub fn new_arc(spec: Spec) -> Arc<Engine> {
Arc::new(Ethash{spec: spec})
}
}
impl Engine for Ethash {

View File

@ -13,13 +13,11 @@
/// use ethcore::client::Client;
/// use ethcore::sync::EthSync;
/// use ethcore::ethereum;
/// use ethcore::ethereum::ethash::Ethash;
///
/// fn main() {
/// let mut service = NetworkService::start().unwrap();
/// let engine = Ethash::new_arc(ethereum::new_frontier());
/// let dir = env::temp_dir();
/// let client = Arc::new(Client::new(engine, &dir));
/// let client = Arc::new(Client::new(ethereum::new_frontier(), &dir).unwrap());
/// EthSync::register(&mut service, client);
/// }
/// ```