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-14 19:03:48 +01:00
|
|
|
use basic_types::LogBloom;
|
2016-01-10 14:05:39 +01:00
|
|
|
|
2016-01-12 13:14:01 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
pub struct Mismatch<T: fmt::Debug> {
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
pub expected: T,
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
pub found: T,
|
|
|
|
}
|
|
|
|
|
2016-01-12 13:14:01 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
pub struct OutOfBounds<T: fmt::Debug> {
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-12 11:44:16 +01:00
|
|
|
pub min: Option<T>,
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-12 11:44:16 +01:00
|
|
|
pub max: Option<T>,
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
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 {
|
2016-01-15 13:07:44 +01:00
|
|
|
/// Returned when there gas paid for transaction execution is
|
|
|
|
/// lower than base gas required.
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
|
|
|
NotEnoughBaseGas {
|
|
|
|
/// TODO [Gav Wood] Please document me
|
|
|
|
required: U256,
|
|
|
|
/// TODO [Gav Wood] Please document me
|
|
|
|
got: U256
|
|
|
|
},
|
2016-01-11 17:37:22 +01:00
|
|
|
/// Returned when block (gas_used + gas) > gas_limit.
|
|
|
|
///
|
|
|
|
/// If gas =< gas_limit, upstream may try to execute the transaction
|
|
|
|
/// in next block.
|
2016-01-19 17:02:01 +01:00
|
|
|
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
|
|
|
|
},
|
2016-01-11 17:37:22 +01:00
|
|
|
/// Returned when transaction nonce does not match state nonce.
|
2016-01-19 17:02:01 +01:00
|
|
|
InvalidNonce {
|
|
|
|
/// TODO [Gav Wood] Please document me
|
|
|
|
expected: U256,
|
|
|
|
/// TODO [Gav Wood] Please document me
|
|
|
|
got: U256
|
|
|
|
},
|
2016-01-11 17:37:22 +01:00
|
|
|
/// Returned when cost of transaction (value + gas_price * gas) exceeds
|
|
|
|
/// current sender balance.
|
2016-01-19 17:02:01 +01:00
|
|
|
NotEnoughCash {
|
|
|
|
/// TODO [Gav Wood] Please document me
|
|
|
|
required: U512,
|
|
|
|
/// TODO [Gav Wood] Please document me
|
|
|
|
got: U512
|
|
|
|
},
|
2016-01-11 17:37:22 +01:00
|
|
|
/// Returned when internal evm error occurs.
|
|
|
|
Internal
|
|
|
|
}
|
|
|
|
|
2016-01-12 11:44:16 +01:00
|
|
|
#[derive(Debug)]
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-12 11:44:16 +01:00
|
|
|
pub enum TransactionError {
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-12 11:44:16 +01:00
|
|
|
InvalidGasLimit(OutOfBounds<U256>),
|
|
|
|
}
|
|
|
|
|
2016-01-12 13:14:01 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
pub enum BlockError {
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
TooManyUncles(OutOfBounds<usize>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
UncleWrongGeneration,
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
ExtraDataOutOfBounds(OutOfBounds<usize>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
InvalidSealArity(Mismatch<usize>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
TooMuchGasUsed(OutOfBounds<U256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidUnclesHash(Mismatch<H256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-11 12:45:35 +01:00
|
|
|
UncleTooOld(OutOfBounds<BlockNumber>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-11 12:45:35 +01:00
|
|
|
UncleIsBrother(OutOfBounds<BlockNumber>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
UncleInChain(H256),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
UncleParentNotInChain(H256),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidStateRoot(Mismatch<H256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidGasUsed(Mismatch<U256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidTransactionsRoot(Mismatch<H256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidDifficulty(Mismatch<U256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidGasLimit(OutOfBounds<U256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidReceiptsStateRoot(Mismatch<H256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-11 12:45:35 +01:00
|
|
|
InvalidTimestamp(OutOfBounds<u64>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidLogBloom(Mismatch<LogBloom>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-17 12:00:34 +01:00
|
|
|
InvalidEthashDifficulty(Mismatch<U256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidBlockNonce(Mismatch<H256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidParentHash(Mismatch<H256>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-11 12:45:35 +01:00
|
|
|
InvalidNumber(OutOfBounds<BlockNumber>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
UnknownParent(H256),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 19:47:32 +01:00
|
|
|
UnknownUncleParent(H256),
|
2016-01-10 14:05:39 +01:00
|
|
|
}
|
|
|
|
|
2016-01-10 23:37:09 +01:00
|
|
|
#[derive(Debug)]
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 23:37:09 +01:00
|
|
|
pub enum ImportError {
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-15 12:26:04 +01:00
|
|
|
Bad(Option<Error>),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 23:37:09 +01:00
|
|
|
AlreadyInChain,
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [arkpar] Please document me
|
2016-01-10 23:37:09 +01:00
|
|
|
AlreadyQueued,
|
|
|
|
}
|
|
|
|
|
2016-01-11 13:42:32 +01:00
|
|
|
impl From<Error> for ImportError {
|
|
|
|
fn from(err: Error) -> ImportError {
|
2016-01-15 12:26:04 +01:00
|
|
|
ImportError::Bad(Some(err))
|
2016-01-11 13:42:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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 {
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
Util(UtilError),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
Block(BlockError),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-10 14:05:39 +01:00
|
|
|
UnknownEngineName(String),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
2016-01-11 17:37:22 +01:00
|
|
|
Execution(ExecutionError),
|
2016-01-19 17:02:01 +01:00
|
|
|
/// TODO [Gav Wood] Please document me
|
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-13 23:15:44 +01:00
|
|
|
impl From<UtilError> for Error {
|
|
|
|
fn from(err: UtilError) -> Error {
|
|
|
|
Error::Util(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<IoError> for Error {
|
|
|
|
fn from(err: IoError) -> Error {
|
|
|
|
Error::Util(From::from(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);*/
|