Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #922 from ethcore/beta-staging
Browse files Browse the repository at this point in the history
Master to beta v1.0.2
  • Loading branch information
debris committed Apr 11, 2016
2 parents e179b0e + 8f63f6d commit 70389b2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 50 deletions.
20 changes: 11 additions & 9 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ Protocol Options:
--identity NAME Specify your node's name.
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
an account.
Expand Down Expand Up @@ -185,7 +186,7 @@ struct Args {
flag_chain: String,
flag_db_path: String,
flag_identity: String,
flag_unlock: Vec<String>,
flag_unlock: Option<String>,
flag_password: Vec<String>,
flag_cache: Option<usize>,
flag_keys_path: String,
Expand Down Expand Up @@ -518,14 +519,15 @@ impl Configuration {
.collect::<Vec<_>>()
.into_iter()
}).collect::<Vec<_>>();

let account_service = AccountService::new_in(Path::new(&self.keys_path()));
for d in &self.args.flag_unlock {
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 let Some(ref unlocks) = self.args.flag_unlock {
for d in unlocks.split(',') {
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);
}
}
}
account_service
Expand Down
1 change: 0 additions & 1 deletion rpc/src/v1/helpers/poll_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl<F, T> PollManager<F, T> where T: Timer {
}

// Implementation is always using `poll_mut`
#[cfg(test)]
/// Get a reference to stored poll filter
pub fn poll(&mut self, id: &PollId) -> Option<&F> {
self.polls.prune();
Expand Down
31 changes: 23 additions & 8 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,9 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
let hash = signed_transaction.hash();

let import = {
let miner = take_weak!(self.miner);
let client = take_weak!(self.client);
take_weak!(self.miner).import_transactions(vec![signed_transaction], |a: &Address| AccountDetails {
nonce: miner
.last_nonce(a)
.map(|nonce| nonce + U256::one())
.unwrap_or_else(|| client.nonce(a)),
nonce: client.nonce(a),
balance: client.balance(a),
})
};
Expand Down Expand Up @@ -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> {
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 client = take_weak!(self.client);
let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()];
Expand Down Expand Up @@ -635,10 +631,11 @@ impl<C, M> EthFilter for EthFilterClient<C, M>

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.to_block = BlockId::Latest;
let logs = client.logs(filter.clone())
let logs = client.logs(filter)
.into_iter()
.map(From::from)
.collect::<Vec<Log>>();
Expand All @@ -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> {
from_params::<(Index,)>(params)
.and_then(|(index,)| {
Expand Down
5 changes: 4 additions & 1 deletion rpc/src/v1/traits/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ pub trait EthFilter: Sized + Send + Sync + 'static {
/// Returns filter changes since last poll.
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.
fn uninstall_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }

Expand All @@ -200,7 +203,7 @@ pub trait EthFilter: Sized + Send + Sync + 'static {
delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter);
delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter);
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
}
Expand Down
32 changes: 1 addition & 31 deletions util/src/keys/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,7 @@ impl AccountProvider for AccountService {
}
}

impl Default for AccountService {
fn default() -> Self {
AccountService::new()
}
}

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
pub fn new_in(path: &Path) -> Self {
let secret_store = RwLock::new(SecretStore::new_in(path));
Expand Down Expand Up @@ -165,25 +150,10 @@ impl AccountService {
}
}


impl Default for SecretStore {
fn default() -> Self {
SecretStore::new()
}
}

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
pub fn new_in(path: &Path) -> Self {
::std::fs::create_dir_all(&path).expect("Cannot access requested key directory - critical");
SecretStore {
directory: KeyDirectory::new(path),
unlocks: RwLock::new(HashMap::new()),
Expand Down

0 comments on commit 70389b2

Please sign in to comment.