//! General error types for use in ethcore. use util::*; use header::BlockNumber; #[derive(Debug)] pub struct Mismatch { pub expected: T, pub found: T, } #[derive(Debug)] pub struct OutOfBounds { pub min: T, pub max: T, pub found: T, } #[derive(Debug)] pub enum BlockError { TooManyUncles(OutOfBounds), UncleWrongGeneration, ExtraDataOutOfBounds(OutOfBounds), InvalidSealArity(Mismatch), TooMuchGasUsed(OutOfBounds), InvalidUnclesHash(Mismatch), UncleTooOld(OutOfBounds), UncleIsBrother(OutOfBounds), UncleInChain(H256), UncleParentNotInChain(H256), InvalidStateRoot, InvalidGasUsed, InvalidTransactionsRoot(Mismatch), InvalidDifficulty(Mismatch), InvalidGasLimit(OutOfBounds), InvalidReceiptsStateRoot, InvalidTimestamp(OutOfBounds), InvalidLogBloom, InvalidBlockNonce, InvalidParentHash(Mismatch), InvalidNumber(OutOfBounds), UnknownParent(H256), UnknownUncleParent(H256), } #[derive(Debug)] pub enum ImportError { Bad(Error), AlreadyInChain, AlreadyQueued, } impl From for ImportError { fn from(err: Error) -> ImportError { ImportError::Bad(err) } } /// Result of import block operation. pub type ImportResult = Result<(), ImportError>; #[derive(Debug)] /// General error type which should be capable of representing all errors in ethcore. pub enum Error { Util(UtilError), Block(BlockError), UnknownEngineName(String), } impl From for Error { fn from(err: BlockError) -> Error { Error::Block(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);*/