Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Change error convertion way
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Dec 7, 2020
1 parent 18c55a3 commit 2f4c289
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions frame/dvm/frame/ethereum/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use darwinia_evm::{AddressMapping, ExitError, ExitSucceed, Precompile};
use frame_support::traits::ExistenceRequirement;
use sp_core::H160;
use sp_runtime::traits::{BlakeTwo256, Hash};
use sp_std::borrow::Cow;
use sp_std::marker::PhantomData;
use sp_std::prelude::*;

Expand Down Expand Up @@ -60,7 +59,7 @@ impl<T: Trait> Precompile for NativeTransfer<T> {
target_gas: Option<usize>,
) -> core::result::Result<(ExitSucceed, Vec<u8>, usize), ExitError> {
if input.len() != 177 {
Err(ExitError::Other(Cow::Borrowed("InputDataLenErr")))
Err(ExitError::Other("InputDataLenErr".into()))
} else {
let cost = ensure_linear_cost(target_gas, input.len(), 60, 12)?;

Expand All @@ -86,21 +85,21 @@ impl<T: Trait> Precompile for NativeTransfer<T> {
Ok(()) => Ok((ExitSucceed::Returned, vec![], cost)),
Err(error) => match error {
sp_runtime::DispatchError::BadOrigin => {
Err(ExitError::Other(Cow::Borrowed("BadOrigin")))
Err(ExitError::Other("BadOrigin".into()))
}
sp_runtime::DispatchError::CannotLookup => {
Err(ExitError::Other(Cow::Borrowed("CannotLookup")))
Err(ExitError::Other("CannotLookup".into()))
}
sp_runtime::DispatchError::Other(message) => {
Err(ExitError::Other(Cow::Borrowed(message)))
Err(ExitError::Other(message.into()))
}
sp_runtime::DispatchError::Module { message, .. } => {
Err(ExitError::Other(Cow::Borrowed(message.unwrap())))
Err(ExitError::Other(message.unwrap_or("Module Error").into()))
}
},
}
} else {
Err(ExitError::Other(Cow::Borrowed("BadSignature")))
Err(ExitError::Other("BadSignature".into()))
}
}
}
Expand Down

0 comments on commit 2f4c289

Please sign in to comment.