2016-01-10 14:05:39 +01:00
|
|
|
//! General error types for use in ethcore.
|
|
|
|
|
|
|
|
use util::*;
|
2016-01-11 12:45:35 +01:00
|
|
|
use header::BlockNumber;
|
2016-01-10 14:05:39 +01:00
|
|
|
|
2016-01-12 13:14:01 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2016-01-10 14:05:39 +01:00
|
|
|
pub struct Mismatch<T: fmt::Debug> {
|
|
|
|
pub expected: T,
|
|
|
|
pub found: T,
|
|
|
|
}
|
|
|
|
|
2016-01-12 13:14:01 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2016-01-10 14:05:39 +01:00
|
|
|
pub struct OutOfBounds<T: fmt::Debug> {
|
2016-01-12 11:44:16 +01:00
|
|
|
pub min: Option<T>,
|
|
|
|
pub max: Option<T>,
|
2016-01-10 14:05:39 +01:00
|
|
|
pub found: T,
|
|
|
|
}
|
|
|
|
|
2016-01-11 17:37:22 +01:00
|
|
|
/// Result of executing the transaction.
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum ExecutionError {
|
|
|
|
/// Returned when block (gas_used + gas) > gas_limit.
|
|
|
|
///
|
|
|
|
/// If gas =< gas_limit, upstream may try to execute the transaction
|
|
|
|
/// in next block.
|
|
|
|
BlockGasLimitReached { gas_limit: U256, gas_used: U256, gas: U256 },
|
|
|
|
/// Returned when transaction nonce does not match state nonce.
|
|
|
|
InvalidNonce { expected: U256, is: U256 },
|
|
|
|
/// Returned when cost of transaction (value + gas_price * gas) exceeds
|
|
|
|
/// current sender balance.
|
|
|
|
NotEnoughCash { required: U256, is: U256 },
|
|
|
|
/// Returned when internal evm error occurs.
|
|
|
|
Internal
|
|
|
|
}
|
|
|
|
|
2016-01-12 11:44:16 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum TransactionError {
|
|
|
|
InvalidGasLimit(OutOfBounds<U256>),
|
|
|
|
}
|
|
|
|
|
2016-01-12 13:14:01 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2016-01-10 14:05:39 +01:00
|
|
|
pub enum BlockError {
|
2016-01-10 19:47:32 +01:00
|
|
|
TooManyUncles(OutOfBounds<usize>),
|
2016-01-10 14:05:39 +01:00
|
|
|
UncleWrongGeneration,
|
|
|
|
ExtraDataOutOfBounds(OutOfBounds<usize>),
|
|
|
|
InvalidSealArity(Mismatch<usize>),
|
2016-01-10 19:47:32 +01:00
|
|
|
TooMuchGasUsed(OutOfBounds<U256>),
|
|
|
|
InvalidUnclesHash(Mismatch<H256>),
|
2016-01-11 12:45:35 +01:00
|
|
|
UncleTooOld(OutOfBounds<BlockNumber>),
|
|
|
|
UncleIsBrother(OutOfBounds<BlockNumber>),
|
2016-01-10 19:47:32 +01:00
|
|
|
UncleInChain(H256),
|
|
|
|
UncleParentNotInChain(H256),
|
|
|
|
InvalidStateRoot,
|
|
|
|
InvalidGasUsed,
|
|
|
|
InvalidTransactionsRoot(Mismatch<H256>),
|
|
|
|
InvalidDifficulty(Mismatch<U256>),
|
|
|
|
InvalidGasLimit(OutOfBounds<U256>),
|
|
|
|
InvalidReceiptsStateRoot,
|
2016-01-11 12:45:35 +01:00
|
|
|
InvalidTimestamp(OutOfBounds<u64>),
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidLogBloom,
|
|
|
|
InvalidBlockNonce,
|
|
|
|
InvalidParentHash(Mismatch<H256>),
|
2016-01-11 12:45:35 +01:00
|
|
|
InvalidNumber(OutOfBounds<BlockNumber>),
|
2016-01-10 19:47:32 +01:00
|
|
|
UnknownParent(H256),
|
|
|
|
UnknownUncleParent(H256),
|
2016-01-10 14:05:39 +01:00
|
|
|
}
|
|
|
|
|
2016-01-10 23:37:09 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ImportError {
|
2016-01-11 13:42:32 +01:00
|
|
|
Bad(Error),
|
2016-01-10 23:37:09 +01:00
|
|
|
AlreadyInChain,
|
|
|
|
AlreadyQueued,
|
|
|
|
}
|
|
|
|
|
2016-01-11 13:42:32 +01:00
|
|
|
impl From<Error> for ImportError {
|
|
|
|
fn from(err: Error) -> ImportError {
|
|
|
|
ImportError::Bad(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Result of import block operation.
|
|
|
|
pub type ImportResult = Result<(), ImportError>;
|
|
|
|
|
2016-01-10 14:05:39 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
/// General error type which should be capable of representing all errors in ethcore.
|
|
|
|
pub enum Error {
|
|
|
|
Util(UtilError),
|
|
|
|
Block(BlockError),
|
|
|
|
UnknownEngineName(String),
|
2016-01-11 17:37:22 +01:00
|
|
|
Execution(ExecutionError),
|
2016-01-12 11:44:16 +01:00
|
|
|
Transaction(TransactionError),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<TransactionError> for Error {
|
|
|
|
fn from(err: TransactionError) -> Error {
|
|
|
|
Error::Transaction(err)
|
|
|
|
}
|
2016-01-10 14:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BlockError> for Error {
|
|
|
|
fn from(err: BlockError) -> Error {
|
|
|
|
Error::Block(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 17:37:22 +01:00
|
|
|
impl From<ExecutionError> for Error {
|
|
|
|
fn from(err: ExecutionError) -> Error {
|
|
|
|
Error::Execution(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 20:47:19 +01:00
|
|
|
impl From<CryptoError> for Error {
|
|
|
|
fn from(err: CryptoError) -> Error {
|
|
|
|
Error::Util(UtilError::Crypto(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 11:44:16 +01:00
|
|
|
impl From<DecoderError> for Error {
|
|
|
|
fn from(err: DecoderError) -> Error {
|
|
|
|
Error::Util(UtilError::Decoder(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 14:05:39 +01:00
|
|
|
// TODO: uncomment below once https://github.com/rust-lang/rust/issues/27336 sorted.
|
|
|
|
/*#![feature(concat_idents)]
|
|
|
|
macro_rules! assimilate {
|
|
|
|
($name:ident) => (
|
|
|
|
impl From<concat_idents!($name, Error)> for Error {
|
|
|
|
fn from(err: concat_idents!($name, Error)) -> Error {
|
|
|
|
Error:: $name (err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
assimilate!(FromHex);
|
|
|
|
assimilate!(BaseData);*/
|