From 07521c17b4e9b876db9d3a110ce6cf5c5625240e Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 1 Jul 2016 21:33:59 +0300 Subject: [PATCH] dedicated types --- ethcore/src/client/mod.rs | 4 ++- ethcore/src/error.rs | 17 ++++++++- ethcore/src/types/block_import_error.rs | 44 +++++++++++++++++++++++ ethcore/src/types/mod.rs.in | 2 ++ ethcore/src/types/transaction_import.rs | 46 +++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 ethcore/src/types/block_import_error.rs create mode 100644 ethcore/src/types/transaction_import.rs diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 27a1d3265..e54e8e382 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -49,6 +49,8 @@ use trace::LocalizedTrace; use evm::Factory as EvmFactory; use miner::{TransactionImportResult}; use error::Error as EthError; +pub use block_import_error::BlockImportError; +pub use transaction_import::{TransactionImportResult, TransactionImportError}; /// Options concerning what analytics we run on the call. #[derive(Eq, PartialEq, Default, Clone, Copy, Debug)] @@ -188,7 +190,7 @@ pub trait BlockChainClient : Sync + Send { fn last_hashes(&self) -> LastHashes; /// import transactions from network/other 3rd party - fn import_transactions(&self, transactions: Vec) -> Vec>; + fn import_transactions(&self, transactions: Vec) -> Vec>; /// Queue transactions for importing. fn queue_transactions(&self, transactions: Vec); diff --git a/ethcore/src/error.rs b/ethcore/src/error.rs index 92d3cbe6b..7460762c2 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -250,7 +250,7 @@ impl fmt::Display for Error { } /// Result of import block operation. -pub type ImportResult = Result; +pub type ImportResult = Result; impl From for Error { fn from(err: ClientError) -> Error { @@ -312,6 +312,21 @@ impl From for Error { } } +impl From 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)), + } + } +} + +binary_fixed_size!(BlockError); +binary_fixed_size!(ImportError); +binary_fixed_size!(TransactionError); + + // TODO: uncomment below once https://github.com/rust-lang/rust/issues/27336 sorted. /*#![feature(concat_idents)] macro_rules! assimilate { diff --git a/ethcore/src/types/block_import_error.rs b/ethcore/src/types/block_import_error.rs new file mode 100644 index 000000000..8b400613f --- /dev/null +++ b/ethcore/src/types/block_import_error.rs @@ -0,0 +1,44 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// 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 . + +//! Block import error related types + +use std::mem; +use ipc::binary::BinaryConvertError; +use std::collections::VecDeque; +use error::{ImportError, BlockError, Error}; +use std::convert::From; + +/// Error dedicated to import block function +#[derive(Binary, Debug)] +pub enum BlockImportError { + /// Import error + Import(ImportError), + /// Block error + Block(BlockError), + /// Other error + Other(String), +} + +impl From 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)), + } + } +} diff --git a/ethcore/src/types/mod.rs.in b/ethcore/src/types/mod.rs.in index b51e9e57b..97579da8a 100644 --- a/ethcore/src/types/mod.rs.in +++ b/ethcore/src/types/mod.rs.in @@ -25,3 +25,5 @@ pub mod executed; pub mod block_status; pub mod account_diff; pub mod state_diff; +pub mod transaction_import; +pub mod block_import_error; diff --git a/ethcore/src/types/transaction_import.rs b/ethcore/src/types/transaction_import.rs new file mode 100644 index 000000000..78078cfea --- /dev/null +++ b/ethcore/src/types/transaction_import.rs @@ -0,0 +1,46 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// 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 . + +//! Transaction import result related types + +use ipc::binary::BinaryConvertError; +use std::collections::VecDeque; + +#[derive(Debug, Clone, PartialEq)] +/// Represents the result of importing transaction. +pub enum TransactionImportResult { + /// Transaction was imported to current queue. + Current, + /// Transaction was imported to future queue. + Future +} + +binary_fixed_size!(TransactionImportResult); + +#[derive(Debug, Clone, Binary)] +pub enum TransactionImportError { + Transaction(TransactionError), + Other(String), +} + +impl From for BlockImportError { + fn from(e: Error) -> Self { + match e { + Error::Transaction(transaction_error) => TransactionImportError::Transaction(block_error), + _ => TransactionImportError::Other(format!("other block import error: {:?}", e)), + } + } +}