diff --git a/rpc/src/v1/helpers/poll_manager.rs b/rpc/src/v1/helpers/poll_manager.rs index 9735d7d5d..bc3518830 100644 --- a/rpc/src/v1/helpers/poll_manager.rs +++ b/rpc/src/v1/helpers/poll_manager.rs @@ -61,7 +61,6 @@ impl PollManager 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(); diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 5ecbfefa2..1d973f933 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -636,10 +636,11 @@ impl EthFilter for EthFilterClient 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::>(); @@ -654,6 +655,24 @@ impl EthFilter for EthFilterClient }) } + fn filter_logs(&self, params: Params) -> Result { + 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::>(); + to_value(&logs) + }, + // just empty array + _ => Ok(Value::Array(vec![] as Vec)), + } + }) + } + fn uninstall_filter(&self, params: Params) -> Result { from_params::<(Index,)>(params) .and_then(|(index,)| { diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index 5d36da670..a28f72c5c 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -190,6 +190,9 @@ pub trait EthFilter: Sized + Send + Sync + 'static { /// Returns filter changes since last poll. fn filter_changes(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Returns all logs matching given filter (in a range 'from' - 'to'). + fn filter_logs(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Uninstalls filter. fn uninstall_filter(&self, _: Params) -> Result { 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_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 } diff --git a/util/src/keys/store.rs b/util/src/keys/store.rs index 5dec27fc3..36edb0ff1 100644 --- a/util/src/keys/store.rs +++ b/util/src/keys/store.rs @@ -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)); @@ -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()),