From d772146b43a037c17c77e87c8ff72afe7b5ce147 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 20 Jul 2021 17:25:35 +0000 Subject: [PATCH] refactor: extract evm string error --- --- a/crates/evm-coder/src/abi.rs +++ b/crates/evm-coder/src/abi.rs @@ -163,8 +163,6 @@ self.write_padleft(&u128::to_be_bytes(*value)) } - /// This method writes u128, and exists only for convenience, because there is - /// no u256 support in rust pub fn uint256(&mut self, value: &U256) { let mut out = [0; 32]; value.to_big_endian(&mut out); @@ -258,28 +256,6 @@ impl AbiWrite for () { fn abi_write(&self, _writer: &mut AbiWriter) {} -} - -/// Error, which can be constructed from any ToString type -/// Encoded to Abi as Error(string) -#[derive(Debug)] -pub struct StringError(String); - -impl From for StringError -where - E: ToString, -{ - fn from(e: E) -> Self { - Self(e.to_string()) - } -} - -impl From for AbiWriter { - fn from(v: StringError) -> Self { - let mut out = AbiWriter::new_call(crate::fn_selector!(Error(string))); - out.string(&v.0); - out - } } #[macro_export] --- /dev/null +++ b/crates/evm-coder/src/execution.rs @@ -0,0 +1,23 @@ +#[cfg(not(feature = "std"))] +use alloc::string::{String, ToString}; +use evm_core::{ExitError, ExitFatal}; +#[cfg(feature = "std")] +use std::string::{String, ToString}; + +#[derive(Debug)] +pub enum Error { + Revert(String), + Fatal(ExitFatal), + Error(ExitError), +} + +impl From for Error +where + E: ToString, +{ + fn from(e: E) -> Self { + Self::Revert(e.to_string()) + } +} + +pub type Result = core::result::Result; -- gitstuff