Merge branch 'master' into types-binary

Conflicts:
	ethcore/src/error.rs
This commit is contained in:
Nikolay Volf 2016-05-14 23:12:18 +03:00
commit 2d992d0c29
24 changed files with 206 additions and 92 deletions

18
Cargo.lock generated
View File

@ -304,7 +304,7 @@ dependencies = [
"ethsync 1.2.0", "ethsync 1.2.0",
"json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)", "json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)",
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)", "jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -362,7 +362,7 @@ dependencies = [
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)", "jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-status 0.3.7 (git+https://github.com/ethcore/parity-status.git)", "parity-status 0.3.7 (git+https://github.com/ethcore/parity-status.git)",
"parity-wallet 0.1.1 (git+https://github.com/ethcore/parity-wallet.git)", "parity-wallet 0.2.0 (git+https://github.com/ethcore/parity-wallet.git)",
"parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)", "parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)",
"url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -580,6 +580,16 @@ dependencies = [
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "jsonrpc-http-server"
version = "5.1.0"
source = "git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains#9c026feeb6573c82c99c8005c5d8244de68a2e30"
dependencies = [
"hyper 0.9.3 (git+https://github.com/ethcore/hyper)",
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "kernel32-sys" name = "kernel32-sys"
version = "0.2.2" version = "0.2.2"
@ -833,8 +843,8 @@ dependencies = [
[[package]] [[package]]
name = "parity-wallet" name = "parity-wallet"
version = "0.1.1" version = "0.2.0"
source = "git+https://github.com/ethcore/parity-wallet.git#125b2c05118890eac7b845f832f39b069d9b4be8" source = "git+https://github.com/ethcore/parity-wallet.git#18a602fd25f3e9bcdbc5528bf61ba627665d962c"
dependencies = [ dependencies = [
"parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)", "parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)",
] ]

View File

@ -59,7 +59,7 @@ impl RandomTempPath {
impl Drop for RandomTempPath { impl Drop for RandomTempPath {
fn drop(&mut self) { fn drop(&mut self) {
if let Err(e) = fs::remove_dir_all(self.as_path()) { if let Err(e) = fs::remove_dir_all(self.as_path()) {
panic!("failed to remove temp directory, probably something failed to destroyed ({})", e); panic!("Failed to remove temp directory. Here's what prevented this from happening: ({})", e);
} }
} }
} }

View File

@ -398,7 +398,7 @@ impl<V> Client<V> where V: Verifier {
} }
impl<V> BlockChainClient for Client<V> where V: Verifier { impl<V> BlockChainClient for Client<V> where V: Verifier {
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
let header = self.block_header(BlockId::Latest).unwrap(); let header = self.block_header(BlockId::Latest).unwrap();
let view = HeaderView::new(&header); let view = HeaderView::new(&header);
let last_hashes = self.build_last_hashes(view.hash()); let last_hashes = self.build_last_hashes(view.hash());
@ -413,7 +413,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
}; };
// that's just a copy of the state. // that's just a copy of the state.
let mut state = self.state(); let mut state = self.state();
let sender = try!(t.sender()); let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let balance = state.balance(&sender); let balance = state.balance(&sender);
// give the sender max balance // give the sender max balance
state.sub_balance(&sender, &balance); state.sub_balance(&sender, &balance);

View File

@ -41,7 +41,7 @@ use header::{BlockNumber, Header};
use transaction::{LocalizedTransaction, SignedTransaction}; use transaction::{LocalizedTransaction, SignedTransaction};
use log_entry::LocalizedLogEntry; use log_entry::LocalizedLogEntry;
use filter::Filter; use filter::Filter;
use error::{ImportResult, Error}; use error::{ImportResult, ExecutionError};
use receipt::LocalizedReceipt; use receipt::LocalizedReceipt;
use engine::{Engine}; use engine::{Engine};
use trace::LocalizedTrace; use trace::LocalizedTrace;
@ -132,7 +132,7 @@ pub trait BlockChainClient : Sync + Send {
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>; fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
/// Makes a non-persistent transaction call. /// Makes a non-persistent transaction call.
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error>; fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
/// Attempt to seal the block internally. See `Engine`. /// Attempt to seal the block internally. See `Engine`.
fn generate_seal(&self, block: &ExecutedBlock, accounts: Option<&AccountProvider>) -> Option<Vec<Bytes>> { self.engine().generate_seal(block, accounts) } fn generate_seal(&self, block: &ExecutedBlock, accounts: Option<&AccountProvider>) -> Option<Vec<Bytes>> { self.engine().generate_seal(block, accounts) }

View File

@ -31,7 +31,7 @@ use error::{ImportResult};
use block_queue::BlockQueueInfo; use block_queue::BlockQueueInfo;
use block::{SealedBlock, ClosedBlock, LockedBlock}; use block::{SealedBlock, ClosedBlock, LockedBlock};
use executive::Executed; use executive::Executed;
use error::Error; use error::{ExecutionError};
use engine::Engine; use engine::Engine;
use trace::LocalizedTrace; use trace::LocalizedTrace;
@ -221,7 +221,7 @@ impl TestBlockChainClient {
} }
impl BlockChainClient for TestBlockChainClient { impl BlockChainClient for TestBlockChainClient {
fn call(&self, _t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
Ok(self.execution_result.read().unwrap().clone().unwrap()) Ok(self.execution_result.read().unwrap().clone().unwrap())
} }

View File

@ -82,7 +82,7 @@ impl<'a> Executive<'a> {
} }
/// This function should be used to execute transaction. /// This function should be used to execute transaction.
pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, Error> { pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, ExecutionError> {
let check = options.check_nonce; let check = options.check_nonce;
match options.tracing { match options.tracing {
true => self.transact_with_tracer(t, check, ExecutiveTracer::default()), true => self.transact_with_tracer(t, check, ExecutiveTracer::default()),
@ -91,8 +91,11 @@ impl<'a> Executive<'a> {
} }
/// Execute transaction/call with tracing enabled /// Execute transaction/call with tracing enabled
pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, Error> where T: Tracer { pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, ExecutionError> where T: Tracer {
let sender = try!(t.sender()); let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let nonce = self.state.nonce(&sender); let nonce = self.state.nonce(&sender);
let schedule = self.engine.schedule(self.info); let schedule = self.engine.schedule(self.info);
@ -946,8 +949,8 @@ mod tests {
}; };
match res { match res {
Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature))) => (), Err(ExecutionError::TransactionMalformed(_)) => (),
_ => assert!(false, "Expected invalid signature error.") _ => assert!(false, "Expected an invalid transaction error.")
} }
} }
@ -978,7 +981,7 @@ mod tests {
}; };
match res { match res {
Err(Error::Execution(ExecutionError::InvalidNonce { expected, got })) Err(ExecutionError::InvalidNonce { expected, got })
if expected == U256::zero() && got == U256::one() => (), if expected == U256::zero() && got == U256::one() => (),
_ => assert!(false, "Expected invalid nonce error.") _ => assert!(false, "Expected invalid nonce error.")
} }
@ -1012,7 +1015,7 @@ mod tests {
}; };
match res { match res {
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })) Err(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })
if gas_limit == U256::from(100_000) && gas_used == U256::from(20_000) && gas == U256::from(80_001) => (), if gas_limit == U256::from(100_000) && gas_used == U256::from(20_000) && gas == U256::from(80_001) => (),
_ => assert!(false, "Expected block gas limit error.") _ => assert!(false, "Expected block gas limit error.")
} }
@ -1046,7 +1049,7 @@ mod tests {
}; };
match res { match res {
Err(Error::Execution(ExecutionError::NotEnoughCash { required , got })) Err(ExecutionError::NotEnoughCash { required , got })
if required == U512::from(100_018) && got == U512::from(100_017) => (), if required == U512::from(100_018) && got == U512::from(100_017) => (),
_ => assert!(false, "Expected not enough cash error. {:?}", res) _ => assert!(false, "Expected not enough cash error. {:?}", res)
} }

View File

@ -99,7 +99,9 @@ pub enum ExecutionError {
got: U512 got: U512
}, },
/// Returned when internal evm error occurs. /// Returned when internal evm error occurs.
Internal Internal,
/// Returned when generic transaction occurs
TransactionMalformed(String),
} }

View File

@ -63,7 +63,7 @@ pub use external::{ExternalMiner, ExternalMinerService};
use util::{H256, U256, Address, Bytes}; use util::{H256, U256, Address, Bytes};
use ethcore::client::{BlockChainClient, Executed}; use ethcore::client::{BlockChainClient, Executed};
use ethcore::block::{ClosedBlock}; use ethcore::block::{ClosedBlock};
use ethcore::error::{Error}; use ethcore::error::{Error, ExecutionError};
use ethcore::transaction::SignedTransaction; use ethcore::transaction::SignedTransaction;
/// Miner client API /// Miner client API
@ -150,7 +150,7 @@ pub trait MinerService : Send + Sync {
fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256; fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256;
/// Call into contract code using pending state. /// Call into contract code using pending state.
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error>; fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
/// Get storage value in pending state. /// Get storage value in pending state.
fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256; fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256;

View File

@ -240,7 +240,7 @@ impl MinerService for Miner {
} }
} }
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
let sealing_work = self.sealing_work.lock().unwrap(); let sealing_work = self.sealing_work.lock().unwrap();
match sealing_work.peek_last_ref() { match sealing_work.peek_last_ref() {
Some(work) => { Some(work) => {
@ -258,7 +258,10 @@ impl MinerService for Miner {
}; };
// that's just a copy of the state. // that's just a copy of the state.
let mut state = block.state().clone(); let mut state = block.state().clone();
let sender = try!(t.sender()); let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let balance = state.balance(&sender); let balance = state.balance(&sender);
// give the sender max balance // give the sender max balance
state.sub_balance(&sender, &balance); state.sub_balance(&sender, &balance);

View File

@ -42,6 +42,9 @@ Account Options:
ACCOUNTS is a comma-delimited list of addresses. ACCOUNTS is a comma-delimited list of addresses.
--password FILE Provide a file containing a password for unlocking --password FILE Provide a file containing a password for unlocking
an account. an account.
--keys-iterations NUM Specify the number of iterations to use when deriving key
from the password (bigger is more secure)
[default: 10240].
Networking Options: Networking Options:
--port PORT Override the port on which the node should listen --port PORT Override the port on which the node should listen
@ -99,7 +102,9 @@ Sealing/Mining Options:
[default: 0.005]. The minimum gas price is set [default: 0.005]. The minimum gas price is set
accordingly. accordingly.
--usd-per-eth SOURCE USD value of a single ETH. SOURCE may be either an --usd-per-eth SOURCE USD value of a single ETH. SOURCE may be either an
amount in USD or a web service [default: etherscan]. amount in USD, a web service or 'auto' to use each
web service in turn and fallback on the last known
good value [default: auto].
--gas-floor-target GAS Amount of gas per block to target when sealing a new --gas-floor-target GAS Amount of gas per block to target when sealing a new
block [default: 4712388]. block [default: 4712388].
--author ADDRESS Specify the block author (aka "coinbase") address --author ADDRESS Specify the block author (aka "coinbase") address
@ -182,6 +187,7 @@ pub struct Args {
pub flag_password: Vec<String>, pub flag_password: Vec<String>,
pub flag_cache: Option<usize>, pub flag_cache: Option<usize>,
pub flag_keys_path: String, pub flag_keys_path: String,
pub flag_keys_iterations: u32,
pub flag_bootnodes: Option<String>, pub flag_bootnodes: Option<String>,
pub flag_network_id: Option<String>, pub flag_network_id: Option<String>,
pub flag_pruning: String, pub flag_pruning: String,

View File

@ -37,6 +37,11 @@ pub struct Configuration {
pub args: Args pub args: Args
} }
pub struct Directories {
pub keys: String,
pub db: String,
}
impl Configuration { impl Configuration {
pub fn parse() -> Self { pub fn parse() -> Self {
Configuration { Configuration {
@ -60,11 +65,6 @@ impl Configuration {
self.args.flag_maxpeers.unwrap_or(self.args.flag_peers) as u32 self.args.flag_maxpeers.unwrap_or(self.args.flag_peers) as u32
} }
pub fn path(&self) -> String {
let d = self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_db_path);
d.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
}
pub fn author(&self) -> Address { pub fn author(&self) -> Address {
let d = self.args.flag_etherbase.as_ref().unwrap_or(&self.args.flag_author); let d = self.args.flag_etherbase.as_ref().unwrap_or(&self.args.flag_author);
Address::from_str(clean_0x(d)).unwrap_or_else(|_| { Address::from_str(clean_0x(d)).unwrap_or_else(|_| {
@ -91,11 +91,18 @@ impl Configuration {
die!("{}: Invalid basic transaction price given in USD. Must be a decimal number.", self.args.flag_usd_per_tx) die!("{}: Invalid basic transaction price given in USD. Must be a decimal number.", self.args.flag_usd_per_tx)
}); });
let usd_per_eth = match self.args.flag_usd_per_eth.as_str() { let usd_per_eth = match self.args.flag_usd_per_eth.as_str() {
"auto" => PriceInfo::get().map_or_else(|| {
let last_known_good = 9.69696;
// TODO: use #1083 to read last known good value.
last_known_good
}, |x| x.ethusd),
"etherscan" => PriceInfo::get().map_or_else(|| { "etherscan" => PriceInfo::get().map_or_else(|| {
die!("Unable to retrieve USD value of ETH from etherscan. Rerun with a different value for --usd-per-eth.") die!("Unable to retrieve USD value of ETH from etherscan. Rerun with a different value for --usd-per-eth.")
}, |x| x.ethusd), }, |x| x.ethusd),
x => FromStr::from_str(x).unwrap_or_else(|_| die!("{}: Invalid ether price given in USD. Must be a decimal number.", x)) x => FromStr::from_str(x).unwrap_or_else(|_| die!("{}: Invalid ether price given in USD. Must be a decimal number.", x))
}; };
// TODO: use #1083 to write last known good value as use_per_eth.
let wei_per_usd: f32 = 1.0e18 / usd_per_eth; let wei_per_usd: f32 = 1.0e18 / usd_per_eth;
let gas_per_tx: f32 = 21000.0; let gas_per_tx: f32 = 21000.0;
let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx; let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx;
@ -113,10 +120,6 @@ impl Configuration {
} }
} }
pub fn keys_path(&self) -> String {
self.args.flag_keys_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
}
pub fn spec(&self) -> Spec { pub fn spec(&self) -> Spec {
match self.chain().as_str() { match self.chain().as_str() {
"frontier" | "homestead" | "mainnet" => ethereum::new_frontier(), "frontier" | "homestead" | "mainnet" => ethereum::new_frontier(),
@ -245,7 +248,7 @@ impl Configuration {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter() .into_iter()
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
let account_service = AccountService::new_in(Path::new(&self.keys_path())); let account_service = AccountService::with_security(Path::new(&self.keys_path()), self.keys_iterations());
if let Some(ref unlocks) = self.args.flag_unlock { if let Some(ref unlocks) = self.args.flag_unlock {
for d in unlocks.split(',') { for d in unlocks.split(',') {
let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| { let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| {
@ -263,23 +266,23 @@ impl Configuration {
self.args.flag_rpcapi.clone().unwrap_or(self.args.flag_jsonrpc_apis.clone()) self.args.flag_rpcapi.clone().unwrap_or(self.args.flag_jsonrpc_apis.clone())
} }
pub fn rpc_cors(&self) -> Option<String> { pub fn rpc_cors(&self) -> Vec<String> {
self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone()) let cors = self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone());
cors.map_or_else(Vec::new, |c| c.split(',').map(|s| s.to_owned()).collect())
} }
fn geth_ipc_path() -> &'static str { fn geth_ipc_path() -> String {
if cfg!(target_os = "macos") { path::ethereum::with_default("geth.ipc").to_str().unwrap().to_owned()
"$HOME/Library/Ethereum/geth.ipc" }
} else {
"$HOME/.ethereum/geth.ipc" pub fn keys_iterations(&self) -> u32 {
} self.args.flag_keys_iterations
} }
pub fn ipc_settings(&self) -> IpcConfiguration { pub fn ipc_settings(&self) -> IpcConfiguration {
IpcConfiguration { IpcConfiguration {
enabled: !(self.args.flag_ipcdisable || self.args.flag_ipc_off), enabled: !(self.args.flag_ipcdisable || self.args.flag_ipc_off),
socket_addr: if self.args.flag_geth { Self::geth_ipc_path().to_owned() } else { self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone()) } socket_addr: self.ipc_path(),
.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()),
apis: self.args.flag_ipcapi.clone().unwrap_or(self.args.flag_ipc_apis.clone()), apis: self.args.flag_ipcapi.clone().unwrap_or(self.args.flag_ipc_apis.clone()),
} }
} }
@ -296,6 +299,37 @@ impl Configuration {
rpc_port: self.args.flag_rpcport.unwrap_or(self.args.flag_jsonrpc_port), rpc_port: self.args.flag_rpcport.unwrap_or(self.args.flag_jsonrpc_port),
} }
} }
pub fn directories(&self) -> Directories {
let db_path = Configuration::replace_home(
&self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_db_path));
::std::fs::create_dir_all(&db_path).unwrap_or_else(|e| die_with_io_error("main", e));
let keys_path = Configuration::replace_home(&self.args.flag_keys_path);
::std::fs::create_dir_all(&db_path).unwrap_or_else(|e| die_with_io_error("main", e));
Directories {
keys: keys_path,
db: db_path,
}
}
pub fn keys_path(&self) -> String {
self.directories().keys
}
pub fn path(&self) -> String {
self.directories().db
}
fn replace_home(arg: &str) -> String {
arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
}
fn ipc_path(&self) -> String {
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())) }
}
} }
#[cfg(test)] #[cfg(test)]
@ -338,7 +372,7 @@ mod tests {
assert_eq!(net.rpc_enabled, true); assert_eq!(net.rpc_enabled, true);
assert_eq!(net.rpc_interface, "all".to_owned()); assert_eq!(net.rpc_interface, "all".to_owned());
assert_eq!(net.rpc_port, 8000); assert_eq!(net.rpc_port, 8000);
assert_eq!(conf.rpc_cors(), Some("*".to_owned())); assert_eq!(conf.rpc_cors(), vec!["*".to_owned()]);
assert_eq!(conf.rpc_apis(), "web3,eth".to_owned()); assert_eq!(conf.rpc_apis(), "web3,eth".to_owned());
} }

View File

@ -219,7 +219,7 @@ fn flush_stdout() {
fn execute_account_cli(conf: Configuration) { fn execute_account_cli(conf: Configuration) {
use util::keys::store::SecretStore; use util::keys::store::SecretStore;
use rpassword::read_password; use rpassword::read_password;
let mut secret_store = SecretStore::new_in(Path::new(&conf.keys_path())); let mut secret_store = SecretStore::with_security(Path::new(&conf.keys_path()), conf.keys_iterations());
if conf.args.cmd_new { if conf.args.cmd_new {
println!("Please note that password is NOT RECOVERABLE."); println!("Please note that password is NOT RECOVERABLE.");
print!("Type password: "); print!("Type password: ");

View File

@ -41,7 +41,7 @@ pub struct HttpConfiguration {
pub interface: String, pub interface: String,
pub port: u16, pub port: u16,
pub apis: String, pub apis: String,
pub cors: Option<String>, pub cors: Vec<String>,
} }
pub struct IpcConfiguration { pub struct IpcConfiguration {
@ -139,11 +139,11 @@ pub fn setup_http_rpc_server(
pub fn setup_http_rpc_server( pub fn setup_http_rpc_server(
dependencies: &Arc<Dependencies>, dependencies: &Arc<Dependencies>,
url: &SocketAddr, url: &SocketAddr,
cors_domain: Option<String>, cors_domains: Vec<String>,
apis: Vec<&str>, apis: Vec<&str>,
) -> RpcServer { ) -> RpcServer {
let server = setup_rpc_server(apis, dependencies); let server = setup_rpc_server(apis, dependencies);
let start_result = server.start_http(url, cors_domain); let start_result = server.start_http(url, cors_domains);
let deps = dependencies.clone(); let deps = dependencies.clone();
match start_result { match start_result {
Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err), Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err),

View File

@ -13,7 +13,7 @@ log = "0.3"
serde = "0.7.0" serde = "0.7.0"
serde_json = "0.7.0" serde_json = "0.7.0"
jsonrpc-core = "2.0" jsonrpc-core = "2.0"
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git" } jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git", branch = "multiple_cors_domains" }
ethcore-util = { path = "../util" } ethcore-util = { path = "../util" }
ethcore = { path = "../ethcore" } ethcore = { path = "../ethcore" }
ethash = { path = "../ethash" } ethash = { path = "../ethash" }

View File

@ -59,9 +59,11 @@ impl RpcServer {
} }
/// Start http server asynchronously and returns result with `Server` handle on success or an error. /// Start http server asynchronously and returns result with `Server` handle on success or an error.
pub fn start_http(&self, addr: &SocketAddr, cors_domain: Option<String>) -> Result<Server, RpcServerError> { pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec<String>) -> Result<Server, RpcServerError> {
let cors_domain = cors_domain.to_owned(); let cors_domains = cors_domains.into_iter()
Server::start(addr, self.handler.clone(), cors_domain.map(jsonrpc_http_server::AccessControlAllowOrigin::Value)) .map(jsonrpc_http_server::AccessControlAllowOrigin::Value)
.collect();
Server::start(addr, self.handler.clone(), cors_domains)
} }
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error. /// Start ipc server asynchronously and returns result with `Server` handle on success or an error.

View File

@ -18,7 +18,7 @@
use util::{Address, H256, Bytes, U256, FixedHash, Uint}; use util::{Address, H256, Bytes, U256, FixedHash, Uint};
use util::standard::*; use util::standard::*;
use ethcore::error::Error; use ethcore::error::{Error, ExecutionError};
use ethcore::client::{BlockChainClient, Executed}; use ethcore::client::{BlockChainClient, Executed};
use ethcore::block::{ClosedBlock, IsBlock}; use ethcore::block::{ClosedBlock, IsBlock};
use ethcore::transaction::SignedTransaction; use ethcore::transaction::SignedTransaction;
@ -179,7 +179,7 @@ impl MinerService for TestMinerService {
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone()) self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone())
} }
fn call(&self, _chain: &BlockChainClient, _t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, _chain: &BlockChainClient, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
unimplemented!(); unimplemented!();
} }

View File

@ -1193,7 +1193,7 @@ impl ChainSync {
let mut rlp_stream = RlpStream::new_list(route.blocks.len()); let mut rlp_stream = RlpStream::new_list(route.blocks.len());
for block_hash in route.blocks { for block_hash in route.blocks {
let mut hash_rlp = RlpStream::new_list(2); let mut hash_rlp = RlpStream::new_list(2);
let difficulty = chain.block_total_difficulty(BlockId::Hash(block_hash.clone())).expect("Mallformed block without a difficulty on the chain!"); let difficulty = chain.block_total_difficulty(BlockId::Hash(block_hash.clone())).expect("Malformed block without a difficulty on the chain!");
hash_rlp.append(&block_hash); hash_rlp.append(&block_hash);
hash_rlp.append(&difficulty); hash_rlp.append(&difficulty);
rlp_stream.append_raw(&hash_rlp.out(), 1); rlp_stream.append_raw(&hash_rlp.out(), 1);
@ -1570,7 +1570,7 @@ mod tests {
} }
#[test] #[test]
fn handles_peer_new_block_mallformed() { fn handles_peer_new_block_malformed() {
let mut client = TestBlockChainClient::new(); let mut client = TestBlockChainClient::new();
client.add_blocks(10, EachBlockWith::Uncle); client.add_blocks(10, EachBlockWith::Uncle);

View File

@ -381,7 +381,7 @@ impl KeyFileContent {
} }
} }
/// Loads key from valid json, returns error and records warning if key is mallformed /// Loads key from valid json, returns error and records warning if key is malformed
pub fn load(json: &Json) -> Result<KeyFileContent, ()> { pub fn load(json: &Json) -> Result<KeyFileContent, ()> {
match Self::from_json(json) { match Self::from_json(json) {
Ok(key_file) => Ok(key_file), Ok(key_file) => Ok(key_file),

View File

@ -20,6 +20,7 @@ use common::*;
use keys::store::SecretStore; use keys::store::SecretStore;
use keys::directory::KeyFileContent; use keys::directory::KeyFileContent;
use std::path::PathBuf; use std::path::PathBuf;
use path;
/// Enumerates all geth keys in the directory and returns collection of tuples `(accountId, filename)` /// Enumerates all geth keys in the directory and returns collection of tuples `(accountId, filename)`
pub fn enumerate_geth_keys(path: &Path) -> Result<Vec<(Address, String)>, ImportError> { pub fn enumerate_geth_keys(path: &Path) -> Result<Vec<(Address, String)>, ImportError> {
@ -98,30 +99,7 @@ pub fn import_geth_keys(secret_store: &mut SecretStore, geth_keyfiles_directory:
/// ///
/// Based on https://github.com/ethereum/go-ethereum/blob/e553215/common/path.go#L75 /// Based on https://github.com/ethereum/go-ethereum/blob/e553215/common/path.go#L75
pub fn keystore_dir() -> PathBuf { pub fn keystore_dir() -> PathBuf {
#[cfg(target_os = "macos")] path::ethereum::with_default("keystore")
fn data_dir(mut home: PathBuf) -> PathBuf {
home.push("Library");
home.push("Ethereum");
home
}
#[cfg(windows)]
fn data_dir(mut home: PathBuf) -> PathBuf {
home.push("AppData");
home.push("Roaming");
home.push("Ethereum");
home
}
#[cfg(not(any(target_os = "macos", windows)))]
fn data_dir(mut home: PathBuf) -> PathBuf {
home.push(".ethereum");
home
}
let mut data_dir = data_dir(::std::env::home_dir().expect("Failed to get home dir"));
data_dir.push("keystore");
data_dir
} }
#[cfg(test)] #[cfg(test)]

View File

@ -73,6 +73,7 @@ pub enum SigningError {
pub struct SecretStore { pub struct SecretStore {
directory: KeyDirectory, directory: KeyDirectory,
unlocks: RwLock<HashMap<Address, AccountUnlock>>, unlocks: RwLock<HashMap<Address, AccountUnlock>>,
key_iterations: u32,
} }
struct AccountUnlock { struct AccountUnlock {
@ -128,10 +129,15 @@ impl AccountProvider for AccountService {
impl AccountService { impl AccountService {
/// New account service with the keys store in specific location /// New account service with the keys store in specific location
pub fn new_in(path: &Path) -> Self { pub fn new_in(path: &Path) -> Self {
let secret_store = RwLock::new(SecretStore::new_in(path)); AccountService::with_security(path, KEY_ITERATIONS)
}
/// New account service with the keys store in specific location and configured security parameters
pub fn with_security(path: &Path, key_iterations: u32) -> Self {
let secret_store = RwLock::new(SecretStore::with_security(path, key_iterations));
secret_store.write().unwrap().try_import_existing(); secret_store.write().unwrap().try_import_existing();
AccountService { AccountService {
secret_store: secret_store secret_store: secret_store,
} }
} }
@ -157,10 +163,16 @@ impl AccountService {
impl SecretStore { impl SecretStore {
/// new instance of Secret Store in specific directory /// new instance of Secret Store in specific directory
pub fn new_in(path: &Path) -> Self { pub fn new_in(path: &Path) -> Self {
SecretStore::with_security(path, KEY_ITERATIONS)
}
/// new instance of Secret Store in specific directory and configured security parameters
pub fn with_security(path: &Path, key_iterations: u32) -> Self {
::std::fs::create_dir_all(&path).expect("Cannot access requested key directory - critical"); ::std::fs::create_dir_all(&path).expect("Cannot access requested key directory - critical");
SecretStore { SecretStore {
directory: KeyDirectory::new(path), directory: KeyDirectory::new(path),
unlocks: RwLock::new(HashMap::new()), unlocks: RwLock::new(HashMap::new()),
key_iterations: key_iterations,
} }
} }
@ -206,6 +218,7 @@ impl SecretStore {
SecretStore { SecretStore {
directory: KeyDirectory::new(path.as_path()), directory: KeyDirectory::new(path.as_path()),
unlocks: RwLock::new(HashMap::new()), unlocks: RwLock::new(HashMap::new()),
key_iterations: KEY_ITERATIONS,
} }
} }
@ -289,8 +302,8 @@ fn derive_key_iterations(password: &str, salt: &H256, c: u32) -> (Bytes, Bytes)
(derived_right_bits.to_vec(), derived_left_bits.to_vec()) (derived_right_bits.to_vec(), derived_left_bits.to_vec())
} }
fn derive_key(password: &str, salt: &H256) -> (Bytes, Bytes) { fn derive_key(password: &str, salt: &H256, iterations: u32) -> (Bytes, Bytes) {
derive_key_iterations(password, salt, KEY_ITERATIONS) derive_key_iterations(password, salt, iterations)
} }
fn derive_key_scrypt(password: &str, salt: &H256, n: u32, p: u32, r: u32) -> (Bytes, Bytes) { fn derive_key_scrypt(password: &str, salt: &H256, n: u32, p: u32, r: u32) -> (Bytes, Bytes) {
@ -346,7 +359,7 @@ impl EncryptedHashMap<H128> for SecretStore {
// two parts of derived key // two parts of derived key
// DK = [ DK[0..15] DK[16..31] ] = [derived_left_bits, derived_right_bits] // DK = [ DK[0..15] DK[16..31] ] = [derived_left_bits, derived_right_bits]
let (derived_left_bits, derived_right_bits) = derive_key(password, &salt); let (derived_left_bits, derived_right_bits) = derive_key(password, &salt, self.key_iterations);
let mut cipher_text = vec![0u8; value.as_slice().len()]; let mut cipher_text = vec![0u8; value.as_slice().len()];
// aes-128-ctr with initial vector of iv // aes-128-ctr with initial vector of iv
@ -361,7 +374,7 @@ impl EncryptedHashMap<H128> for SecretStore {
iv, iv,
salt, salt,
mac, mac,
KEY_ITERATIONS, self.key_iterations,
KEY_LENGTH)); KEY_LENGTH));
key_file.id = key; key_file.id = key;
if let Err(io_error) = self.directory.save(key_file) { if let Err(io_error) = self.directory.save(key_file) {

View File

@ -148,6 +148,7 @@ pub mod panics;
pub mod keys; pub mod keys;
pub mod table; pub mod table;
pub mod network_settings; pub mod network_settings;
pub mod path;
pub use common::*; pub use common::*;
pub use misc::*; pub use misc::*;

View File

@ -466,8 +466,8 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
io.register_stream(DISCOVERY).expect("Error registering UDP listener"); io.register_stream(DISCOVERY).expect("Error registering UDP listener");
io.register_timer(DISCOVERY_REFRESH, 7200).expect("Error registering discovery timer"); io.register_timer(DISCOVERY_REFRESH, 7200).expect("Error registering discovery timer");
io.register_timer(DISCOVERY_ROUND, 300).expect("Error registering discovery timer"); io.register_timer(DISCOVERY_ROUND, 300).expect("Error registering discovery timer");
io.register_timer(NODE_TABLE, 300_000).expect("Error registering node table timer");
} }
try!(io.register_timer(NODE_TABLE, 300_000));
try!(io.register_stream(TCP_ACCEPT)); try!(io.register_stream(TCP_ACCEPT));
Ok(()) Ok(())
} }
@ -509,6 +509,9 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
} }
fn connect_peers(&self, io: &IoContext<NetworkIoMessage<Message>>) { fn connect_peers(&self, io: &IoContext<NetworkIoMessage<Message>>) {
if self.info.read().unwrap().deref().capabilities.is_empty() {
return;
}
let ideal_peers = { self.info.read().unwrap().deref().config.ideal_peers }; let ideal_peers = { self.info.read().unwrap().deref().config.ideal_peers };
let pin = { self.info.read().unwrap().deref().config.pin }; let pin = { self.info.read().unwrap().deref().config.pin };
let session_count = self.session_count(); let session_count = self.session_count();

56
util/src/path.rs Normal file
View File

@ -0,0 +1,56 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Path utilities
/// Default ethereum paths
pub mod ethereum {
use std::path::PathBuf;
#[cfg(target_os = "macos")]
/// Default path for ethereum installation on Mac Os
pub fn default() -> PathBuf {
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
home.push("Library");
home.push("Ethereum");
home
}
#[cfg(windows)]
/// Default path for ethereum installation on Windows
pub fn default() -> PathBuf {
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
home.push("AppData");
home.push("Roaming");
home.push("Ethereum");
home
}
#[cfg(not(any(target_os = "macos", windows)))]
/// Default path for ethereum installation on posix system which is not Mac OS
pub fn default() -> PathBuf {
let mut home = ::std::env::home_dir().expect("Failed to get home dir");
home.push(".ethereum");
home
}
/// Get the specific folder inside default ethereum installation
pub fn with_default(s: &str) -> PathBuf {
let mut pth = default();
pth.push(s);
pth
}
}

View File

@ -18,7 +18,7 @@ ethcore-util = { path = "../util" }
parity-webapp = { git = "https://github.com/ethcore/parity-webapp.git" } parity-webapp = { git = "https://github.com/ethcore/parity-webapp.git" }
# List of apps # List of apps
parity-status = { git = "https://github.com/ethcore/parity-status.git", version = "0.3.7" } parity-status = { git = "https://github.com/ethcore/parity-status.git", version = "0.3.7" }
parity-wallet = { git = "https://github.com/ethcore/parity-wallet.git", version = "0.1.1", optional = true } parity-wallet = { git = "https://github.com/ethcore/parity-wallet.git", version = "0.2.0", optional = true }
clippy = { version = "0.0.64", optional = true} clippy = { version = "0.0.64", optional = true}
[features] [features]