//! General error types for use in ethcore. use util::*; use header::BlockNumber; use basic_types::LogBloom; #[derive(Debug, PartialEq, Eq)] /// TODO [Gav Wood] Please document me pub struct Mismatch { /// TODO [Gav Wood] Please document me pub expected: T, /// TODO [Gav Wood] Please document me pub found: T, } #[derive(Debug, PartialEq, Eq)] /// TODO [Gav Wood] Please document me pub struct OutOfBounds { /// TODO [Gav Wood] Please document me pub min: Option, /// TODO [Gav Wood] Please document me pub max: Option, /// TODO [Gav Wood] Please document me pub found: T, } /// Result of executing the transaction. #[derive(PartialEq, Debug)] pub enum ExecutionError { /// Returned when there gas paid for transaction execution is /// lower than base gas required. /// TODO [Gav Wood] Please document me NotEnoughBaseGas { /// TODO [Gav Wood] Please document me required: U256, /// TODO [Gav Wood] Please document me got: U256 }, /// Returned when block (gas_used + gas) > gas_limit. /// /// If gas =< gas_limit, upstream may try to execute the transaction /// in next block. BlockGasLimitReached { /// TODO [Gav Wood] Please document me gas_limit: U256, /// TODO [Gav Wood] Please document me gas_used: U256, /// TODO [Gav Wood] Please document me gas: U256 }, /// Returned when transaction nonce does not match state nonce. InvalidNonce { /// TODO [Gav Wood] Please document me expected: U256, /// TODO [Gav Wood] Please document me got: U256 }, /// Returned when cost of transaction (value + gas_price * gas) exceeds /// current sender balance. NotEnoughCash { /// TODO [Gav Wood] Please document me required: U512, /// TODO [Gav Wood] Please document me got: U512 }, /// Returned when internal evm error occurs. Internal } #[derive(Debug)] /// TODO [Gav Wood] Please document me pub enum TransactionError { /// TODO [Gav Wood] Please document me InvalidGasLimit(OutOfBounds), } #[derive(Debug, PartialEq, Eq)] /// TODO [arkpar] Please document me pub enum BlockError { /// TODO [Gav Wood] Please document me TooManyUncles(OutOfBounds), /// TODO [Gav Wood] Please document me UncleWrongGeneration, /// TODO [Gav Wood] Please document me ExtraDataOutOfBounds(OutOfBounds), /// TODO [arkpar] Please document me InvalidSealArity(Mismatch), /// TODO [arkpar] Please document me TooMuchGasUsed(OutOfBounds), /// TODO [arkpar] Please document me InvalidUnclesHash(Mismatch), /// TODO [arkpar] Please document me UncleTooOld(OutOfBounds), /// TODO [arkpar] Please document me UncleIsBrother(OutOfBounds), /// TODO [arkpar] Please document me UncleInChain(H256), /// TODO [arkpar] Please document me UncleParentNotInChain(H256), /// TODO [arkpar] Please document me InvalidStateRoot(Mismatch), /// TODO [arkpar] Please document me InvalidGasUsed(Mismatch), /// TODO [arkpar] Please document me InvalidTransactionsRoot(Mismatch), /// TODO [arkpar] Please document me InvalidDifficulty(Mismatch), /// TODO [arkpar] Please document me InvalidGasLimit(OutOfBounds), /// TODO [arkpar] Please document me InvalidReceiptsStateRoot(Mismatch), /// TODO [arkpar] Please document me InvalidTimestamp(OutOfBounds), /// TODO [arkpar] Please document me InvalidLogBloom(Mismatch), /// TODO [arkpar] Please document me InvalidEthashDifficulty(Mismatch), /// TODO [arkpar] Please document me InvalidBlockNonce(Mismatch), /// TODO [arkpar] Please document me InvalidParentHash(Mismatch), /// TODO [arkpar] Please document me InvalidNumber(Mismatch), /// Block number isn't sensible. RidiculousNumber(OutOfBounds), /// TODO [arkpar] Please document me UnknownParent(H256), /// TODO [Gav Wood] Please document me UnknownUncleParent(H256), } #[derive(Debug)] /// TODO [arkpar] Please document me pub enum ImportError { /// TODO [arkpar] Please document me Bad(Option), /// TODO [arkpar] Please document me AlreadyInChain, /// TODO [arkpar] Please document me AlreadyQueued, } impl From for ImportError { fn from(err: Error) -> ImportError { ImportError::Bad(Some(err)) } } /// Result of import block operation. pub type ImportResult = Result; #[derive(Debug)] /// General error type which should be capable of representing all errors in ethcore. pub enum Error { /// TODO [Gav Wood] Please document me Util(UtilError), /// TODO [Gav Wood] Please document me Block(BlockError), /// TODO [Gav Wood] Please document me UnknownEngineName(String), /// TODO [Gav Wood] Please document me Execution(ExecutionError), /// TODO [Gav Wood] Please document me Transaction(TransactionError), } impl From for Error { fn from(err: TransactionError) -> Error { Error::Transaction(err) } } impl From for Error { fn from(err: BlockError) -> Error { Error::Block(err) } } impl From for Error { fn from(err: ExecutionError) -> Error { Error::Execution(err) } } impl From for Error { fn from(err: CryptoError) -> Error { Error::Util(UtilError::Crypto(err)) } } impl From for Error { fn from(err: DecoderError) -> Error { Error::Util(UtilError::Decoder(err)) } } impl From for Error { fn from(err: UtilError) -> Error { Error::Util(err) } } impl From for Error { fn from(err: IoError) -> Error { Error::Util(From::from(err)) } } // TODO: uncomment below once https://github.com/rust-lang/rust/issues/27336 sorted. /*#![feature(concat_idents)] macro_rules! assimilate { ($name:ident) => ( impl From for Error { fn from(err: concat_idents!($name, Error)) -> Error { Error:: $name (err) } } ) } assimilate!(FromHex); assimilate!(BaseData);*/