From 516725abe4ad5d1182fef42e66ad36b466c10f00 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 21 Dec 2017 16:50:58 +0300 Subject: [PATCH] ok_or -> ok_or_else --- ethcore/src/engines/validator_set/contract.rs | 2 +- ethcore/src/engines/validator_set/multi.rs | 2 +- ethcore/src/engines/validator_set/safe_contract.rs | 2 +- parity/secretstore.rs | 2 +- secret_store/src/acl_storage.rs | 2 +- .../key_server_cluster/admin_sessions/share_add_session.rs | 2 +- .../key_server_cluster/admin_sessions/share_move_session.rs | 6 +++--- secret_store/src/key_storage.rs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index 54e86b98b..da35484c6 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -58,7 +58,7 @@ impl ValidatorContract { let client = self.client.read().clone(); Box::new(move |a, d| client.as_ref() .and_then(Weak::upgrade) - .ok_or("No client!".into()) + .ok_or_else(|| "No client!".into()) .and_then(|c| { match c.as_full_client() { Some(c) => c.transact_contract(a, d) diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 3f53b0363..c46cd2276 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -138,7 +138,7 @@ impl ValidatorSet for Multi { } *self.block_number.write() = Box::new(move |id| client .upgrade() - .ok_or("No client!".into()) + .ok_or_else(|| "No client!".into()) .and_then(|c| c.block_number(id).ok_or("Unknown block".into()))); } } diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 695f2a658..3fe9bda6d 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -311,7 +311,7 @@ impl ValidatorSet for ValidatorSafeContract { let client = self.client.read().clone(); Box::new(move |addr, data| client.as_ref() .and_then(Weak::upgrade) - .ok_or("No client!".into()) + .ok_or_else(|| "No client!".into()) .and_then(|c| { match c.as_full_client() { Some(c) => c.call_contract(id, addr, data), diff --git a/parity/secretstore.rs b/parity/secretstore.rs index 416c9d547..a3a55654f 100644 --- a/parity/secretstore.rs +++ b/parity/secretstore.rs @@ -121,7 +121,7 @@ mod server { // Attempt to sign in the engine signer. let password = deps.accounts_passwords.iter() .find(|p| deps.account_provider.sign(account.clone(), Some((*p).clone()), Default::default()).is_ok()) - .ok_or(format!("No valid password for the secret store node account {}", account))?; + .ok_or_else(|| format!("No valid password for the secret store node account {}", account))?; Arc::new(ethcore_secretstore::KeyStoreNodeKeyPair::new(deps.account_provider, account, password.clone()) .map_err(|e| format!("{}", e))?) }, diff --git a/secret_store/src/acl_storage.rs b/secret_store/src/acl_storage.rs index c06929e94..c8c46d5c0 100644 --- a/secret_store/src/acl_storage.rs +++ b/secret_store/src/acl_storage.rs @@ -111,7 +111,7 @@ impl CachedContract { let do_call = |a, d| future::done( self.client .upgrade() - .ok_or("Calling contract without client".into()) + .ok_or_else(|| "Calling contract without client".into()) .and_then(|c| c.call_contract(BlockId::Latest, a, d))); contract.check_permissions(do_call, address, document.clone()) .map_err(|err| Error::Internal(err)) diff --git a/secret_store/src/key_server_cluster/admin_sessions/share_add_session.rs b/secret_store/src/key_server_cluster/admin_sessions/share_add_session.rs index 040360d7d..433b49db6 100644 --- a/secret_store/src/key_server_cluster/admin_sessions/share_add_session.rs +++ b/secret_store/src/key_server_cluster/admin_sessions/share_add_session.rs @@ -258,7 +258,7 @@ impl SessionImpl where T: SessionTransport { let admin_public = self.core.admin_public.as_ref().cloned().ok_or(Error::ConsensusUnreachable)?; // key share version is required on ShareAdd master node - let key_share = self.core.key_share.as_ref().ok_or(Error::KeyStorage("key share is not found on master node".into()))?; + let key_share = self.core.key_share.as_ref().ok_or_else(|| Error::KeyStorage("key share is not found on master node".into()))?; let key_version = key_share.version(&version).map_err(|e| Error::KeyStorage(e.into()))?; // old nodes set is all non-isolated owners of version holders diff --git a/secret_store/src/key_server_cluster/admin_sessions/share_move_session.rs b/secret_store/src/key_server_cluster/admin_sessions/share_move_session.rs index d193e9efd..da75d095d 100644 --- a/secret_store/src/key_server_cluster/admin_sessions/share_move_session.rs +++ b/secret_store/src/key_server_cluster/admin_sessions/share_move_session.rs @@ -188,7 +188,7 @@ impl SessionImpl where T: SessionTransport { let is_consensus_pre_established = data.shares_to_move.is_some(); if !is_consensus_pre_established { let shares_to_move_reversed = shares_to_move_reversed.ok_or(Error::InvalidMessage)?; - let key_share = self.core.key_share.as_ref().ok_or(Error::KeyStorage("key share is not found on master node".into()))?; + let key_share = self.core.key_share.as_ref().ok_or_else(|| Error::KeyStorage("key share is not found on master node".into()))?; check_shares_to_move(&self.core.meta.self_node_id, &shares_to_move_reversed, Some(&key_share.id_numbers))?; let old_set_signature = old_set_signature.ok_or(Error::InvalidMessage)?; @@ -424,7 +424,7 @@ impl SessionImpl where T: SessionTransport { if !move_confirmations_to_receive.remove(sender) { return Err(Error::InvalidMessage); } - + if !move_confirmations_to_receive.is_empty() { return Ok(()); } @@ -818,7 +818,7 @@ mod tests { // check that session has completed on all nodes assert!(ml.nodes.values().all(|n| n.session.is_finished())); - + // check that secret is still the same as before adding the share check_secret_is_preserved(ml.original_key_pair.clone(), ml.nodes.iter() .filter(|&(k, _)| !shares_to_move.values().any(|v| v == k)) diff --git a/secret_store/src/key_storage.rs b/secret_store/src/key_storage.rs index fec58de2b..0997ea765 100644 --- a/secret_store/src/key_storage.rs +++ b/secret_store/src/key_storage.rs @@ -149,7 +149,7 @@ impl PersistentKeyStorage { pub fn new(config: &ServiceConfiguration) -> Result { let mut db_path = PathBuf::from(&config.data_path); db_path.push("db"); - let db_path = db_path.to_str().ok_or(Error::Database("Invalid secretstore path".to_owned()))?; + let db_path = db_path.to_str().ok_or_else(|| Error::Database("Invalid secretstore path".to_owned()))?; let db = Database::open_default(&db_path)?; let db = upgrade_db(db)?;