From 9ae93d69628aa77efbc52477f85ecd1b7b1c58f1 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 7 Jun 2016 16:04:26 +0200 Subject: [PATCH 01/15] remove unsafety from util/hash.rs --- util/src/hash.rs | 106 +++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 67 deletions(-) diff --git a/util/src/hash.rs b/util/src/hash.rs index acb4c5cc5..20190f2de 100644 --- a/util/src/hash.rs +++ b/util/src/hash.rs @@ -150,10 +150,8 @@ macro_rules! impl_hash { } fn copy_to(&self, dest: &mut[u8]) { - unsafe { let min = ::std::cmp::min($size, dest.len()); - ::std::ptr::copy(self.0.as_ptr(), dest.as_mut_ptr(), min); - } + dest[..min].copy_from_slice(&self.0[..min]); } fn shift_bloomed<'a, T>(&'a mut self, b: &T) -> &'a mut Self where T: FixedHash { @@ -163,10 +161,7 @@ macro_rules! impl_hash { // impl |= instead // TODO: that's done now! - unsafe { - use std::{mem, ptr}; - ptr::copy(new_self.0.as_ptr(), self.0.as_mut_ptr(), mem::size_of::()); - } + self.0 = new_self.0; self } @@ -316,12 +311,9 @@ macro_rules! impl_hash { #[cfg_attr(feature="dev", allow(expl_impl_clone_on_copy))] impl Clone for $from { fn clone(&self) -> $from { - unsafe { - use std::{mem, ptr}; - let mut ret: $from = mem::uninitialized(); - ptr::copy(self.0.as_ptr(), ret.0.as_mut_ptr(), mem::size_of::<$from>()); - ret - } + let mut ret = $from::new(); + ret.0.copy_from_slice(&self.0); + ret } } @@ -404,14 +396,11 @@ macro_rules! impl_hash { type Output = $from; fn bitor(self, rhs: Self) -> Self::Output { - unsafe { - use std::mem; - let mut ret: $from = mem::uninitialized(); - for i in 0..$size { - ret.0[i] = self.0[i] | rhs.0[i]; - } - ret + let mut ret: $from = $from::default(); + for i in 0..$size { + ret.0[i] = self.0[i] | rhs.0[i]; } + ret } } @@ -429,14 +418,11 @@ macro_rules! impl_hash { type Output = $from; fn bitand(self, rhs: Self) -> Self::Output { - unsafe { - use std::mem; - let mut ret: $from = mem::uninitialized(); - for i in 0..$size { - ret.0[i] = self.0[i] & rhs.0[i]; - } - ret + let mut ret: $from = $from::default(); + for i in 0..$size { + ret.0[i] = self.0[i] & rhs.0[i]; } + ret } } @@ -454,14 +440,11 @@ macro_rules! impl_hash { type Output = $from; fn bitxor(self, rhs: Self) -> Self::Output { - unsafe { - use std::mem; - let mut ret: $from = mem::uninitialized(); - for i in 0..$size { - ret.0[i] = self.0[i] ^ rhs.0[i]; - } - ret + let mut ret: $from = $from::default(); + for i in 0..$size { + ret.0[i] = self.0[i] ^ rhs.0[i]; } + ret } } @@ -516,21 +499,17 @@ macro_rules! impl_hash { impl From for H256 { fn from(value: U256) -> H256 { - unsafe { - let mut ret: H256 = ::std::mem::uninitialized(); - value.to_raw_bytes(&mut ret); - ret - } + let mut ret = H256::new(); + value.to_raw_bytes(&mut ret); + ret } } impl<'a> From<&'a U256> for H256 { fn from(value: &'a U256) -> H256 { - unsafe { - let mut ret: H256 = ::std::mem::uninitialized(); - value.to_raw_bytes(&mut ret); - ret - } + let mut ret: H256 = H256::new(); + value.to_raw_bytes(&mut ret); + ret } } @@ -548,51 +527,44 @@ impl<'a> From<&'a H256> for U256 { impl From for Address { fn from(value: H256) -> Address { - unsafe { - let mut ret: Address = ::std::mem::uninitialized(); - ::std::ptr::copy(value.as_ptr().offset(12), ret.as_mut_ptr(), 20); - ret - } + let mut ret = Address::new(); + ret.0.copy_from_slice(&value[12..32]); + ret } } impl From for H64 { fn from(value: H256) -> H64 { - unsafe { - let mut ret: H64 = ::std::mem::uninitialized(); - ::std::ptr::copy(value.as_ptr().offset(20), ret.as_mut_ptr(), 8); - ret - } + let mut ret = H64::new(); + ret.0.copy_from_slice(&value[20..28]); + ret } } + /* impl<'a> From<&'a H256> for Address { fn from(value: &'a H256) -> Address { - unsafe { - let mut ret: Address = ::std::mem::uninitialized(); - ::std::ptr::copy(value.as_ptr().offset(12), ret.as_mut_ptr(), 20); + let mut ret = Address::new(); + ret.0.copy_from_slice(&value[12..32]); ret } } } */ + impl From
for H256 { fn from(value: Address) -> H256 { - unsafe { - let mut ret = H256::new(); - ::std::ptr::copy(value.as_ptr(), ret.as_mut_ptr().offset(12), 20); - ret - } + let mut ret = H256::new(); + ret.0[12..32].copy_from_slice(&value); + ret } } impl<'a> From<&'a Address> for H256 { fn from(value: &'a Address) -> H256 { - unsafe { - let mut ret = H256::new(); - ::std::ptr::copy(value.as_ptr(), ret.as_mut_ptr().offset(12), 20); - ret - } + let mut ret = H256::new(); + ret.0[12..32].copy_from_slice(&value); + ret } } From 482fe3b21112a6a398e4b57d5693ac9d5de49b5a Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 7 Jun 2016 16:11:34 +0200 Subject: [PATCH 02/15] fixed indentation --- util/src/hash.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/src/hash.rs b/util/src/hash.rs index 20190f2de..290d5500a 100644 --- a/util/src/hash.rs +++ b/util/src/hash.rs @@ -150,8 +150,8 @@ macro_rules! impl_hash { } fn copy_to(&self, dest: &mut[u8]) { - let min = ::std::cmp::min($size, dest.len()); - dest[..min].copy_from_slice(&self.0[..min]); + let min = ::std::cmp::min($size, dest.len()); + dest[..min].copy_from_slice(&self.0[..min]); } fn shift_bloomed<'a, T>(&'a mut self, b: &T) -> &'a mut Self where T: FixedHash { From e46c9f67ab0731770b80f106cfbdfaa64c00a06b Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 7 Jun 2016 16:15:17 +0200 Subject: [PATCH 03/15] remove outdated comments --- util/src/hash.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/util/src/hash.rs b/util/src/hash.rs index 290d5500a..ab1255e39 100644 --- a/util/src/hash.rs +++ b/util/src/hash.rs @@ -143,6 +143,7 @@ macro_rules! impl_hash { } min } + fn from_slice(src: &[u8]) -> Self { let mut r = Self::new(); r.clone_from_slice(src); @@ -158,11 +159,7 @@ macro_rules! impl_hash { let bp: Self = b.bloom_part($size); let new_self = &bp | self; - // impl |= instead - // TODO: that's done now! - self.0 = new_self.0; - self } @@ -174,7 +171,6 @@ macro_rules! impl_hash { let bloom_bits = m * 8; let mask = bloom_bits - 1; let bloom_bytes = (log2(bloom_bits) + 7) / 8; - //println!("bb: {}", bloom_bytes); // must be a power of 2 assert_eq!(m & (m - 1), 0); From db869fcdd10792de5d618762345d45b94fc4a7f5 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 7 Jun 2016 16:18:50 +0200 Subject: [PATCH 04/15] remove unnecessary reference --- util/src/hash.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/src/hash.rs b/util/src/hash.rs index ab1255e39..6c1f8b2a4 100644 --- a/util/src/hash.rs +++ b/util/src/hash.rs @@ -559,7 +559,7 @@ impl From
for H256 { impl<'a> From<&'a Address> for H256 { fn from(value: &'a Address) -> H256 { let mut ret = H256::new(); - ret.0[12..32].copy_from_slice(&value); + ret.0[12..32].copy_from_slice(value); ret } } From 5168a1c8517f972667ece5cbea140a136c287d76 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 7 Jun 2016 16:42:07 +0200 Subject: [PATCH 05/15] remove some unsafety from uint.rs --- util/bigint/src/uint.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/util/bigint/src/uint.rs b/util/bigint/src/uint.rs index f87b494a9..5c8da4a3c 100644 --- a/util/bigint/src/uint.rs +++ b/util/bigint/src/uint.rs @@ -92,8 +92,8 @@ macro_rules! uint_overflowing_add_reg { macro_rules! uint_overflowing_add { (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ let mut result: [u64; 4] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) }; - let other_t: &[u64; 4] = unsafe { &mem::transmute($other) }; + let self_t: &[u64; 4] = &self.0; + let other_t: &[u64; 4] = &other.0; let overflow: u8; unsafe { @@ -115,8 +115,8 @@ macro_rules! uint_overflowing_add { }); (U512, $n_words: expr, $self_expr: expr, $other: expr) => ({ let mut result: [u64; 8] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 8] = unsafe { &mem::transmute($self_expr) }; - let other_t: &[u64; 8] = unsafe { &mem::transmute($other) }; + let self_t: &[u64; 8] = &self.0; + let other_t: &[u64; 8] = &other.0; let overflow: u8; @@ -196,8 +196,8 @@ macro_rules! uint_overflowing_sub_reg { macro_rules! uint_overflowing_sub { (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ let mut result: [u64; 4] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) }; - let other_t: &[u64; 4] = unsafe { &mem::transmute($other) }; + let self_t: &[u64; 4] = &self.0; + let other_t: &[u64; 4] = &other.0; let overflow: u8; unsafe { @@ -218,8 +218,8 @@ macro_rules! uint_overflowing_sub { }); (U512, $n_words: expr, $self_expr: expr, $other: expr) => ({ let mut result: [u64; 8] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 8] = unsafe { &mem::transmute($self_expr) }; - let other_t: &[u64; 8] = unsafe { &mem::transmute($other) }; + let self_t: &[u64; 8] = &self.0; + let other_t: &[u64; 8] = &other.0; let overflow: u8; @@ -270,8 +270,8 @@ macro_rules! uint_overflowing_sub { macro_rules! uint_overflowing_mul { (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ let mut result: [u64; 4] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) }; - let other_t: &[u64; 4] = unsafe { &mem::transmute($other) }; + let self_t: &[u64; 4] = &self.0; + let other_t: &[u64; 4] = &self.0; let overflow: u64; unsafe { @@ -548,6 +548,7 @@ pub trait Uint: Sized + Default + FromStr + From + fmt::Debug + fmt::Displa macro_rules! construct_uint { ($name:ident, $n_words:expr) => ( /// Little-endian large integer type + #[repr(C)] #[derive(Copy, Clone, Eq, PartialEq)] pub struct $name(pub [u64; $n_words]); @@ -1132,8 +1133,8 @@ impl U256 { /// No overflow possible #[cfg(all(asm_available, target_arch="x86_64"))] pub fn full_mul(self, other: U256) -> U512 { - let self_t: &[u64; 4] = unsafe { &mem::transmute(self) }; - let other_t: &[u64; 4] = unsafe { &mem::transmute(other) }; + let self_t: &[u64; 4] = &self.0; + let other_t: &[u64; 4] = &other.0; let mut result: [u64; 8] = unsafe { mem::uninitialized() }; unsafe { asm!(" From 2e52c990425c12899980eafa8e66dac7a00b74a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 9 Jun 2016 10:02:52 +0200 Subject: [PATCH 06/15] Fixing CORS settings --- Cargo.lock | 2 +- rpc/src/lib.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d0803f65..f9ee733b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -606,7 +606,7 @@ dependencies = [ [[package]] name = "jsonrpc-http-server" version = "5.1.0" -source = "git+https://github.com/ethcore/jsonrpc-http-server.git#77dcac785c02c3a7622d36aa635ee80d63d0b20c" +source = "git+https://github.com/ethcore/jsonrpc-http-server.git#6117b1d77b5a60d6fa2dc884f12aa7f5fd4585ca" dependencies = [ "hyper 0.9.3 (git+https://github.com/ethcore/hyper)", "jsonrpc-core 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index b46a13197..ad2d52495 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -75,7 +75,11 @@ impl RpcServer { /// Start http server asynchronously and returns result with `Server` handle on success or an error. pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec) -> Result { let cors_domains = cors_domains.into_iter() - .map(jsonrpc_http_server::AccessControlAllowOrigin::Value) + .map(|v| match v { + ref v if v == "*" => jsonrpc_http_server::AccessControlAllowOrigin::Any, + ref v if v == "null" => jsonrpc_http_server::AccessControlAllowOrigin::Null, + v => jsonrpc_http_server::AccessControlAllowOrigin::Value(v), + }) .collect(); Server::start(addr, self.handler.clone(), cors_domains) } From d54d3a2c60f7d30f16a169963b8fe0c8760a0b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 9 Jun 2016 15:19:48 +0200 Subject: [PATCH 07/15] Fixing match --- rpc/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index ad2d52495..43c120e40 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -75,10 +75,10 @@ impl RpcServer { /// Start http server asynchronously and returns result with `Server` handle on success or an error. pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec) -> Result { let cors_domains = cors_domains.into_iter() - .map(|v| match v { - ref v if v == "*" => jsonrpc_http_server::AccessControlAllowOrigin::Any, - ref v if v == "null" => jsonrpc_http_server::AccessControlAllowOrigin::Null, - v => jsonrpc_http_server::AccessControlAllowOrigin::Value(v), + .map(|v| match v.as_str() { + "*" => jsonrpc_http_server::AccessControlAllowOrigin::Any, + "null" => jsonrpc_http_server::AccessControlAllowOrigin::Null, + v => jsonrpc_http_server::AccessControlAllowOrigin::Value(v.into()), }) .collect(); Server::start(addr, self.handler.clone(), cors_domains) From 383b7a3cab8eac27081bdbdad1712ba6148f0053 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 10 Jun 2016 09:53:09 +0300 Subject: [PATCH 08/15] avoid unwraps --- ipc/codegen/Cargo.toml | 2 +- ipc/codegen/src/serialization.rs | 14 +++++++++++--- ipc/tests/build.rs | 27 ++++++++++++++------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/ipc/codegen/Cargo.toml b/ipc/codegen/Cargo.toml index 2febd1a2b..b7111c4af 100644 --- a/ipc/codegen/Cargo.toml +++ b/ipc/codegen/Cargo.toml @@ -15,7 +15,7 @@ with-syntex = ["quasi/with-syntex", "quasi_codegen", "quasi_codegen/with-syntex" [build-dependencies] quasi_codegen = { version = "0.11", optional = true } -syntex = { version = "*", optional = true } +syntex = { version = "0.33", optional = true } [dependencies] aster = { version = "0.17", default-features = false } diff --git a/ipc/codegen/src/serialization.rs b/ipc/codegen/src/serialization.rs index b32c88b6d..9c58e198e 100644 --- a/ipc/codegen/src/serialization.rs +++ b/ipc/codegen/src/serialization.rs @@ -89,7 +89,7 @@ fn serialize_item( let (size_expr, read_expr, write_expr) = (binary_expressions.size, binary_expressions.read, binary_expressions.write); - Ok(quote_item!(cx, + match quote_item!(cx, impl $generics ::ipc::BinaryConvertable for $ty $where_clause { fn size(&self) -> usize { $size_expr @@ -106,8 +106,16 @@ fn serialize_item( fn len_params() -> usize { 1 } - } - ).unwrap()) + }) + { + Some(item) => Ok(item), + None => { + cx.span_err( + item.span, + "syntax error expanding serialization implementation"); + Err(Error) + } + } } #[allow(unreachable_code)] diff --git a/ipc/tests/build.rs b/ipc/tests/build.rs index da5d939f2..e498e3405 100644 --- a/ipc/tests/build.rs +++ b/ipc/tests/build.rs @@ -19,20 +19,20 @@ extern crate ethcore_ipc_codegen as codegen; use std::env; use std::path::Path; +use std::process::exit; pub fn main() { let out_dir = env::var_os("OUT_DIR").unwrap(); - // ipc pass - { + // rpc pass + if { let src = Path::new("nested.rs.in"); let dst = Path::new(&out_dir).join("nested_ipc.rs"); let mut registry = syntex::Registry::new(); codegen::register(&mut registry); - registry.expand("", &src, &dst).unwrap(); + registry.expand("", &src, &dst).is_ok() } - - // serde pass + // serialization pass { let src = Path::new(&out_dir).join("nested_ipc.rs"); let dst = Path::new(&out_dir).join("nested_cg.rs"); @@ -41,16 +41,15 @@ pub fn main() { registry.expand("", &src, &dst).unwrap(); } - // ipc pass - { + // rpc pass + if { let src = Path::new("service.rs.in"); let dst = Path::new(&out_dir).join("service_ipc.rs"); let mut registry = syntex::Registry::new(); codegen::register(&mut registry); - registry.expand("", &src, &dst).unwrap(); + registry.expand("", &src, &dst).is_ok() } - - // serde pass + // serialization pass { let src = Path::new(&out_dir).join("service_ipc.rs"); let dst = Path::new(&out_dir).join("service_cg.rs"); @@ -59,13 +58,15 @@ pub fn main() { registry.expand("", &src, &dst).unwrap(); } - - // ipc pass + // rpc pass { let src = Path::new("binary.rs.in"); let dst = Path::new(&out_dir).join("binary.rs"); let mut registry = syntex::Registry::new(); codegen::register(&mut registry); - registry.expand("", &src, &dst).unwrap(); + if let Err(err_msg) = registry.expand("", &src, &dst) { + println!("error: {}", err_msg); + exit(1); + } } } From 036b324804b052ea3adb7a94e83e90e48d54d6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 10 Jun 2016 11:38:36 +0200 Subject: [PATCH 09/15] Bumping dapps --- Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d0803f65..0ed7f0187 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -293,7 +293,7 @@ dependencies = [ "parity-dapps-dao 0.4.0 (git+https://github.com/ethcore/parity-dapps-dao-rs.git)", "parity-dapps-makerotc 0.3.0 (git+https://github.com/ethcore/parity-dapps-makerotc-rs.git)", "parity-dapps-status 0.5.0 (git+https://github.com/ethcore/parity-dapps-status-rs.git)", - "parity-dapps-wallet 0.6.0 (git+https://github.com/ethcore/parity-dapps-wallet-rs.git)", + "parity-dapps-wallet 0.6.1 (git+https://github.com/ethcore/parity-dapps-wallet-rs.git)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -901,7 +901,7 @@ dependencies = [ [[package]] name = "parity-dapps-builtins" version = "0.5.1" -source = "git+https://github.com/ethcore/parity-dapps-builtins-rs.git#d3c95d62ffaa57016b162a9a9f0e6dd629dab423" +source = "git+https://github.com/ethcore/parity-dapps-builtins-rs.git#b3970ff4686a12321365cfafba6552bfaa2e7874" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] @@ -932,8 +932,8 @@ dependencies = [ [[package]] name = "parity-dapps-wallet" -version = "0.6.0" -source = "git+https://github.com/ethcore/parity-dapps-wallet-rs.git#ad23b093d47527333a262c95e6fb20a97d15d6e6" +version = "0.6.1" +source = "git+https://github.com/ethcore/parity-dapps-wallet-rs.git#8923d4c73359c75ce04f0639bbcde46adb846b81" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] @@ -941,7 +941,7 @@ dependencies = [ [[package]] name = "parity-minimal-sysui" version = "0.1.0" -source = "git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git#cb27ae09ee18773ccca6ba2ac74fa3128047a652" +source = "git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git#121216ad10868e428dc4ca08145898a8a4193a84" [[package]] name = "phf" From e5e238746b09377ed3c00beb420fd442bc41deef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 10 Jun 2016 15:39:34 +0200 Subject: [PATCH 10/15] Bumping sysui & topbar. personal_signerEnabled returns port --- parity/configuration.rs | 8 ++++++++ parity/main.rs | 4 ++-- parity/rpc_apis.rs | 6 +++--- rpc/src/v1/impls/personal.rs | 10 ++++++---- rpc/src/v1/tests/mocked/personal.rs | 28 +++++++++++++++++++++------- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/parity/configuration.rs b/parity/configuration.rs index 66ca93316..3076e4e68 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -360,6 +360,14 @@ impl Configuration { if self.args.flag_geth { self.geth_ipc_path() } else { Configuration::replace_home(&self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone())) } } + + pub fn signer_port(&self) -> Option { + if self.args.flag_signer { + Some(self.args.flag_signer_port) + } else { + None + } + } } #[cfg(test)] diff --git a/parity/main.rs b/parity/main.rs index 58d5fe18e..0d536e28a 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -201,7 +201,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) let sync = EthSync::register(service.network(), sync_config, client.clone()); let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies { - signer_enabled: conf.args.flag_signer, + signer_port: conf.signer_port(), signer_queue: Arc::new(rpc_apis::ConfirmationsQueue::default()), client: client.clone(), sync: sync.clone(), @@ -244,7 +244,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) // Set up a signer let signer_server = signer::start(signer::Configuration { - enabled: deps_for_rpc_apis.signer_enabled, + enabled: deps_for_rpc_apis.signer_port.is_some(), port: conf.args.flag_signer_port, signer_path: conf.directories().signer, }, signer::Dependencies { diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index fea5d0135..e69a2751f 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -79,7 +79,7 @@ impl FromStr for Api { } pub struct Dependencies { - pub signer_enabled: bool, + pub signer_port: Option, pub signer_queue: Arc, pub client: Arc, pub sync: Arc, @@ -146,14 +146,14 @@ pub fn setup_rpc(server: T, deps: Arc, apis: ApiSet server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate()); server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate()); - if deps.signer_enabled { + if deps.signer_port.is_some() { server.add_delegate(EthSigningQueueClient::new(&deps.signer_queue).to_delegate()); } else { server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate()); } }, Api::Personal => { - server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner, deps.signer_enabled).to_delegate()); + server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner, deps.signer_port.clone()).to_delegate()); }, Api::Signer => { server.add_delegate(SignerClient::new(&deps.secret_store, &deps.client, &deps.miner, &deps.signer_queue).to_delegate()); diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs index bb570a4e0..c62c71453 100644 --- a/rpc/src/v1/impls/personal.rs +++ b/rpc/src/v1/impls/personal.rs @@ -31,18 +31,18 @@ pub struct PersonalClient accounts: Weak, client: Weak, miner: Weak, - signer_enabled: bool, + signer_port: Option, } impl PersonalClient where A: AccountProvider, C: MiningBlockChainClient, M: MinerService { /// Creates new PersonalClient - pub fn new(store: &Arc, client: &Arc, miner: &Arc, signer_enabled: bool) -> Self { + pub fn new(store: &Arc, client: &Arc, miner: &Arc, signer_port: Option) -> Self { PersonalClient { accounts: Arc::downgrade(store), client: Arc::downgrade(client), miner: Arc::downgrade(miner), - signer_enabled: signer_enabled, + signer_port: signer_port, } } } @@ -51,7 +51,9 @@ impl Personal for PersonalClient where A: AccountProvider, C: MiningBlockChainClient, M: MinerService { fn signer_enabled(&self, _: Params) -> Result { - to_value(&self.signer_enabled) + self.signer_port + .map(|v| to_value(&v)) + .unwrap_or_else(|| to_value(&false)) } fn accounts(&self, _: Params) -> Result { diff --git a/rpc/src/v1/tests/mocked/personal.rs b/rpc/src/v1/tests/mocked/personal.rs index 16d8e620f..02b07abd3 100644 --- a/rpc/src/v1/tests/mocked/personal.rs +++ b/rpc/src/v1/tests/mocked/personal.rs @@ -49,11 +49,11 @@ fn miner_service() -> Arc { Arc::new(TestMinerService::default()) } -fn setup() -> PersonalTester { +fn setup(signer: Option) -> PersonalTester { let accounts = accounts_provider(); let client = blockchain_client(); let miner = miner_service(); - let personal = PersonalClient::new(&accounts, &client, &miner, false); + let personal = PersonalClient::new(&accounts, &client, &miner, signer); let io = IoHandler::new(); io.add_delegate(personal.to_delegate()); @@ -71,7 +71,7 @@ fn setup() -> PersonalTester { #[test] fn should_return_false_if_signer_is_disabled() { // given - let tester = setup(); + let tester = setup(None); // when let request = r#"{"jsonrpc": "2.0", "method": "personal_signerEnabled", "params": [], "id": 1}"#; @@ -82,9 +82,23 @@ fn should_return_false_if_signer_is_disabled() { assert_eq!(tester.io.handle_request(request), Some(response.to_owned())); } +#[test] +fn should_return_port_number_if_signer_is_enabled() { + // given + let tester = setup(Some(8180)); + + // when + let request = r#"{"jsonrpc": "2.0", "method": "personal_signerEnabled", "params": [], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":8180,"id":1}"#; + + + // then + assert_eq!(tester.io.handle_request(request), Some(response.to_owned())); +} + #[test] fn accounts() { - let tester = setup(); + let tester = setup(None); tester.accounts.accounts .write() .unwrap() @@ -98,7 +112,7 @@ fn accounts() { #[test] fn new_account() { - let tester = setup(); + let tester = setup(None); let request = r#"{"jsonrpc": "2.0", "method": "personal_newAccount", "params": ["pass"], "id": 1}"#; let res = tester.io.handle_request(request); @@ -122,7 +136,7 @@ fn sign_and_send_transaction_with_invalid_password() { let account = TestAccount::new("password123"); let address = account.address(); - let tester = setup(); + let tester = setup(None); tester.accounts.accounts.write().unwrap().insert(address.clone(), account); let request = r#"{ "jsonrpc": "2.0", @@ -148,7 +162,7 @@ fn sign_and_send_transaction() { let address = account.address(); let secret = account.secret.clone(); - let tester = setup(); + let tester = setup(None); tester.accounts.accounts.write().unwrap().insert(address.clone(), account); let request = r#"{ "jsonrpc": "2.0", From 89a77149bf893fd05a7abeeeb310733913e2682f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 10 Jun 2016 15:48:22 +0200 Subject: [PATCH 11/15] Removing clone --- parity/rpc_apis.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index e69a2751f..d9085fc31 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -153,7 +153,7 @@ pub fn setup_rpc(server: T, deps: Arc, apis: ApiSet } }, Api::Personal => { - server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner, deps.signer_port.clone()).to_delegate()); + server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner, deps.signer_port).to_delegate()); }, Api::Signer => { server.add_delegate(SignerClient::new(&deps.secret_store, &deps.client, &deps.miner, &deps.signer_queue).to_delegate()); From 6d9baef12cdae69d3d040a46d44ec142a4c74519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 10 Jun 2016 15:59:03 +0200 Subject: [PATCH 12/15] Bumping minimal sysui [ci skip] --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0ed7f0187..3b820e8a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -941,7 +941,7 @@ dependencies = [ [[package]] name = "parity-minimal-sysui" version = "0.1.0" -source = "git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git#121216ad10868e428dc4ca08145898a8a4193a84" +source = "git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git#4c704913f671060bb0e43b5ce4a68d02281115d5" [[package]] name = "phf" From c2b226ec5706d2bb66b3a371219229f18d6dd42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sun, 12 Jun 2016 10:23:16 +0200 Subject: [PATCH 13/15] Dapps bump --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9ee733b8..0192bcad5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -901,7 +901,7 @@ dependencies = [ [[package]] name = "parity-dapps-builtins" version = "0.5.1" -source = "git+https://github.com/ethcore/parity-dapps-builtins-rs.git#d3c95d62ffaa57016b162a9a9f0e6dd629dab423" +source = "git+https://github.com/ethcore/parity-dapps-builtins-rs.git#b3970ff4686a12321365cfafba6552bfaa2e7874" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] @@ -909,7 +909,7 @@ dependencies = [ [[package]] name = "parity-dapps-dao" version = "0.4.0" -source = "git+https://github.com/ethcore/parity-dapps-dao-rs.git#18f4b839b20fbdf8e0d163e14d25aafee603ac4b" +source = "git+https://github.com/ethcore/parity-dapps-dao-rs.git#dd6b9ca7c18fbfa714183a4f570bd75b8391c13d" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] @@ -917,7 +917,7 @@ dependencies = [ [[package]] name = "parity-dapps-makerotc" version = "0.3.0" -source = "git+https://github.com/ethcore/parity-dapps-makerotc-rs.git#7b771f217a3eefeb9a976c7ed470ca49fd9a9daa" +source = "git+https://github.com/ethcore/parity-dapps-makerotc-rs.git#33568ac7209aa765c498bb2322e848f552656303" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] From 9260d443623add83f14477c7210aa8dbeb2a8b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sun, 12 Jun 2016 10:30:44 +0200 Subject: [PATCH 14/15] Fixing uint ASM macros --- util/bigint/src/uint.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/util/bigint/src/uint.rs b/util/bigint/src/uint.rs index 5c8da4a3c..286f6a43f 100644 --- a/util/bigint/src/uint.rs +++ b/util/bigint/src/uint.rs @@ -91,9 +91,9 @@ macro_rules! uint_overflowing_add_reg { #[cfg(all(asm_available, target_arch="x86_64"))] macro_rules! uint_overflowing_add { (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ - let mut result: [u64; 4] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 4] = &self.0; - let other_t: &[u64; 4] = &other.0; + let mut result: [u64; $n_words] = unsafe { mem::uninitialized() }; + let self_t: &[u64; $n_words] = &$self_expr.0; + let other_t: &[u64; $n_words] = &$other.0; let overflow: u8; unsafe { @@ -114,9 +114,9 @@ macro_rules! uint_overflowing_add { (U256(result), overflow != 0) }); (U512, $n_words: expr, $self_expr: expr, $other: expr) => ({ - let mut result: [u64; 8] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 8] = &self.0; - let other_t: &[u64; 8] = &other.0; + let mut result: [u64; $n_words] = unsafe { mem::uninitialized() }; + let self_t: &[u64; $n_words] = &$self_expr.0; + let other_t: &[u64; $n_words] = &$other.0; let overflow: u8; @@ -195,9 +195,9 @@ macro_rules! uint_overflowing_sub_reg { #[cfg(all(asm_available, target_arch="x86_64"))] macro_rules! uint_overflowing_sub { (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ - let mut result: [u64; 4] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 4] = &self.0; - let other_t: &[u64; 4] = &other.0; + let mut result: [u64; $n_words] = unsafe { mem::uninitialized() }; + let self_t: &[u64; $n_words] = &$self_expr.0; + let other_t: &[u64; $n_words] = &$other.0; let overflow: u8; unsafe { @@ -217,9 +217,9 @@ macro_rules! uint_overflowing_sub { (U256(result), overflow != 0) }); (U512, $n_words: expr, $self_expr: expr, $other: expr) => ({ - let mut result: [u64; 8] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 8] = &self.0; - let other_t: &[u64; 8] = &other.0; + let mut result: [u64; $n_words] = unsafe { mem::uninitialized() }; + let self_t: &[u64; $n_words] = &$self_expr.0; + let other_t: &[u64; $n_words] = &$other.0; let overflow: u8; @@ -269,9 +269,9 @@ macro_rules! uint_overflowing_sub { #[cfg(all(asm_available, target_arch="x86_64"))] macro_rules! uint_overflowing_mul { (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ - let mut result: [u64; 4] = unsafe { mem::uninitialized() }; - let self_t: &[u64; 4] = &self.0; - let other_t: &[u64; 4] = &self.0; + let mut result: [u64; $n_words] = unsafe { mem::uninitialized() }; + let self_t: &[u64; $n_words] = &$self_expr.0; + let other_t: &[u64; $n_words] = &$other.0; let overflow: u64; unsafe { From fca22e92ce94437f36c764325b71e671b7f89b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sun, 12 Jun 2016 11:26:07 +0200 Subject: [PATCH 15/15] Bumping clippy --- Cargo.lock | 27 +++++++++++---------------- Cargo.toml | 2 +- dapps/Cargo.toml | 2 +- ethcore/Cargo.toml | 2 +- json/Cargo.toml | 2 +- rpc/Cargo.toml | 2 +- signer/Cargo.toml | 2 +- sync/Cargo.toml | 2 +- util/Cargo.toml | 2 +- 9 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9ee733b8..2267134a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,7 +3,7 @@ name = "parity" version = "1.2.0" dependencies = [ "ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", "ctrlc 1.1.1 (git+https://github.com/ethcore/rust-ctrlc.git)", "daemonize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.6.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -130,23 +130,18 @@ dependencies = [ [[package]] name = "clippy" -version = "0.0.71" +version = "0.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "clippy_lints 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", - "quine-mc_cluskey 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy_lints 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "clippy_lints" -version = "0.0.71" +version = "0.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "quine-mc_cluskey 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -256,7 +251,7 @@ name = "ethcore" version = "1.2.0" dependencies = [ "bloomchain 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.2.0", @@ -280,7 +275,7 @@ dependencies = [ name = "ethcore-dapps" version = "1.2.0" dependencies = [ - "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-rpc 1.2.0", "ethcore-util 1.2.0", "hyper 0.9.3 (git+https://github.com/ethcore/hyper)", @@ -344,7 +339,7 @@ dependencies = [ name = "ethcore-rpc" version = "1.2.0" dependencies = [ - "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.2.0", "ethcore 1.2.0", "ethcore-devtools 1.2.0", @@ -367,7 +362,7 @@ dependencies = [ name = "ethcore-signer" version = "1.2.0" dependencies = [ - "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-rpc 1.2.0", "ethcore-util 1.2.0", @@ -386,7 +381,7 @@ dependencies = [ "arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "bigint 0.1.0", "chrono 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -431,7 +426,7 @@ dependencies = [ name = "ethsync" version = "1.2.0" dependencies = [ - "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.76 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.2.0", "ethcore-util 1.2.0", diff --git a/Cargo.toml b/Cargo.toml index b08032c9a..f7f805d30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ daemonize = "0.2" num_cpus = "0.2" number_prefix = "0.2" rpassword = "0.2.1" -clippy = { version = "0.0.71", optional = true} +clippy = { version = "0.0.76", optional = true} ethcore = { path = "ethcore" } ethcore-util = { path = "util" } ethsync = { path = "sync" } diff --git a/dapps/Cargo.toml b/dapps/Cargo.toml index 2394df31a..396ee4f2c 100644 --- a/dapps/Cargo.toml +++ b/dapps/Cargo.toml @@ -28,7 +28,7 @@ parity-dapps-wallet = { git = "https://github.com/ethcore/parity-dapps-wallet-rs parity-dapps-dao = { git = "https://github.com/ethcore/parity-dapps-dao-rs.git", version = "0.4.0", optional = true } parity-dapps-makerotc = { git = "https://github.com/ethcore/parity-dapps-makerotc-rs.git", version = "0.3.0", optional = true } mime_guess = { version = "1.6.1" } -clippy = { version = "0.0.71", optional = true} +clippy = { version = "0.0.76", optional = true} [build-dependencies] serde_codegen = { version = "0.7.0", optional = true } diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index d558c902d..889d759ae 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -22,7 +22,7 @@ ethcore-util = { path = "../util" } evmjit = { path = "../evmjit", optional = true } ethash = { path = "../ethash" } num_cpus = "0.2" -clippy = { version = "0.0.71", optional = true} +clippy = { version = "0.0.76", optional = true} crossbeam = "0.2.9" lazy_static = "0.1" ethcore-devtools = { path = "../devtools" } diff --git a/json/Cargo.toml b/json/Cargo.toml index fc1eb3992..a2a560c43 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -10,7 +10,7 @@ rustc-serialize = "0.3" serde = "0.7.0" serde_json = "0.7.0" serde_macros = { version = "0.7.0", optional = true } -clippy = { version = "0.0.71", optional = true} +clippy = { version = "0.0.76", optional = true} [build-dependencies] serde_codegen = { version = "0.7.0", optional = true } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 4f5eaba82..b1369c88d 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -23,7 +23,7 @@ ethcore-devtools = { path = "../devtools" } rustc-serialize = "0.3" transient-hashmap = "0.1" serde_macros = { version = "0.7.0", optional = true } -clippy = { version = "0.0.71", optional = true} +clippy = { version = "0.0.76", optional = true} json-ipc-server = { git = "https://github.com/ethcore/json-ipc-server.git" } [build-dependencies] diff --git a/signer/Cargo.toml b/signer/Cargo.toml index ae5f4b42a..82160d55a 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -20,7 +20,7 @@ ethcore-util = { path = "../util" } ethcore-rpc = { path = "../rpc" } parity-minimal-sysui = { git = "https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git" } -clippy = { version = "0.0.71", optional = true} +clippy = { version = "0.0.76", optional = true} [features] dev = ["clippy"] diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 8c5b4c926..c77749c39 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -10,7 +10,7 @@ authors = ["Ethcore