Merge branch 'master' of github.com:ethcore/parity into jsonrpc2

This commit is contained in:
debris 2016-02-11 10:20:15 +01:00
commit b0f2ae147b
4 changed files with 30 additions and 14 deletions

View File

@ -369,7 +369,7 @@ impl BlockChainClient for Client {
self.block_hash(id).and_then(|hash| {
self.chain.read().unwrap().block(&hash).map(|bytes| {
let rlp = Rlp::new(&bytes);
let mut body = RlpStream::new();
let mut body = RlpStream::new_list(2);
body.append_raw(rlp.at(1).as_raw(), 1);
body.append_raw(rlp.at(2).as_raw(), 1);
body.out()

View File

@ -20,7 +20,6 @@ use util::*;
use util::panics::*;
use spec::Spec;
use error::*;
use std::env;
use client::Client;
/// Message type for external and internal events
@ -44,16 +43,14 @@ pub struct ClientService {
impl ClientService {
/// Start the service in a separate thread.
pub fn start(spec: Spec, net_config: NetworkConfiguration) -> Result<ClientService, Error> {
pub fn start(spec: Spec, net_config: NetworkConfiguration, db_path: &Path) -> Result<ClientService, Error> {
let panic_handler = PanicHandler::new_in_arc();
let mut net_service = try!(NetworkService::start(net_config));
panic_handler.forward_from(&net_service);
info!("Starting {}", net_service.host_info());
info!("Configured for {} using {} engine", spec.name, spec.engine_name);
let mut dir = env::home_dir().unwrap();
dir.push(".parity");
let client = try!(Client::new(spec, &dir, net_service.io().channel()));
let client = try!(Client::new(spec, db_path, net_service.io().channel()));
panic_handler.forward_from(client.deref());
let client_io = Arc::new(ClientIoHandler {
client: client.clone()
@ -136,7 +133,8 @@ mod tests {
#[test]
fn it_can_be_started() {
let spec = get_test_spec();
let service = ClientService::start(spec, NetworkConfiguration::new());
let temp_path = RandomTempPath::new();
let service = ClientService::start(spec, NetworkConfiguration::new(), &temp_path.as_path());
assert!(service.is_ok());
}
}

View File

@ -76,6 +76,19 @@ fn returns_chain_info() {
assert_eq!(info.best_block_hash, block.header().hash());
}
#[test]
fn returns_block_body() {
let dummy_block = get_good_dummy_block();
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
let client = client_result.reference();
let block = BlockView::new(&dummy_block);
let body = client.block_body(BlockId::Hash(block.header().hash())).unwrap();
let body = Rlp::new(&body);
assert_eq!(body.item_count(), 2);
assert_eq!(body.at(0).as_raw()[..], block.rlp().at(1).as_raw()[..]);
assert_eq!(body.at(1).as_raw()[..], block.rlp().at(2).as_raw()[..]);
}
#[test]
fn imports_block_sequence() {
let client_result = generate_dummy_client(6);

View File

@ -60,6 +60,7 @@ Usage:
Options:
--chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file
or frontier, mainnet, morden, or testnet [default: frontier].
-d --db-path PATH Specify the database & configuration directory path [default: $HOME/.parity]
--listen-address URL Specify the IP/port on which to listen for peers [default: 0.0.0.0:30304].
--public-address URL Specify the IP/port on which peers may connect [default: 0.0.0.0:30304].
@ -129,7 +130,11 @@ impl Configuration {
}
}
fn get_spec(&self) -> Spec {
fn path(&self) -> String {
self.args.flag_db_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
}
fn spec(&self) -> Spec {
match self.args.flag_chain.as_ref() {
"frontier" | "mainnet" => ethereum::new_frontier(),
"morden" | "testnet" => ethereum::new_morden(),
@ -138,14 +143,14 @@ impl Configuration {
}
}
fn get_init_nodes(&self, spec: &Spec) -> Vec<String> {
fn init_nodes(&self, spec: &Spec) -> Vec<String> {
match self.args.arg_enode.len() {
0 => spec.nodes().clone(),
_ => self.args.arg_enode.clone(),
}
}
fn get_net_addresses(&self) -> (SocketAddr, SocketAddr) {
fn net_addresses(&self) -> (SocketAddr, SocketAddr) {
let listen_address;
let public_address;
@ -183,7 +188,7 @@ fn main() {
return;
}
let spec = conf.get_spec();
let spec = conf.spec();
// Setup logging
setup_log(&conf.args.flag_logging);
@ -193,13 +198,13 @@ fn main() {
// Configure network
let mut net_settings = NetworkConfiguration::new();
net_settings.nat_enabled = conf.args.flag_upnp;
net_settings.boot_nodes = conf.get_init_nodes(&spec);
let (listen, public) = conf.get_net_addresses();
net_settings.boot_nodes = conf.init_nodes(&spec);
let (listen, public) = conf.net_addresses();
net_settings.listen_address = listen;
net_settings.public_address = public;
// Build client
let mut service = ClientService::start(spec, net_settings).unwrap();
let mut service = ClientService::start(spec, net_settings, &Path::new(&conf.path())).unwrap();
let client = service.client().clone();
client.configure_cache(conf.args.flag_cache_pref_size, conf.args.flag_cache_max_size);