From 59e87b6a5128c15a9cac55fba355295b2daf5477 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Tue, 4 Jul 2017 17:01:06 +0200 Subject: [PATCH] Clean up function naming in RPC error module --- rpc/src/v1/helpers/dispatch.rs | 12 ++++++------ rpc/src/v1/helpers/errors.rs | 18 +++++++++--------- rpc/src/v1/helpers/ipfs.rs | 2 +- rpc/src/v1/helpers/secretstore.rs | 6 +++--- rpc/src/v1/impls/eth.rs | 18 +++++++++--------- rpc/src/v1/impls/light/eth.rs | 8 ++++---- rpc/src/v1/impls/light/parity.rs | 2 +- rpc/src/v1/impls/light/parity_set.rs | 4 ++-- rpc/src/v1/impls/parity.rs | 2 +- rpc/src/v1/impls/parity_set.rs | 6 +++--- rpc/src/v1/impls/signer.rs | 2 +- rpc/src/v1/impls/traces.rs | 8 ++++---- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index ce978422d..ff950d346 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -162,7 +162,7 @@ impl Dispatcher for FullDispatcher accounts.sign(address, Some(pass), hash).map(WithToken::No), SignWith::Token(token) => accounts.sign_with_token(address, token, hash).map(Into::into), }.map_err(|e| match password { - SignWith::Nothing => errors::from_signing_error(e), - _ => errors::from_password_error(e), + SignWith::Nothing => errors::signing(e), + _ => errors::password(e), }) } @@ -570,8 +570,8 @@ fn decrypt(accounts: &AccountProvider, address: Address, msg: Bytes, password: S SignWith::Password(pass) => accounts.decrypt(address, Some(pass), &DEFAULT_MAC, &msg).map(WithToken::No), SignWith::Token(token) => accounts.decrypt_with_token(address, token, &DEFAULT_MAC, &msg).map(Into::into), }.map_err(|e| match password { - SignWith::Nothing => errors::from_signing_error(e), - _ => errors::from_password_error(e), + SignWith::Nothing => errors::signing(e), + _ => errors::password(e), }) } diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index df7d65067..30e6d7f94 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -221,7 +221,7 @@ pub fn network_disabled() -> Error { } } -pub fn encryption_error(error: T) -> Error { +pub fn encryption(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::ENCRYPTION_ERROR), message: "Encryption error.".into(), @@ -229,7 +229,7 @@ pub fn encryption_error(error: T) -> Error { } } -pub fn encoding_error(error: T) -> Error { +pub fn encoding(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::ENCODING_ERROR), message: "Encoding error.".into(), @@ -237,7 +237,7 @@ pub fn encoding_error(error: T) -> Error { } } -pub fn database_error(error: T) -> Error { +pub fn database(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::DATABASE_ERROR), message: "Database error.".into(), @@ -245,7 +245,7 @@ pub fn database_error(error: T) -> Error { } } -pub fn from_fetch_error(error: T) -> Error { +pub fn fetch(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::FETCH_ERROR), message: "Error while fetching content.".into(), @@ -253,7 +253,7 @@ pub fn from_fetch_error(error: T) -> Error { } } -pub fn from_signing_error(error: AccountError) -> Error { +pub fn signing(error: AccountError) -> Error { Error { code: ErrorCode::ServerError(codes::ACCOUNT_LOCKED), message: "Your account is locked. Unlock the account via CLI, personal_unlockAccount or use Trusted Signer.".into(), @@ -261,7 +261,7 @@ pub fn from_signing_error(error: AccountError) -> Error { } } -pub fn from_password_error(error: AccountError) -> Error { +pub fn password(error: AccountError) -> Error { Error { code: ErrorCode::ServerError(codes::PASSWORD_INVALID), message: "Account password is invalid or account does not exist.".into(), @@ -301,7 +301,7 @@ pub fn transaction_message(error: TransactionError) -> String { } } -pub fn from_transaction_error(error: EthcoreError) -> Error { +pub fn transaction(error: EthcoreError) -> Error { if let EthcoreError::Transaction(e) = error { Error { @@ -318,7 +318,7 @@ pub fn from_transaction_error(error: EthcoreError) -> Error { } } -pub fn from_rlp_error(error: DecoderError) -> Error { +pub fn rlp(error: DecoderError) -> Error { Error { code: ErrorCode::InvalidParams, message: "Invalid RLP.".into(), @@ -326,7 +326,7 @@ pub fn from_rlp_error(error: DecoderError) -> Error { } } -pub fn from_call_error(error: CallError) -> Error { +pub fn call(error: CallError) -> Error { match error { CallError::StatePruned => state_pruned(), CallError::StateCorrupt => state_corrupt(), diff --git a/rpc/src/v1/helpers/ipfs.rs b/rpc/src/v1/helpers/ipfs.rs index 53aa4be35..80ad1c207 100644 --- a/rpc/src/v1/helpers/ipfs.rs +++ b/rpc/src/v1/helpers/ipfs.rs @@ -32,7 +32,7 @@ pub fn cid(content: Bytes) -> Result { let mut buf = Vec::with_capacity(len); buf.resize(len, 0); hasher.result(&mut buf); - let mh = multihash::encode(multihash::Hash::SHA2256, &buf).map_err(errors::encoding_error)?; + let mh = multihash::encode(multihash::Hash::SHA2256, &buf).map_err(errors::encoding)?; let cid = Cid::new(Codec::DagProtobuf, Version::V0, &mh); Ok(cid.to_string().into()) } diff --git a/rpc/src/v1/helpers/secretstore.rs b/rpc/src/v1/helpers/secretstore.rs index 43c2c8943..9563302d9 100644 --- a/rpc/src/v1/helpers/secretstore.rs +++ b/rpc/src/v1/helpers/secretstore.rs @@ -86,13 +86,13 @@ fn decrypt_with_shadow_coefficients(mut decrypted_shadow: Public, mut common_sha let mut shadow_coefficients_sum = shadow_coefficients[0].clone(); for shadow_coefficient in shadow_coefficients.iter().skip(1) { shadow_coefficients_sum.add(shadow_coefficient) - .map_err(errors::encryption_error)?; + .map_err(errors::encryption)?; } math::public_mul_secret(&mut common_shadow_point, &shadow_coefficients_sum) - .map_err(errors::encryption_error)?; + .map_err(errors::encryption)?; math::public_add(&mut decrypted_shadow, &common_shadow_point) - .map_err(errors::encryption_error)?; + .map_err(errors::encryption)?; Ok(decrypted_shadow) } diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 499b0a15f..24b41bd6f 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -365,7 +365,7 @@ impl Eth for EthClient where BlockNumber::Pending => { match self.miner.balance(&*self.client, &address) { Some(balance) => Ok(balance.into()), - None => Err(errors::database_error("latest balance missing")) + None => Err(errors::database("latest balance missing")) } } id => { @@ -388,7 +388,7 @@ impl Eth for EthClient where BlockNumber::Pending => { match self.miner.storage_at(&*self.client, &address, &H256::from(position)) { Some(s) => Ok(s.into()), - None => Err(errors::database_error("latest storage missing")) + None => Err(errors::database("latest storage missing")) } } id => { @@ -413,13 +413,13 @@ impl Eth for EthClient where .or_else(|| self.miner.nonce(&*self.client, &address)); match nonce { Some(nonce) => Ok(nonce.into()), - None => Err(errors::database_error("latest nonce missing")) + None => Err(errors::database("latest nonce missing")) } } BlockNumber::Pending => { match self.miner.nonce(&*self.client, &address) { Some(nonce) => Ok(nonce.into()), - None => Err(errors::database_error("latest nonce missing")) + None => Err(errors::database("latest nonce missing")) } } id => { @@ -472,7 +472,7 @@ impl Eth for EthClient where BlockNumber::Pending => { match self.miner.code(&*self.client, &address) { Some(code) => Ok(code.map_or_else(Bytes::default, Bytes::new)), - None => Err(errors::database_error("latest code missing")) + None => Err(errors::database("latest code missing")) } } id => { @@ -618,8 +618,8 @@ impl Eth for EthClient where fn send_raw_transaction(&self, raw: Bytes) -> Result { UntrustedRlp::new(&raw.into_vec()).as_val() - .map_err(errors::from_rlp_error) - .and_then(|tx| SignedTransaction::new(tx).map_err(errors::from_transaction_error)) + .map_err(errors::rlp) + .and_then(|tx| SignedTransaction::new(tx).map_err(errors::transaction)) .and_then(|signed_transaction| { FullDispatcher::new(self.client.clone(), self.miner.clone()) .dispatch_transaction(signed_transaction.into()) @@ -645,7 +645,7 @@ impl Eth for EthClient where future::done(result .map(|b| b.output.into()) - .map_err(errors::from_call_error) + .map_err(errors::call) ).boxed() } @@ -657,7 +657,7 @@ impl Eth for EthClient where }; future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into()) .map(Into::into) - .map_err(errors::from_call_error) + .map_err(errors::call) ).boxed() } diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index f50dd82ab..fd03f1226 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -363,18 +363,18 @@ impl Eth for EthClient { let best_header = self.client.best_block_header().decode(); UntrustedRlp::new(&raw.into_vec()).as_val() - .map_err(errors::from_rlp_error) + .map_err(errors::rlp) .and_then(|tx| { self.client.engine().verify_transaction_basic(&tx, &best_header) - .map_err(errors::from_transaction_error)?; + .map_err(errors::transaction)?; - let signed = SignedTransaction::new(tx).map_err(errors::from_transaction_error)?; + let signed = SignedTransaction::new(tx).map_err(errors::transaction)?; let hash = signed.hash(); self.transaction_queue.write().import(signed.into()) .map(|_| hash) .map_err(Into::into) - .map_err(errors::from_transaction_error) + .map_err(errors::transaction) }) .map(Into::into) } diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 273c958fe..481cdb136 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -241,7 +241,7 @@ impl Parity for ParityClient { fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result { ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0) - .map_err(errors::encryption_error) + .map_err(errors::encryption) .map(Into::into) } diff --git a/rpc/src/v1/impls/light/parity_set.rs b/rpc/src/v1/impls/light/parity_set.rs index cab2fa91c..fdeee693f 100644 --- a/rpc/src/v1/impls/light/parity_set.rs +++ b/rpc/src/v1/impls/light/parity_set.rs @@ -127,9 +127,9 @@ impl ParitySet for ParitySetClient { fn hash_content(&self, url: String) -> BoxFuture { self.fetch.process(self.fetch.fetch(&url).then(move |result| { result - .map_err(errors::from_fetch_error) + .map_err(errors::fetch) .and_then(|response| { - sha3(&mut io::BufReader::new(response)).map_err(errors::from_fetch_error) + sha3(&mut io::BufReader::new(response)).map_err(errors::fetch) }) .map(Into::into) })) diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index c9dbf54a6..2cffdd4e6 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -284,7 +284,7 @@ impl Parity for ParityClient where fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result { ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0) - .map_err(errors::encryption_error) + .map_err(errors::encryption) .map(Into::into) } diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index 4be41f7c1..dc771c4f8 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -101,7 +101,7 @@ impl ParitySet for ParitySetClient where } fn set_engine_signer(&self, address: H160, password: String) -> Result { - self.miner.set_engine_signer(address.into(), password).map_err(Into::into).map_err(errors::from_password_error)?; + self.miner.set_engine_signer(address.into(), password).map_err(Into::into).map_err(errors::password)?; Ok(true) } @@ -168,9 +168,9 @@ impl ParitySet for ParitySetClient where fn hash_content(&self, url: String) -> BoxFuture { self.fetch.process(self.fetch.fetch(&url).then(move |result| { result - .map_err(errors::from_fetch_error) + .map_err(errors::fetch) .and_then(|response| { - sha3(&mut io::BufReader::new(response)).map_err(errors::from_fetch_error) + sha3(&mut io::BufReader::new(response)).map_err(errors::fetch) }) .map(Into::into) })) diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index d0b1b7a3c..79f4f0e38 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -133,7 +133,7 @@ impl SignerClient { fn verify_transaction(bytes: Bytes, request: FilledTransactionRequest, process: F) -> Result where F: FnOnce(PendingTransaction) -> Result, { - let signed_transaction = UntrustedRlp::new(&bytes.0).as_val().map_err(errors::from_rlp_error)?; + let signed_transaction = UntrustedRlp::new(&bytes.0).as_val().map_err(errors::rlp)?; let signed_transaction = SignedTransaction::new(signed_transaction).map_err(|e| errors::invalid_params("Invalid signature.", e))?; let sender = signed_transaction.sender(); diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index 705ad9cab..2c65f4403 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -87,23 +87,23 @@ impl Traces for TracesClient where C: MiningBlockChainClient + 'stat self.client.call(&signed, block.into(), to_call_analytics(flags)) .map(TraceResults::from) - .map_err(errors::from_call_error) + .map_err(errors::call) } fn raw_transaction(&self, raw_transaction: Bytes, flags: Vec, block: Trailing) -> Result { let block = block.unwrap_or_default(); let tx = UntrustedRlp::new(&raw_transaction.into_vec()).as_val().map_err(|e| errors::invalid_params("Transaction is not valid RLP", e))?; - let signed = SignedTransaction::new(tx).map_err(errors::from_transaction_error)?; + let signed = SignedTransaction::new(tx).map_err(errors::transaction)?; self.client.call(&signed, block.into(), to_call_analytics(flags)) .map(TraceResults::from) - .map_err(errors::from_call_error) + .map_err(errors::call) } fn replay_transaction(&self, transaction_hash: H256, flags: Vec) -> Result { self.client.replay(TransactionId::Hash(transaction_hash.into()), to_call_analytics(flags)) .map(TraceResults::from) - .map_err(errors::from_call_error) + .map_err(errors::call) } }