Merge pull request #922 from ethcore/beta-staging

Master to beta v1.0.2
This commit is contained in:
Marek Kotewicz 2016-04-11 16:42:09 +02:00
commit 70389b2888
5 changed files with 39 additions and 50 deletions

View File

@ -94,7 +94,8 @@ Protocol Options:
--identity NAME Specify your node's name. --identity NAME Specify your node's name.
Account Options: Account Options:
--unlock ACCOUNT Unlock ACCOUNT for the duration of the execution. --unlock ACCOUNTS Unlock ACCOUNTS for the duration of the execution.
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.
@ -185,7 +186,7 @@ struct Args {
flag_chain: String, flag_chain: String,
flag_db_path: String, flag_db_path: String,
flag_identity: String, flag_identity: String,
flag_unlock: Vec<String>, flag_unlock: Option<String>,
flag_password: Vec<String>, flag_password: Vec<String>,
flag_cache: Option<usize>, flag_cache: Option<usize>,
flag_keys_path: String, flag_keys_path: String,
@ -518,14 +519,15 @@ 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::new_in(Path::new(&self.keys_path()));
for d in &self.args.flag_unlock { if let Some(ref unlocks) = self.args.flag_unlock {
let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| { for d in unlocks.split(',') {
die!("{}: Invalid address for --unlock. Must be 40 hex characters, without the 0x at the beginning.", d) let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| {
}); die!("{}: Invalid address for --unlock. Must be 40 hex characters, without the 0x at the beginning.", d)
if passwords.iter().find(|p| account_service.unlock_account_no_expire(&a, p).is_ok()).is_none() { });
die!("No password given to unlock account {}. Pass the password using `--password`.", a); if passwords.iter().find(|p| account_service.unlock_account_no_expire(&a, p).is_ok()).is_none() {
die!("No password given to unlock account {}. Pass the password using `--password`.", a);
}
} }
} }
account_service account_service

View File

@ -61,7 +61,6 @@ impl<F, T> PollManager<F, T> where T: Timer {
} }
// Implementation is always using `poll_mut` // Implementation is always using `poll_mut`
#[cfg(test)]
/// Get a reference to stored poll filter /// Get a reference to stored poll filter
pub fn poll(&mut self, id: &PollId) -> Option<&F> { pub fn poll(&mut self, id: &PollId) -> Option<&F> {
self.polls.prune(); self.polls.prune();

View File

@ -184,13 +184,9 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
let hash = signed_transaction.hash(); let hash = signed_transaction.hash();
let import = { let import = {
let miner = take_weak!(self.miner);
let client = take_weak!(self.client); let client = take_weak!(self.client);
take_weak!(self.miner).import_transactions(vec![signed_transaction], |a: &Address| AccountDetails { take_weak!(self.miner).import_transactions(vec![signed_transaction], |a: &Address| AccountDetails {
nonce: miner nonce: client.nonce(a),
.last_nonce(a)
.map(|nonce| nonce + U256::one())
.unwrap_or_else(|| client.nonce(a)),
balance: client.balance(a), balance: client.balance(a),
}) })
}; };
@ -464,7 +460,7 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
fn submit_work(&self, params: Params) -> Result<Value, Error> { fn submit_work(&self, params: Params) -> Result<Value, Error> {
from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| { from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| {
// trace!("Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash); trace!(target: "miner", "submit_work: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash);
let miner = take_weak!(self.miner); let miner = take_weak!(self.miner);
let client = take_weak!(self.client); let client = take_weak!(self.client);
let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()]; let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()];
@ -635,10 +631,11 @@ impl<C, M> EthFilter for EthFilterClient<C, M>
to_value(&diff) to_value(&diff)
}, },
PollFilter::Logs(ref mut block_number, ref mut filter) => { PollFilter::Logs(ref mut block_number, ref filter) => {
let mut filter = filter.clone();
filter.from_block = BlockId::Number(*block_number); filter.from_block = BlockId::Number(*block_number);
filter.to_block = BlockId::Latest; filter.to_block = BlockId::Latest;
let logs = client.logs(filter.clone()) let logs = client.logs(filter)
.into_iter() .into_iter()
.map(From::from) .map(From::from)
.collect::<Vec<Log>>(); .collect::<Vec<Log>>();
@ -653,6 +650,24 @@ impl<C, M> EthFilter for EthFilterClient<C, M>
}) })
} }
fn filter_logs(&self, params: Params) -> Result<Value, Error> {
from_params::<(Index,)>(params)
.and_then(|(index,)| {
let mut polls = self.polls.lock().unwrap();
match polls.poll(&index.value()) {
Some(&PollFilter::Logs(ref _block_number, ref filter)) => {
let logs = take_weak!(self.client).logs(filter.clone())
.into_iter()
.map(From::from)
.collect::<Vec<Log>>();
to_value(&logs)
},
// just empty array
_ => Ok(Value::Array(vec![] as Vec<Value>)),
}
})
}
fn uninstall_filter(&self, params: Params) -> Result<Value, Error> { fn uninstall_filter(&self, params: Params) -> Result<Value, Error> {
from_params::<(Index,)>(params) from_params::<(Index,)>(params)
.and_then(|(index,)| { .and_then(|(index,)| {

View File

@ -190,6 +190,9 @@ pub trait EthFilter: Sized + Send + Sync + 'static {
/// Returns filter changes since last poll. /// Returns filter changes since last poll.
fn filter_changes(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } fn filter_changes(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns all logs matching given filter (in a range 'from' - 'to').
fn filter_logs(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Uninstalls filter. /// Uninstalls filter.
fn uninstall_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } fn uninstall_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
@ -200,7 +203,7 @@ pub trait EthFilter: Sized + Send + Sync + 'static {
delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter); delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter);
delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter); delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter);
delegate.add_method("eth_getFilterChanges", EthFilter::filter_changes); delegate.add_method("eth_getFilterChanges", EthFilter::filter_changes);
delegate.add_method("eth_getFilterLogs", EthFilter::filter_changes); delegate.add_method("eth_getFilterLogs", EthFilter::filter_logs);
delegate.add_method("eth_uninstallFilter", EthFilter::uninstall_filter); delegate.add_method("eth_uninstallFilter", EthFilter::uninstall_filter);
delegate delegate
} }

View File

@ -121,22 +121,7 @@ impl AccountProvider for AccountService {
} }
} }
impl Default for AccountService {
fn default() -> Self {
AccountService::new()
}
}
impl AccountService { impl AccountService {
/// New account service with the keys store in default location
pub fn new() -> Self {
let secret_store = RwLock::new(SecretStore::new());
secret_store.write().unwrap().try_import_existing();
AccountService {
secret_store: secret_store
}
}
/// 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)); let secret_store = RwLock::new(SecretStore::new_in(path));
@ -165,25 +150,10 @@ impl AccountService {
} }
} }
impl Default for SecretStore {
fn default() -> Self {
SecretStore::new()
}
}
impl SecretStore { impl SecretStore {
/// new instance of Secret Store in default home directory
pub fn new() -> Self {
let mut path = ::std::env::home_dir().expect("Failed to get home dir");
path.push(".parity");
path.push("keys");
::std::fs::create_dir_all(&path).expect("Should panic since it is critical to be able to access home dir");
Self::new_in(&path)
}
/// 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 {
::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()),