2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-02-05 13:40:41 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-01-10 14:05:39 +01:00
|
|
|
//! General error types for use in ethcore.
|
|
|
|
|
2017-07-29 17:12:07 +02:00
|
|
|
use std::fmt;
|
2016-01-10 14:05:39 +01:00
|
|
|
use util::*;
|
2016-08-05 10:32:04 +02:00
|
|
|
use io::*;
|
2016-01-11 12:45:35 +01:00
|
|
|
use header::BlockNumber;
|
2016-01-14 19:03:48 +01:00
|
|
|
use basic_types::LogBloom;
|
2016-05-18 11:34:15 +02:00
|
|
|
use client::Error as ClientError;
|
2016-07-01 21:13:56 +02:00
|
|
|
use ipc::binary::{BinaryConvertError, BinaryConvertable};
|
2016-08-05 17:00:46 +02:00
|
|
|
use snapshot::Error as SnapshotError;
|
2016-08-24 15:55:47 +02:00
|
|
|
use engines::EngineError;
|
2016-08-24 18:35:21 +02:00
|
|
|
use ethkey::Error as EthkeyError;
|
2017-01-30 21:08:36 +01:00
|
|
|
use account_provider::SignError as AccountsError;
|
2016-08-05 17:00:46 +02:00
|
|
|
|
2017-07-12 13:09:17 +02:00
|
|
|
pub use executed::{ExecutionError, CallError};
|
2016-01-11 17:37:22 +01:00
|
|
|
|
2016-09-01 12:23:31 +02:00
|
|
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
2016-03-10 11:38:24 +01:00
|
|
|
/// Errors concerning transaction processing.
|
2016-01-12 11:44:16 +01:00
|
|
|
pub enum TransactionError {
|
2016-03-17 15:49:29 +01:00
|
|
|
/// Transaction is already imported to the queue
|
|
|
|
AlreadyImported,
|
|
|
|
/// Transaction is not valid anymore (state already has higher nonce)
|
|
|
|
Old,
|
2016-04-18 19:34:59 +02:00
|
|
|
/// Transaction has too low fee
|
|
|
|
/// (there is already a transaction with the same sender-nonce but higher gas price)
|
|
|
|
TooCheapToReplace,
|
|
|
|
/// Transaction was not imported to the queue because limit has been reached.
|
|
|
|
LimitReached,
|
2016-03-10 11:38:24 +01:00
|
|
|
/// Transaction's gas price is below threshold.
|
|
|
|
InsufficientGasPrice {
|
|
|
|
/// Minimal expected gas price
|
|
|
|
minimal: U256,
|
|
|
|
/// Transaction gas price
|
2016-03-16 10:40:33 +01:00
|
|
|
got: U256,
|
|
|
|
},
|
2016-10-28 16:42:24 +02:00
|
|
|
/// Transaction's gas is below currently set minimal gas requirement.
|
|
|
|
InsufficientGas {
|
|
|
|
/// Minimal expected gas
|
|
|
|
minimal: U256,
|
|
|
|
/// Transaction gas
|
|
|
|
got: U256,
|
|
|
|
},
|
2016-03-16 10:40:33 +01:00
|
|
|
/// Sender doesn't have enough funds to pay for this transaction
|
|
|
|
InsufficientBalance {
|
|
|
|
/// Senders balance
|
|
|
|
balance: U256,
|
|
|
|
/// Transaction cost
|
|
|
|
cost: U256,
|
2016-03-10 11:38:24 +01:00
|
|
|
},
|
2016-03-17 15:20:33 +01:00
|
|
|
/// Transactions gas is higher then current gas limit
|
|
|
|
GasLimitExceeded {
|
|
|
|
/// Current gas limit
|
|
|
|
limit: U256,
|
|
|
|
/// Declared transaction gas
|
|
|
|
got: U256,
|
|
|
|
},
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Transaction's gas limit (aka gas) is invalid.
|
2016-01-12 11:44:16 +01:00
|
|
|
InvalidGasLimit(OutOfBounds<U256>),
|
2016-10-27 19:28:34 +02:00
|
|
|
/// Transaction sender is banned.
|
|
|
|
SenderBanned,
|
|
|
|
/// Transaction receipient is banned.
|
|
|
|
RecipientBanned,
|
|
|
|
/// Contract creation code is banned.
|
|
|
|
CodeBanned,
|
2016-11-03 22:22:25 +01:00
|
|
|
/// Invalid network ID given.
|
|
|
|
InvalidNetworkId,
|
2016-01-12 11:44:16 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 00:13:16 +02:00
|
|
|
impl fmt::Display for TransactionError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::TransactionError::*;
|
|
|
|
let msg = match *self {
|
2016-05-22 18:41:45 +02:00
|
|
|
AlreadyImported => "Already imported".into(),
|
|
|
|
Old => "No longer valid".into(),
|
|
|
|
TooCheapToReplace => "Gas price too low to replace".into(),
|
|
|
|
LimitReached => "Transaction limit reached".into(),
|
|
|
|
InsufficientGasPrice { minimal, got } =>
|
|
|
|
format!("Insufficient gas price. Min={}, Given={}", minimal, got),
|
2016-10-28 16:42:24 +02:00
|
|
|
InsufficientGas { minimal, got } =>
|
|
|
|
format!("Insufficient gas. Min={}, Given={}", minimal, got),
|
2016-05-22 18:41:45 +02:00
|
|
|
InsufficientBalance { balance, cost } =>
|
2016-05-21 00:13:16 +02:00
|
|
|
format!("Insufficient balance for transaction. Balance={}, Cost={}",
|
2016-05-22 18:41:45 +02:00
|
|
|
balance, cost),
|
|
|
|
GasLimitExceeded { limit, got } =>
|
|
|
|
format!("Gas limit exceeded. Limit={}, Given={}", limit, got),
|
|
|
|
InvalidGasLimit(ref err) => format!("Invalid gas limit. {}", err),
|
2016-10-27 19:28:34 +02:00
|
|
|
SenderBanned => "Sender is temporarily banned.".into(),
|
|
|
|
RecipientBanned => "Recipient is temporarily banned.".into(),
|
|
|
|
CodeBanned => "Contract code is temporarily banned.".into(),
|
2016-11-03 22:22:25 +01:00
|
|
|
InvalidNetworkId => "Transaction of this network ID is not allowed on this chain.".into(),
|
2016-05-21 00:13:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
f.write_fmt(format_args!("Transaction error ({})", msg))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 12:23:31 +02:00
|
|
|
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Errors concerning block processing.
|
2016-01-10 14:05:39 +01:00
|
|
|
pub enum BlockError {
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Block has too many uncles.
|
2016-01-10 19:47:32 +01:00
|
|
|
TooManyUncles(OutOfBounds<usize>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Extra data is of an invalid length.
|
2016-01-10 14:05:39 +01:00
|
|
|
ExtraDataOutOfBounds(OutOfBounds<usize>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Seal is incorrect format.
|
2016-01-10 14:05:39 +01:00
|
|
|
InvalidSealArity(Mismatch<usize>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Block has too much gas used.
|
2016-01-10 19:47:32 +01:00
|
|
|
TooMuchGasUsed(OutOfBounds<U256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Uncles hash in header is invalid.
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidUnclesHash(Mismatch<H256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// An uncle is from a generation too old.
|
2016-01-11 12:45:35 +01:00
|
|
|
UncleTooOld(OutOfBounds<BlockNumber>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// An uncle is from the same generation as the block.
|
2016-01-11 12:45:35 +01:00
|
|
|
UncleIsBrother(OutOfBounds<BlockNumber>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// An uncle is already in the chain.
|
2016-01-10 19:47:32 +01:00
|
|
|
UncleInChain(H256),
|
2017-07-10 13:36:42 +02:00
|
|
|
/// An uncle is included twice.
|
|
|
|
DuplicateUncle(H256),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// An uncle has a parent not in the chain.
|
2016-01-10 19:47:32 +01:00
|
|
|
UncleParentNotInChain(H256),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// State root header field is invalid.
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidStateRoot(Mismatch<H256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Gas used header field is invalid.
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidGasUsed(Mismatch<U256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Transactions root header field is invalid.
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidTransactionsRoot(Mismatch<H256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Difficulty is out of range; this can be used as an looser error prior to getting a definitive
|
|
|
|
/// value for difficulty. This error needs only provide bounds of which it is out.
|
|
|
|
DifficultyOutOfBounds(OutOfBounds<U256>),
|
|
|
|
/// Difficulty header field is invalid; this is a strong error used after getting a definitive
|
|
|
|
/// value for difficulty (which is provided).
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidDifficulty(Mismatch<U256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Seal element of type H256 (max_hash for Ethash, but could be something else for
|
|
|
|
/// other seal engines) is out of bounds.
|
|
|
|
MismatchedH256SealElement(Mismatch<H256>),
|
|
|
|
/// Proof-of-work aspect of seal, which we assume is a 256-bit value, is invalid.
|
|
|
|
InvalidProofOfWork(OutOfBounds<U256>),
|
2016-05-21 00:13:16 +02:00
|
|
|
/// Some low-level aspect of the seal is incorrect.
|
2016-05-03 17:23:53 +02:00
|
|
|
InvalidSeal,
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Gas limit header field is invalid.
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidGasLimit(OutOfBounds<U256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Receipts trie root header field is invalid.
|
|
|
|
InvalidReceiptsRoot(Mismatch<H256>),
|
|
|
|
/// Timestamp header field is invalid.
|
2016-01-11 12:45:35 +01:00
|
|
|
InvalidTimestamp(OutOfBounds<u64>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Log bloom header field is invalid.
|
2016-01-14 19:03:48 +01:00
|
|
|
InvalidLogBloom(Mismatch<LogBloom>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Parent hash field of header is invalid; this is an invalid error indicating a logic flaw in the codebase.
|
|
|
|
/// TODO: remove and favour an assert!/panic!.
|
2016-01-10 19:47:32 +01:00
|
|
|
InvalidParentHash(Mismatch<H256>),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Number field of header is invalid.
|
2016-01-27 14:09:32 +01:00
|
|
|
InvalidNumber(Mismatch<BlockNumber>),
|
|
|
|
/// Block number isn't sensible.
|
|
|
|
RidiculousNumber(OutOfBounds<BlockNumber>),
|
2017-06-28 09:10:57 +02:00
|
|
|
/// Too many transactions from a particular address.
|
|
|
|
TooManyTransactions(Address),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Parent given is unknown.
|
2016-01-10 19:47:32 +01:00
|
|
|
UnknownParent(H256),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Uncle parent given is unknown.
|
2016-01-10 19:47:32 +01:00
|
|
|
UnknownUncleParent(H256),
|
2017-05-17 12:41:33 +02:00
|
|
|
/// No transition to epoch number.
|
|
|
|
UnknownEpochTransition(u64),
|
2016-01-10 14:05:39 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 00:13:16 +02:00
|
|
|
impl fmt::Display for BlockError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::BlockError::*;
|
|
|
|
|
|
|
|
let msg = match *self {
|
2016-05-22 18:41:45 +02:00
|
|
|
TooManyUncles(ref oob) => format!("Block has too many uncles. {}", oob),
|
|
|
|
ExtraDataOutOfBounds(ref oob) => format!("Extra block data too long. {}", oob),
|
|
|
|
InvalidSealArity(ref mis) => format!("Block seal in incorrect format: {}", mis),
|
|
|
|
TooMuchGasUsed(ref oob) => format!("Block has too much gas used. {}", oob),
|
|
|
|
InvalidUnclesHash(ref mis) => format!("Block has invalid uncles hash: {}", mis),
|
|
|
|
UncleTooOld(ref oob) => format!("Uncle block is too old. {}", oob),
|
|
|
|
UncleIsBrother(ref oob) => format!("Uncle from same generation as block. {}", oob),
|
|
|
|
UncleInChain(ref hash) => format!("Uncle {} already in chain", hash),
|
2017-07-10 13:36:42 +02:00
|
|
|
DuplicateUncle(ref hash) => format!("Uncle {} already in the header", hash),
|
2016-05-22 18:41:45 +02:00
|
|
|
UncleParentNotInChain(ref hash) => format!("Uncle {} has a parent not in the chain", hash),
|
|
|
|
InvalidStateRoot(ref mis) => format!("Invalid state root in header: {}", mis),
|
|
|
|
InvalidGasUsed(ref mis) => format!("Invalid gas used in header: {}", mis),
|
|
|
|
InvalidTransactionsRoot(ref mis) => format!("Invalid transactions root in header: {}", mis),
|
|
|
|
DifficultyOutOfBounds(ref oob) => format!("Invalid block difficulty: {}", oob),
|
|
|
|
InvalidDifficulty(ref mis) => format!("Invalid block difficulty: {}", mis),
|
|
|
|
MismatchedH256SealElement(ref mis) => format!("Seal element out of bounds: {}", mis),
|
|
|
|
InvalidProofOfWork(ref oob) => format!("Block has invalid PoW: {}", oob),
|
|
|
|
InvalidSeal => "Block has invalid seal.".into(),
|
|
|
|
InvalidGasLimit(ref oob) => format!("Invalid gas limit: {}", oob),
|
|
|
|
InvalidReceiptsRoot(ref mis) => format!("Invalid receipts trie root in header: {}", mis),
|
|
|
|
InvalidTimestamp(ref oob) => format!("Invalid timestamp in header: {}", oob),
|
|
|
|
InvalidLogBloom(ref oob) => format!("Invalid log bloom in header: {}", oob),
|
|
|
|
InvalidParentHash(ref mis) => format!("Invalid parent hash: {}", mis),
|
|
|
|
InvalidNumber(ref mis) => format!("Invalid number in header: {}", mis),
|
|
|
|
RidiculousNumber(ref oob) => format!("Implausible block number. {}", oob),
|
|
|
|
UnknownParent(ref hash) => format!("Unknown parent: {}", hash),
|
|
|
|
UnknownUncleParent(ref hash) => format!("Unknown uncle parent: {}", hash),
|
2017-05-17 12:41:33 +02:00
|
|
|
UnknownEpochTransition(ref num) => format!("Unknown transition to epoch number: {}", num),
|
2017-06-28 09:10:57 +02:00
|
|
|
TooManyTransactions(ref address) => format!("Too many transactions from: {}", address),
|
2016-05-21 00:13:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
f.write_fmt(format_args!("Block error ({})", msg))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 12:23:31 +02:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
2016-02-02 12:12:32 +01:00
|
|
|
/// Import to the block queue result
|
2016-01-10 23:37:09 +01:00
|
|
|
pub enum ImportError {
|
2016-03-01 00:02:48 +01:00
|
|
|
/// Already in the block chain.
|
2016-01-10 23:37:09 +01:00
|
|
|
AlreadyInChain,
|
2016-03-01 00:02:48 +01:00
|
|
|
/// Already in the block queue.
|
2016-01-10 23:37:09 +01:00
|
|
|
AlreadyQueued,
|
2016-03-01 00:02:48 +01:00
|
|
|
/// Already marked as bad from a previous import (could mean parent is bad).
|
|
|
|
KnownBad,
|
2016-01-10 23:37:09 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 00:13:16 +02:00
|
|
|
impl fmt::Display for ImportError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-05-22 18:41:45 +02:00
|
|
|
let msg = match *self {
|
|
|
|
ImportError::AlreadyInChain => "block already in chain",
|
|
|
|
ImportError::AlreadyQueued => "block already in the block queue",
|
|
|
|
ImportError::KnownBad => "block known to be bad",
|
2016-05-21 00:13:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
f.write_fmt(format_args!("Block import error ({})", msg))
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 13:09:17 +02:00
|
|
|
/// Error dedicated to import block function
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum BlockImportError {
|
|
|
|
/// Import error
|
|
|
|
Import(ImportError),
|
|
|
|
/// Block error
|
|
|
|
Block(BlockError),
|
|
|
|
/// Other error
|
|
|
|
Other(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Error> for BlockImportError {
|
|
|
|
fn from(e: Error) -> Self {
|
|
|
|
match e {
|
|
|
|
Error::Block(block_error) => BlockImportError::Block(block_error),
|
|
|
|
Error::Import(import_error) => BlockImportError::Import(import_error),
|
|
|
|
_ => BlockImportError::Other(format!("other block import error: {:?}", e)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Represents the result of importing transaction.
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum TransactionImportResult {
|
|
|
|
/// Transaction was imported to current queue.
|
|
|
|
Current,
|
|
|
|
/// Transaction was imported to future queue.
|
|
|
|
Future
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Api-level error for transaction import
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum TransactionImportError {
|
|
|
|
/// Transaction error
|
|
|
|
Transaction(TransactionError),
|
|
|
|
/// Other error
|
|
|
|
Other(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Error> for TransactionImportError {
|
|
|
|
fn from(e: Error) -> Self {
|
|
|
|
match e {
|
|
|
|
Error::Transaction(transaction_error) => TransactionImportError::Transaction(transaction_error),
|
|
|
|
_ => TransactionImportError::Other(format!("other block import error: {:?}", e)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-21 00:13:16 +02:00
|
|
|
|
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-05-18 11:34:15 +02:00
|
|
|
/// Client configuration error.
|
|
|
|
Client(ClientError),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Error concerning a utility.
|
2016-01-10 14:05:39 +01:00
|
|
|
Util(UtilError),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Error concerning block processing.
|
2016-01-10 14:05:39 +01:00
|
|
|
Block(BlockError),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Unknown engine given.
|
2016-01-10 14:05:39 +01:00
|
|
|
UnknownEngineName(String),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Error concerning EVM code execution.
|
2016-01-11 17:37:22 +01:00
|
|
|
Execution(ExecutionError),
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Error concerning transaction processing.
|
2016-01-12 11:44:16 +01:00
|
|
|
Transaction(TransactionError),
|
2016-03-01 00:02:48 +01:00
|
|
|
/// Error concerning block import.
|
|
|
|
Import(ImportError),
|
|
|
|
/// PoW hash is invalid or out of date.
|
|
|
|
PowHashInvalid,
|
|
|
|
/// The value of the nonce or mishash is invalid.
|
|
|
|
PowInvalid,
|
2016-06-07 20:44:09 +02:00
|
|
|
/// Error concerning TrieDBs
|
2016-06-13 16:21:23 +02:00
|
|
|
Trie(TrieError),
|
2016-08-05 10:32:04 +02:00
|
|
|
/// Io crate error.
|
|
|
|
Io(IoError),
|
|
|
|
/// Standard io error.
|
|
|
|
StdIo(::std::io::Error),
|
2016-06-15 17:46:40 +02:00
|
|
|
/// Snappy error.
|
2016-06-16 13:29:24 +02:00
|
|
|
Snappy(::util::snappy::InvalidInput),
|
2016-08-05 17:00:46 +02:00
|
|
|
/// Snapshot error.
|
|
|
|
Snapshot(SnapshotError),
|
2016-08-22 13:19:23 +02:00
|
|
|
/// Consensus vote error.
|
2016-08-24 15:55:47 +02:00
|
|
|
Engine(EngineError),
|
2016-08-24 18:35:21 +02:00
|
|
|
/// Ethkey error.
|
|
|
|
Ethkey(EthkeyError),
|
2017-01-24 10:03:58 +01:00
|
|
|
/// Account Provider error.
|
|
|
|
AccountProvider(AccountsError),
|
2016-01-12 11:44:16 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 00:13:16 +02:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2016-08-05 17:00:46 +02:00
|
|
|
Error::Client(ref err) => err.fmt(f),
|
|
|
|
Error::Util(ref err) => err.fmt(f),
|
|
|
|
Error::Io(ref err) => err.fmt(f),
|
|
|
|
Error::Block(ref err) => err.fmt(f),
|
|
|
|
Error::Execution(ref err) => err.fmt(f),
|
|
|
|
Error::Transaction(ref err) => err.fmt(f),
|
|
|
|
Error::Import(ref err) => err.fmt(f),
|
2016-05-22 18:41:45 +02:00
|
|
|
Error::UnknownEngineName(ref name) =>
|
|
|
|
f.write_fmt(format_args!("Unknown engine name ({})", name)),
|
|
|
|
Error::PowHashInvalid => f.write_str("Invalid or out of date PoW hash."),
|
|
|
|
Error::PowInvalid => f.write_str("Invalid nonce or mishash"),
|
2016-08-05 17:00:46 +02:00
|
|
|
Error::Trie(ref err) => err.fmt(f),
|
|
|
|
Error::StdIo(ref err) => err.fmt(f),
|
|
|
|
Error::Snappy(ref err) => err.fmt(f),
|
|
|
|
Error::Snapshot(ref err) => err.fmt(f),
|
2016-11-29 13:51:27 +01:00
|
|
|
Error::Engine(ref err) => err.fmt(f),
|
2016-08-24 18:35:21 +02:00
|
|
|
Error::Ethkey(ref err) => err.fmt(f),
|
2017-01-24 10:03:58 +01:00
|
|
|
Error::AccountProvider(ref err) => err.fmt(f),
|
2016-05-21 00:13:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 00:02:48 +01:00
|
|
|
/// Result of import block operation.
|
|
|
|
pub type ImportResult = Result<H256, Error>;
|
|
|
|
|
2016-05-18 11:34:15 +02:00
|
|
|
impl From<ClientError> for Error {
|
|
|
|
fn from(err: ClientError) -> Error {
|
2016-08-03 18:35:48 +02:00
|
|
|
match err {
|
|
|
|
ClientError::Trie(err) => Error::Trie(err),
|
|
|
|
_ => Error::Client(err)
|
|
|
|
}
|
2016-05-18 11:34:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 11:44:16 +01:00
|
|
|
impl From<TransactionError> for Error {
|
|
|
|
fn from(err: TransactionError) -> Error {
|
|
|
|
Error::Transaction(err)
|
|
|
|
}
|
2016-01-10 14:05:39 +01:00
|
|
|
}
|
|
|
|
|
2016-03-01 00:02:48 +01:00
|
|
|
impl From<ImportError> for Error {
|
|
|
|
fn from(err: ImportError) -> Error {
|
|
|
|
Error::Import(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-09-01 14:29:59 +02:00
|
|
|
impl From<::rlp::DecoderError> for Error {
|
|
|
|
fn from(err: ::rlp::DecoderError) -> Error {
|
2016-01-12 11:44:16 +01:00
|
|
|
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 {
|
2016-08-05 10:32:04 +02:00
|
|
|
Error::Io(err)
|
2016-01-13 23:15:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 20:44:09 +02:00
|
|
|
impl From<TrieError> for Error {
|
|
|
|
fn from(err: TrieError) -> Error {
|
2016-06-13 16:21:23 +02:00
|
|
|
Error::Trie(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<::std::io::Error> for Error {
|
|
|
|
fn from(err: ::std::io::Error) -> Error {
|
2016-08-05 10:32:04 +02:00
|
|
|
Error::StdIo(err)
|
2016-06-07 20:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-01 20:33:59 +02:00
|
|
|
impl From<BlockImportError> for Error {
|
|
|
|
fn from(err: BlockImportError) -> Error {
|
|
|
|
match err {
|
|
|
|
BlockImportError::Block(e) => Error::Block(e),
|
|
|
|
BlockImportError::Import(e) => Error::Import(e),
|
|
|
|
BlockImportError::Other(s) => Error::Util(UtilError::SimpleString(s)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 17:00:46 +02:00
|
|
|
impl From<snappy::InvalidInput> for Error {
|
|
|
|
fn from(err: snappy::InvalidInput) -> Error {
|
|
|
|
Error::Snappy(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SnapshotError> for Error {
|
|
|
|
fn from(err: SnapshotError) -> Error {
|
|
|
|
match err {
|
|
|
|
SnapshotError::Io(err) => Error::StdIo(err),
|
|
|
|
SnapshotError::Trie(err) => Error::Trie(err),
|
|
|
|
SnapshotError::Decoder(err) => err.into(),
|
|
|
|
other => Error::Snapshot(other),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 15:55:47 +02:00
|
|
|
impl From<EngineError> for Error {
|
|
|
|
fn from(err: EngineError) -> Error {
|
2016-08-26 13:16:56 +02:00
|
|
|
Error::Engine(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 18:35:21 +02:00
|
|
|
impl From<EthkeyError> for Error {
|
|
|
|
fn from(err: EthkeyError) -> Error {
|
|
|
|
Error::Ethkey(err)
|
2016-08-22 13:19:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 10:03:58 +01:00
|
|
|
impl From<AccountsError> for Error {
|
|
|
|
fn from(err: AccountsError) -> Error {
|
|
|
|
Error::AccountProvider(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 18:35:48 +02:00
|
|
|
impl<E> From<Box<E>> for Error where Error: From<E> {
|
|
|
|
fn from(err: Box<E>) -> Error {
|
|
|
|
Error::from(*err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-01 20:33:59 +02:00
|
|
|
binary_fixed_size!(BlockError);
|
|
|
|
binary_fixed_size!(ImportError);
|
|
|
|
binary_fixed_size!(TransactionError);
|
|
|
|
|
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);*/
|