Moving all Client public API types to separate mod & binary serialization codegen for that mod (#1051)

* transaction moved

* trash remove

* ids move

* receipt

* tree-route

* blockchain info

* log_entry move

* trace filter moved

* executed & trace moved

* localized trace moved

* block status moved

* build scripts and codegen refs

* Cargo.lock update

* binary for blockstatus, blockchaininfo

* binary for trace

* trace filters binary ser

* binary for log entries & executed

* binary for receipt

* special case for u8 & transaction binary attribute

* resolved remaining issues & error binary serialization

* json-tests util import

* fix warnings

* ids attr

* add missing attributes

* Update build.rs
This commit is contained in:
Nikolay Volf
2016-05-16 19:33:32 +03:00
committed by Gav Wood
parent 9301963d98
commit 4e41cbca81
32 changed files with 503 additions and 192 deletions

View File

@@ -27,7 +27,7 @@ use chainfilter::{ChainFilter, BloomIndex, FilterDataSource};
use blockchain::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData};
use blockchain::best_block::BestBlock;
use blockchain::bloom_indexer::BloomIndexer;
use blockchain::tree_route::TreeRoute;
use types::tree_route::TreeRoute;
use blockchain::update::ExtrasUpdate;
use blockchain::{CacheSize, ImportRoute};
use db::{Writable, Readable, Key, CacheUpdatePolicy};

View File

@@ -21,7 +21,6 @@ mod best_block;
mod block_info;
mod bloom_indexer;
mod cache;
mod tree_route;
mod update;
mod import_route;
#[cfg(test)]
@@ -29,5 +28,5 @@ mod generator;
pub use self::blockchain::{BlockProvider, BlockChain, BlockChainConfig};
pub use self::cache::CacheSize;
pub use self::tree_route::TreeRoute;
pub use types::tree_route::TreeRoute;
pub use self::import_route::ImportRoute;

View File

@@ -44,34 +44,8 @@ use receipt::LocalizedReceipt;
pub use blockchain::CacheSize as BlockChainCacheSize;
use trace::{TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase};
use trace;
/// General block status
#[derive(Debug, Eq, PartialEq)]
pub enum BlockStatus {
/// Part of the blockchain.
InChain,
/// Queued for import.
Queued,
/// Known as bad.
Bad,
/// Unknown.
Unknown,
}
/// Information about the blockchain gathered together.
#[derive(Debug)]
pub struct BlockChainInfo {
/// Blockchain difficulty.
pub total_difficulty: U256,
/// Block queue difficulty.
pub pending_total_difficulty: U256,
/// Genesis block hash.
pub genesis_hash: H256,
/// Best blockchain block hash.
pub best_block_hash: H256,
/// Best blockchain block number.
pub best_block_number: BlockNumber
}
pub use types::blockchain_info::BlockChainInfo;
pub use types::block_status::BlockStatus;
impl fmt::Display for BlockChainInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

View File

@@ -18,13 +18,12 @@
mod client;
mod config;
mod ids;
mod test_client;
mod trace;
pub use self::client::*;
pub use self::config::{ClientConfig, BlockQueueConfig, BlockChainConfig, Switch};
pub use self::ids::{BlockId, TransactionId, UncleId, TraceId};
pub use types::ids::*;
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use self::trace::Filter as TraceFilter;
pub use executive::{Executed, Executive, TransactOptions};

View File

@@ -20,49 +20,7 @@ use util::*;
use header::BlockNumber;
use basic_types::LogBloom;
/// Result of executing the transaction.
#[derive(PartialEq, Debug)]
pub enum ExecutionError {
/// Returned when there gas paid for transaction execution is
/// lower than base gas required.
NotEnoughBaseGas {
/// Absolute minimum gas required.
required: U256,
/// Gas provided.
got: U256
},
/// 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 of block for transaction.
gas_limit: U256,
/// Gas used in block prior to transaction.
gas_used: U256,
/// Amount of gas in block.
gas: U256
},
/// Returned when transaction nonce does not match state nonce.
InvalidNonce {
/// Nonce expected.
expected: U256,
/// Nonce found.
got: U256
},
/// Returned when cost of transaction (value + gas_price * gas) exceeds
/// current sender balance.
NotEnoughCash {
/// Minimum required balance.
required: U512,
/// Actual balance.
got: U512
},
/// Returned when internal evm error occurs.
Internal,
/// Returned when generic transaction occurs
TransactionMalformed(String),
}
pub use types::executed::ExecutionError;
#[derive(Debug, PartialEq)]
/// Errors concerning transaction processing.

View File

@@ -24,6 +24,8 @@ use substate::*;
use trace::{Trace, Tracer, NoopTracer, ExecutiveTracer};
use crossbeam;
pub use types::executed::{Executed, ExecutionResult};
/// Max depth to avoid stack overflow (when it's reached we start a new thread with VM)
/// TODO [todr] We probably need some more sophisticated calculations here (limit on my machine 132)
/// Maybe something like here: `https://github.com/ethereum/libethereum/blob/4db169b8504f2b87f7d5a481819cfb959fc65f6c/libethereum/ExtVM.cpp`
@@ -45,45 +47,6 @@ pub struct TransactOptions {
pub check_nonce: bool,
}
/// Transaction execution receipt.
#[derive(Debug, PartialEq, Clone)]
pub struct Executed {
/// Gas paid up front for execution of transaction.
pub gas: U256,
/// Gas used during execution of transaction.
pub gas_used: U256,
/// Gas refunded after the execution of transaction.
/// To get gas that was required up front, add `refunded` and `gas_used`.
pub refunded: U256,
/// Cumulative gas used in current block so far.
///
/// `cumulative_gas_used = gas_used(t0) + gas_used(t1) + ... gas_used(tn)`
///
/// where `tn` is current transaction.
pub cumulative_gas_used: U256,
/// Vector of logs generated by transaction.
pub logs: Vec<LogEntry>,
/// Addresses of contracts created during execution of transaction.
/// Ordered from earliest creation.
///
/// eg. sender creates contract A and A in constructor creates contract B
///
/// B creation ends first, and it will be the first element of the vector.
pub contracts_created: Vec<Address>,
/// Transaction output.
pub output: Bytes,
/// The trace of this transaction.
pub trace: Option<Trace>,
}
/// Transaction execution result.
pub type ExecutionResult = Result<Executed, ExecutionError>;
/// Transaction executor.
pub struct Executive<'a> {
state: &'a mut State,

View File

@@ -85,6 +85,7 @@ extern crate num_cpus;
extern crate crossbeam;
extern crate ethjson;
extern crate bloomchain;
#[macro_use] extern crate ethcore_ipc as ipc;
#[cfg(test)] extern crate ethcore_devtools as devtools;
#[cfg(feature = "jit" )] extern crate evmjit;
@@ -98,12 +99,9 @@ pub mod ethereum;
pub mod filter;
pub mod header;
pub mod service;
pub mod log_entry;
pub mod trace;
pub mod spec;
pub mod transaction;
pub mod views;
pub mod receipt;
pub mod pod_state;
mod db;
@@ -128,9 +126,12 @@ mod executive;
mod externalities;
mod verification;
mod blockchain;
mod types;
#[cfg(test)]
mod tests;
#[cfg(test)]
#[cfg(feature="json-tests")]
mod json_tests;
pub use types::*;

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Flat trace module
use trace::BlockTraces;
use super::trace::{Trace, Action, Res};

View File

@@ -21,20 +21,18 @@ mod bloom;
mod config;
mod db;
mod executive_tracer;
mod filter;
mod flat;
pub mod flat;
mod import;
mod localized;
mod noop_tracer;
pub mod trace;
pub use types::trace_types::*;
pub use self::block::BlockTraces;
pub use self::config::{Config, Switch};
pub use self::db::TraceDB;
pub use self::trace::Trace;
pub use types::trace_types::trace::Trace;
pub use self::noop_tracer::NoopTracer;
pub use self::executive_tracer::ExecutiveTracer;
pub use self::filter::{Filter, AddressesFilter};
pub use types::trace_types::filter::{Filter, AddressesFilter};
pub use self::import::ImportRequest;
pub use self::localized::LocalizedTrace;
use util::{Bytes, Address, U256, H256};

View File

@@ -0,0 +1,33 @@
// 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 <http://www.gnu.org/licenses/>.
//! Block status description module
use ipc::binary::BinaryConvertError;
use std::collections::VecDeque;
/// General block status
#[derive(Debug, Eq, PartialEq, Binary)]
pub enum BlockStatus {
/// Part of the blockchain.
InChain,
/// Queued for import.
Queued,
/// Known as bad.
Bad,
/// Unknown.
Unknown,
}

View File

@@ -0,0 +1,38 @@
// 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 <http://www.gnu.org/licenses/>.
//! Blockhain info type definition
use util::numbers::*;
use header::BlockNumber;
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
/// Information about the blockchain gathered together.
#[derive(Debug, Binary)]
pub struct BlockChainInfo {
/// Blockchain difficulty.
pub total_difficulty: U256,
/// Block queue difficulty.
pub pending_total_difficulty: U256,
/// Genesis block hash.
pub genesis_hash: H256,
/// Best blockchain block hash.
pub best_block_hash: H256,
/// Best blockchain block number.
pub best_block_number: BlockNumber
}

View File

@@ -0,0 +1,109 @@
// 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 <http://www.gnu.org/licenses/>.
//! Transaction execution format module.
use util::numbers::*;
use util::Bytes;
use trace::Trace;
use types::log_entry::LogEntry;
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
/// Transaction execution receipt.
#[derive(Debug, PartialEq, Clone, Binary)]
pub struct Executed {
/// Gas paid up front for execution of transaction.
pub gas: U256,
/// Gas used during execution of transaction.
pub gas_used: U256,
/// Gas refunded after the execution of transaction.
/// To get gas that was required up front, add `refunded` and `gas_used`.
pub refunded: U256,
/// Cumulative gas used in current block so far.
///
/// `cumulative_gas_used = gas_used(t0) + gas_used(t1) + ... gas_used(tn)`
///
/// where `tn` is current transaction.
pub cumulative_gas_used: U256,
/// Vector of logs generated by transaction.
pub logs: Vec<LogEntry>,
/// Addresses of contracts created during execution of transaction.
/// Ordered from earliest creation.
///
/// eg. sender creates contract A and A in constructor creates contract B
///
/// B creation ends first, and it will be the first element of the vector.
pub contracts_created: Vec<Address>,
/// Transaction output.
pub output: Bytes,
/// The trace of this transaction.
pub trace: Option<Trace>,
}
/// Result of executing the transaction.
#[derive(PartialEq, Debug, Binary)]
pub enum ExecutionError {
/// Returned when there gas paid for transaction execution is
/// lower than base gas required.
NotEnoughBaseGas {
/// Absolute minimum gas required.
required: U256,
/// Gas provided.
got: U256
},
/// 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 of block for transaction.
gas_limit: U256,
/// Gas used in block prior to transaction.
gas_used: U256,
/// Amount of gas in block.
gas: U256
},
/// Returned when transaction nonce does not match state nonce.
InvalidNonce {
/// Nonce expected.
expected: U256,
/// Nonce found.
got: U256
},
/// Returned when cost of transaction (value + gas_price * gas) exceeds
/// current sender balance.
NotEnoughCash {
/// Minimum required balance.
required: U512,
/// Actual balance.
got: U512
},
/// Returned when internal evm error occurs.
Internal,
/// Returned when generic transaction occurs
TransactionMalformed(String),
}
/// Transaction execution result.
pub type ExecutionResult = Result<Executed, ExecutionError>;

View File

@@ -18,10 +18,13 @@
use util::hash::H256;
use header::BlockNumber;
use util::bytes::{FromRawBytes, FromBytesError, ToBytesWithMap, Populatable};
use ipc::binary::BinaryConvertError;
use ipc::binary::BinaryConvertable;
use std::mem;
use std::collections::VecDeque;
/// Uniquely identifies block.
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
#[derive(Debug, PartialEq, Clone, Hash, Eq, Binary)]
pub enum BlockId {
/// Block's sha3.
/// Querying by hash is always faster.
@@ -35,7 +38,7 @@ pub enum BlockId {
}
/// Uniquely identifies transaction.
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
#[derive(Debug, PartialEq, Clone, Hash, Eq, Binary)]
pub enum TransactionId {
/// Transaction's sha3.
Hash(H256),
@@ -60,7 +63,3 @@ pub struct UncleId (
/// Position in block.
pub usize
);
sized_binary_map!(TransactionId);
sized_binary_map!(UncleId);
sized_binary_map!(BlockId);

View File

@@ -14,15 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Block log.
//! Log entry type definition.
use util::*;
use util::numbers::*;
use std::ops::Deref;
use util::rlp::*;
use util::Bytes;
use util::HeapSizeOf;
use util::sha3::*;
use basic_types::LogBloom;
use header::BlockNumber;
use ethjson;
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
/// A record of execution for a `LOG` operation.
#[derive(Default, Debug, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Binary)]
pub struct LogEntry {
/// The address of the contract executing at the point of the `LOG` operation.
pub address: Address,
@@ -77,7 +85,7 @@ impl From<ethjson::state::Log> for LogEntry {
}
/// Log localized in a blockchain.
#[derive(Default, Debug, PartialEq, Clone)]
#[derive(Default, Debug, PartialEq, Clone, Binary)]
pub struct LocalizedLogEntry {
/// Plain log entry.
pub entry: LogEntry,

20
ethcore/src/types/mod.rs Normal file
View File

@@ -0,0 +1,20 @@
// 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 <http://www.gnu.org/licenses/>.
//! Types used in the public api
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/types.rs"));

View File

@@ -0,0 +1,25 @@
// 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 <http://www.gnu.org/licenses/>.
pub mod transaction;
pub mod ids;
pub mod receipt;
pub mod tree_route;
pub mod blockchain_info;
pub mod log_entry;
pub mod trace_types;
pub mod executed;
pub mod block_status;

View File

@@ -16,13 +16,18 @@
//! Receipt
use util::*;
use util::numbers::*;
use util::rlp::*;
use util::HeapSizeOf;
use basic_types::LogBloom;
use header::BlockNumber;
use log_entry::{LogEntry, LocalizedLogEntry};
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
/// Information describing execution of a transaction.
#[derive(Default, Debug, Clone)]
#[derive(Default, Debug, Clone, Binary)]
pub struct Receipt {
/// The state root after executing the transaction.
pub state_root: H256,
@@ -76,7 +81,7 @@ impl HeapSizeOf for Receipt {
}
/// Receipt with additional info.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Binary)]
pub struct LocalizedReceipt {
/// Transaction hash.
pub transaction_hash: H256,
@@ -98,7 +103,7 @@ pub struct LocalizedReceipt {
#[test]
fn test_basic() {
let expected = FromHex::from_hex("f90162a02f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee83040caeb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000f838f794dcf421d093428b096ca501a7cd1a740855a7976fc0a00000000000000000000000000000000000000000000000000000000000000000").unwrap();
let expected = ::rustc_serialize::hex::FromHex::from_hex("f90162a02f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee83040caeb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000f838f794dcf421d093428b096ca501a7cd1a740855a7976fc0a00000000000000000000000000000000000000000000000000000000000000000").unwrap();
let r = Receipt::new(
x!("2f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee"),
x!(0x40cae),

View File

@@ -14,41 +14,49 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Trace filters type definitions
use std::ops::Range;
use bloomchain::{Filter as BloomFilter, Bloom, Number};
use util::{Address, FixedHash};
use util::sha3::Hashable;
use basic_types::LogBloom;
use super::flat::FlatTrace;
use super::trace::Action;
use trace::flat::FlatTrace;
use types::trace_types::trace::Action;
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
/// Addresses filter.
///
/// Used to create bloom possibilities and match filters.
pub struct AddressesFilter(Vec<Address>);
#[derive(Binary)]
pub struct AddressesFilter {
list: Vec<Address>
}
impl From<Vec<Address>> for AddressesFilter {
fn from(addresses: Vec<Address>) -> Self {
AddressesFilter(addresses)
AddressesFilter { list: addresses }
}
}
impl AddressesFilter {
/// Returns true if address matches one of the searched addresses.
pub fn matches(&self, address: &Address) -> bool {
self.matches_all() || self.0.contains(address)
self.matches_all() || self.list.contains(address)
}
/// Returns true if this address filter matches everything.
pub fn matches_all(&self) -> bool {
self.0.is_empty()
self.list.is_empty()
}
/// Returns blooms of this addresses filter.
pub fn blooms(&self) -> Vec<LogBloom> {
match self.0.is_empty() {
match self.list.is_empty() {
true => vec![LogBloom::new()],
false => self.0.iter()
false => self.list.iter()
.map(|address| LogBloom::from_bloomed(&address.sha3()))
.collect()
}
@@ -56,11 +64,11 @@ impl AddressesFilter {
/// Returns vector of blooms zipped with blooms of this addresses filter.
pub fn with_blooms(&self, blooms: Vec<LogBloom>) -> Vec<LogBloom> {
match self.0.is_empty() {
match self.list.is_empty() {
true => blooms,
false => blooms
.into_iter()
.flat_map(|bloom| self.0.iter()
.flat_map(|bloom| self.list.iter()
.map(|address| bloom.with_bloomed(&address.sha3()))
.collect::<Vec<_>>())
.collect()
@@ -68,6 +76,7 @@ impl AddressesFilter {
}
}
#[derive(Binary)]
/// Traces filter.
pub struct Filter {
/// Block range.

View File

@@ -14,12 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Localized traces type definitions
use util::H256;
use super::trace::{Action, Res};
use header::BlockNumber;
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
/// Localized trace.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Binary)]
pub struct LocalizedTrace {
/// Type of action performed by a transaction.
pub action: Action,

View File

@@ -0,0 +1,21 @@
// 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 <http://www.gnu.org/licenses/>.
//! Types used in the public api
pub mod filter;
pub mod trace;
pub mod localized;

View File

@@ -15,14 +15,18 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Tracing datatypes.
use util::{U256, Bytes, Address, FixedHash};
use util::rlp::*;
use util::sha3::Hashable;
use action_params::ActionParams;
use basic_types::LogBloom;
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
/// `Call` result.
#[derive(Debug, Clone, PartialEq, Default)]
#[derive(Debug, Clone, PartialEq, Default, Binary)]
pub struct CallResult {
/// Gas used by call.
pub gas_used: U256,
@@ -51,7 +55,7 @@ impl Decodable for CallResult {
}
/// `Create` result.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Binary)]
pub struct CreateResult {
/// Gas used by create.
pub gas_used: U256,
@@ -84,7 +88,7 @@ impl Decodable for CreateResult {
}
/// Description of a _call_ action, either a `CALL` operation or a message transction.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Binary)]
pub struct Call {
/// The sending account.
pub from: Address,
@@ -146,7 +150,7 @@ impl Call {
}
/// Description of a _create_ action, either a `CREATE` operation or a create transction.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Binary)]
pub struct Create {
/// The address of the creator.
pub from: Address,
@@ -202,7 +206,7 @@ impl Create {
}
/// Description of an action that we trace; will be either a call or a create.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Binary)]
pub enum Action {
/// It's a call action.
Call(Call),
@@ -249,7 +253,7 @@ impl Action {
}
/// The result of the performed action.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Binary)]
pub enum Res {
/// Successful call action result.
Call(CallResult),
@@ -300,7 +304,7 @@ impl Decodable for Res {
}
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Binary)]
/// A trace; includes a description of the action being traced and sub traces of each interior action.
pub struct Trace {
/// The number of EVM execution environments active when this action happened; 0 if it's

View File

@@ -16,13 +16,21 @@
//! Transaction data structure.
use util::*;
use util::numbers::*;
use std::ops::Deref;
use util::rlp::*;
use util::sha3::*;
use util::{UtilError, CryptoError, Bytes, Signature, Secret, ec};
use std::cell::*;
use error::*;
use evm::Schedule;
use header::BlockNumber;
use ethjson;
use ipc::binary::BinaryConvertError;
use std::mem;
use std::collections::VecDeque;
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Binary)]
/// Transaction action type.
pub enum Action {
/// Create creates new contract.
@@ -48,7 +56,7 @@ impl Decodable for Action {
/// A set of information describing an externally-originating message call
/// or contract creation operation.
#[derive(Default, Debug, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Binary)]
pub struct Transaction {
/// Nonce.
pub nonce: U256,
@@ -183,7 +191,7 @@ impl Transaction {
}
/// Signed transaction information.
#[derive(Debug, Clone, Eq)]
#[derive(Debug, Clone, Eq, Binary)]
pub struct SignedTransaction {
/// Plain Transaction.
unsigned: Transaction,
@@ -310,7 +318,7 @@ impl SignedTransaction {
}
try!(self.sender());
if self.gas < U256::from(self.gas_required(&schedule)) {
Err(From::from(TransactionError::InvalidGasLimit(OutOfBounds{min: Some(U256::from(self.gas_required(&schedule))), max: None, found: self.gas})))
Err(From::from(TransactionError::InvalidGasLimit(::util::OutOfBounds{min: Some(U256::from(self.gas_required(&schedule))), max: None, found: self.gas})))
} else {
Ok(self)
}
@@ -318,7 +326,7 @@ impl SignedTransaction {
}
/// Signed Transaction that is a part of canon blockchain.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Binary)]
pub struct LocalizedTransaction {
/// Signed part.
pub signed: SignedTransaction,
@@ -340,7 +348,7 @@ impl Deref for LocalizedTransaction {
#[test]
fn sender_test() {
let t: SignedTransaction = decode(&FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap());
let t: SignedTransaction = decode(&::rustc_serialize::hex::FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap());
assert_eq!(t.data, b"");
assert_eq!(t.gas, U256::from(0x5208u64));
assert_eq!(t.gas_price, U256::from(0x01u64));
@@ -354,7 +362,7 @@ fn sender_test() {
#[test]
fn signing() {
let key = KeyPair::create().unwrap();
let key = ::util::crypto::KeyPair::create().unwrap();
let t = Transaction {
action: Action::Create,
nonce: U256::from(42),

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Tree route info type definition
use util::numbers::H256;
/// Represents a tree route between `from` block and `to` block: