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

Clean up function naming in RPC error module #5995

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions rpc/src/v1/helpers/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<C: MiningBlockChainClient, M: MinerService> Dispatcher for FullDispatcher<C
let hash = signed_transaction.transaction.hash();

self.miner.import_own_transaction(&*self.client, signed_transaction)
.map_err(errors::from_transaction_error)
.map_err(errors::transaction)
.map(|_| hash)
}
}
Expand Down Expand Up @@ -400,7 +400,7 @@ impl Dispatcher for LightDispatcher {

self.transaction_queue.write().import(signed_transaction)
.map_err(Into::into)
.map_err(errors::from_transaction_error)
.map_err(errors::transaction)
.map(|_| hash)
}
}
Expand Down Expand Up @@ -538,8 +538,8 @@ fn signature(accounts: &AccountProvider, address: Address, hash: H256, password:
SignWith::Password(pass) => 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),
})
}

Expand Down Expand Up @@ -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),
})
}

Expand Down
18 changes: 9 additions & 9 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,47 +221,47 @@ pub fn network_disabled() -> Error {
}
}

pub fn encryption_error<T: fmt::Debug>(error: T) -> Error {
pub fn encryption<T: fmt::Debug>(error: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::ENCRYPTION_ERROR),
message: "Encryption error.".into(),
data: Some(Value::String(format!("{:?}", error))),
}
}

pub fn encoding_error<T: fmt::Debug>(error: T) -> Error {
pub fn encoding<T: fmt::Debug>(error: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::ENCODING_ERROR),
message: "Encoding error.".into(),
data: Some(Value::String(format!("{:?}", error))),
}
}

pub fn database_error<T: fmt::Debug>(error: T) -> Error {
pub fn database<T: fmt::Debug>(error: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::DATABASE_ERROR),
message: "Database error.".into(),
data: Some(Value::String(format!("{:?}", error))),
}
}

pub fn from_fetch_error<T: fmt::Debug>(error: T) -> Error {
pub fn fetch<T: fmt::Debug>(error: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::FETCH_ERROR),
message: "Error while fetching content.".into(),
data: Some(Value::String(format!("{:?}", 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(),
data: Some(Value::String(format!("{:?}", 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(),
Expand Down Expand Up @@ -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 {
Expand All @@ -318,15 +318,15 @@ 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(),
data: Some(Value::String(format!("{:?}", 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(),
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/helpers/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn cid(content: Bytes) -> Result<String, Error> {
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())
}
6 changes: 3 additions & 3 deletions rpc/src/v1/helpers/secretstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
18 changes: 9 additions & 9 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> 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 => {
Expand All @@ -388,7 +388,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> 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 => {
Expand All @@ -413,13 +413,13 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> 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 => {
Expand Down Expand Up @@ -472,7 +472,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> 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 => {
Expand Down Expand Up @@ -618,8 +618,8 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where

fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
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())
Expand All @@ -645,7 +645,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where

future::done(result
.map(|b| b.output.into())
.map_err(errors::from_call_error)
.map_err(errors::call)
).boxed()
}

Expand All @@ -657,7 +657,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> 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()
}

Expand Down
8 changes: 4 additions & 4 deletions rpc/src/v1/impls/light/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/impls/light/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl Parity for ParityClient {

fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result<Bytes, Error> {
ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0)
.map_err(errors::encryption_error)
.map_err(errors::encryption)
.map(Into::into)
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/src/v1/impls/light/parity_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ impl<F: Fetch> ParitySet for ParitySetClient<F> {
fn hash_content(&self, url: String) -> BoxFuture<H256, Error> {
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)
}))
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/impls/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where

fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result<Bytes, Error> {
ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0)
.map_err(errors::encryption_error)
.map_err(errors::encryption)
.map(Into::into)
}

Expand Down
6 changes: 3 additions & 3 deletions rpc/src/v1/impls/parity_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<C, M, U, F> ParitySet for ParitySetClient<C, M, U, F> where
}

fn set_engine_signer(&self, address: H160, password: String) -> Result<bool, Error> {
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)
}

Expand Down Expand Up @@ -168,9 +168,9 @@ impl<C, M, U, F> ParitySet for ParitySetClient<C, M, U, F> where
fn hash_content(&self, url: String) -> BoxFuture<H256, Error> {
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)
}))
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/impls/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<D: Dispatcher + 'static> SignerClient<D> {
fn verify_transaction<F>(bytes: Bytes, request: FilledTransactionRequest, process: F) -> Result<ConfirmationResponse, Error> where
F: FnOnce(PendingTransaction) -> Result<ConfirmationResponse, Error>,
{
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();

Expand Down
8 changes: 4 additions & 4 deletions rpc/src/v1/impls/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ impl<C, M> Traces for TracesClient<C, M> 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<String>, block: Trailing<BlockNumber>) -> Result<TraceResults, Error> {
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<String>) -> Result<TraceResults, Error> {
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)
}
}