Custom attribute for binary serialization (#3922)

* derive(Binary) -> binary

* ethcore types refact

* fixup ethcore

* make binary optional

* fix common types

* fix updater

* remove condition
This commit is contained in:
Nikolay Volf 2016-12-21 18:09:35 +04:00 committed by Gav Wood
parent b369939f20
commit af501e6467
39 changed files with 268 additions and 160 deletions

View File

@ -20,7 +20,7 @@ use util::H256;
/// Either a hash or a number. /// Either a hash or a number.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub enum HashOrNumber { pub enum HashOrNumber {
/// Block hash variant. /// Block hash variant.
Hash(H256), Hash(H256),
@ -42,7 +42,7 @@ impl From<u64> for HashOrNumber {
/// A request for block headers. /// A request for block headers.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct Headers { pub struct Headers {
/// Starting block number or hash. /// Starting block number or hash.
pub start: HashOrNumber, pub start: HashOrNumber,
@ -56,7 +56,7 @@ pub struct Headers {
/// A request for specific block bodies. /// A request for specific block bodies.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct Bodies { pub struct Bodies {
/// Hashes which bodies are being requested for. /// Hashes which bodies are being requested for.
pub block_hashes: Vec<H256> pub block_hashes: Vec<H256>
@ -67,7 +67,7 @@ pub struct Bodies {
/// This request is answered with a list of transaction receipts for each block /// This request is answered with a list of transaction receipts for each block
/// requested. /// requested.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct Receipts { pub struct Receipts {
/// Block hashes to return receipts for. /// Block hashes to return receipts for.
pub block_hashes: Vec<H256>, pub block_hashes: Vec<H256>,
@ -75,7 +75,7 @@ pub struct Receipts {
/// A request for a state proof /// A request for a state proof
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct StateProof { pub struct StateProof {
/// Block hash to query state from. /// Block hash to query state from.
pub block: H256, pub block: H256,
@ -90,7 +90,7 @@ pub struct StateProof {
/// A request for state proofs. /// A request for state proofs.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct StateProofs { pub struct StateProofs {
/// All the proof requests. /// All the proof requests.
pub requests: Vec<StateProof>, pub requests: Vec<StateProof>,
@ -98,7 +98,7 @@ pub struct StateProofs {
/// A request for contract code. /// A request for contract code.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct ContractCode { pub struct ContractCode {
/// Block hash /// Block hash
pub block_hash: H256, pub block_hash: H256,
@ -108,7 +108,7 @@ pub struct ContractCode {
/// A request for contract code. /// A request for contract code.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct ContractCodes { pub struct ContractCodes {
/// Block hash and account key (== sha3(address)) pairs to fetch code for. /// Block hash and account key (== sha3(address)) pairs to fetch code for.
pub code_requests: Vec<ContractCode>, pub code_requests: Vec<ContractCode>,
@ -116,7 +116,7 @@ pub struct ContractCodes {
/// A request for a header proof from the Canonical Hash Trie. /// A request for a header proof from the Canonical Hash Trie.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct HeaderProof { pub struct HeaderProof {
/// Number of the CHT. /// Number of the CHT.
pub cht_number: u64, pub cht_number: u64,
@ -128,7 +128,7 @@ pub struct HeaderProof {
/// A request for header proofs from the CHT. /// A request for header proofs from the CHT.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct HeaderProofs { pub struct HeaderProofs {
/// All the proof requests. /// All the proof requests.
pub requests: Vec<HeaderProof>, pub requests: Vec<HeaderProof>,
@ -136,7 +136,7 @@ pub struct HeaderProofs {
/// Kinds of requests. /// Kinds of requests.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub enum Kind { pub enum Kind {
/// Requesting headers. /// Requesting headers.
Headers, Headers,
@ -154,7 +154,7 @@ pub enum Kind {
/// Encompasses all possible types of requests in a single structure. /// Encompasses all possible types of requests in a single structure.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub enum Request { pub enum Request {
/// Requesting headers. /// Requesting headers.
Headers(Headers), Headers(Headers),

View File

@ -17,7 +17,6 @@
//! Types used in the public (IPC) api which require custom code generation. //! Types used in the public (IPC) api which require custom code generation.
#![cfg_attr(feature = "ipc", allow(dead_code, unused_assignments, unused_variables))] // codegen issues #![cfg_attr(feature = "ipc", allow(dead_code, unused_assignments, unused_variables))] // codegen issues
#[cfg(feature = "ipc")] #[cfg(feature = "ipc")]
include!(concat!(env!("OUT_DIR"), "/mod.rs.in")); include!(concat!(env!("OUT_DIR"), "/mod.rs.in"));

View File

@ -22,7 +22,8 @@ use std::collections::BTreeMap;
use util::{U256, H256, Uint, Bytes}; use util::{U256, H256, Uint, Bytes};
use ipc::binary::BinaryConvertable; use ipc::binary::BinaryConvertable;
#[derive(Debug, PartialEq, Eq, Clone, Binary)] #[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
/// Diff type for specifying a change (or not). /// Diff type for specifying a change (or not).
pub enum Diff<T> where T: Eq + BinaryConvertable { pub enum Diff<T> where T: Eq + BinaryConvertable {
/// Both sides are the same. /// Both sides are the same.
@ -49,7 +50,8 @@ impl<T> Diff<T> where T: Eq + BinaryConvertable {
pub fn is_same(&self) -> bool { match *self { Diff::Same => true, _ => false }} pub fn is_same(&self) -> bool { match *self { Diff::Same => true, _ => false }}
} }
#[derive(Debug, PartialEq, Eq, Clone, Binary)] #[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
/// Account diff. /// Account diff.
pub struct AccountDiff { pub struct AccountDiff {
/// Change in balance, allowed to be `Diff::Same`. /// Change in balance, allowed to be `Diff::Same`.
@ -62,7 +64,8 @@ pub struct AccountDiff {
pub storage: BTreeMap<H256, Diff<H256>>, pub storage: BTreeMap<H256, Diff<H256>>,
} }
#[derive(Debug, PartialEq, Eq, Clone, Binary)] #[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
/// Change in existance type. /// Change in existance type.
// TODO: include other types of change. // TODO: include other types of change.
pub enum Existance { pub enum Existance {

View File

@ -20,7 +20,8 @@ use error::{ImportError, BlockError, Error};
use std::convert::From; use std::convert::From;
/// Error dedicated to import block function /// Error dedicated to import block function
#[derive(Binary, Debug)] #[derive(Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub enum BlockImportError { pub enum BlockImportError {
/// Import error /// Import error
Import(ImportError), Import(ImportError),

View File

@ -18,7 +18,8 @@
use verification::queue::Status as QueueStatus; use verification::queue::Status as QueueStatus;
/// General block status /// General block status
#[derive(Debug, Eq, PartialEq, Binary)] #[derive(Debug, Eq, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub enum BlockStatus { pub enum BlockStatus {
/// Part of the blockchain. /// Part of the blockchain.
InChain, InChain,

View File

@ -21,7 +21,8 @@ use header::BlockNumber;
use types::security_level::SecurityLevel; use types::security_level::SecurityLevel;
/// Information about the blockchain gathered together. /// Information about the blockchain gathered together.
#[derive(Clone, Debug, Binary)] #[derive(Clone, Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub struct BlockChainInfo { pub struct BlockChainInfo {
/// Blockchain difficulty. /// Blockchain difficulty.
pub total_difficulty: U256, pub total_difficulty: U256,

View File

@ -17,7 +17,8 @@
//! Call analytics related types //! Call analytics related types
/// Options concerning what analytics we run on the call. /// Options concerning what analytics we run on the call.
#[derive(Eq, PartialEq, Default, Clone, Copy, Debug, Binary)] #[derive(Eq, PartialEq, Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub struct CallAnalytics { pub struct CallAnalytics {
/// Make a transaction trace. /// Make a transaction trace.
pub transaction_tracing: bool, pub transaction_tracing: bool,

View File

@ -24,7 +24,8 @@ use types::state_diff::StateDiff;
use std::fmt; use std::fmt;
/// The type of the call-like instruction. /// The type of the call-like instruction.
#[derive(Debug, PartialEq, Clone, Binary)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub enum CallType { pub enum CallType {
/// Not a CALL. /// Not a CALL.
None, None,
@ -61,7 +62,8 @@ impl Decodable for CallType {
} }
/// Transaction execution receipt. /// Transaction execution receipt.
#[derive(Debug, PartialEq, Clone, Binary)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub struct Executed { pub struct Executed {
/// Gas paid up front for execution of transaction. /// Gas paid up front for execution of transaction.
pub gas: U256, pub gas: U256,
@ -101,7 +103,8 @@ pub struct Executed {
} }
/// Result of executing the transaction. /// Result of executing the transaction.
#[derive(PartialEq, Debug, Clone, Binary)] #[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub enum ExecutionError { pub enum ExecutionError {
/// Returned when there gas paid for transaction execution is /// Returned when there gas paid for transaction execution is
/// lower than base gas required. /// lower than base gas required.
@ -168,7 +171,8 @@ impl fmt::Display for ExecutionError {
} }
/// Result of executing the transaction. /// Result of executing the transaction.
#[derive(PartialEq, Debug, Clone, Binary)] #[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub enum CallError { pub enum CallError {
/// Couldn't find the transaction in the chain. /// Couldn't find the transaction in the chain.
TransactionNotFound, TransactionNotFound,

View File

@ -22,7 +22,8 @@ use client::BlockId;
use log_entry::LogEntry; use log_entry::LogEntry;
/// Blockchain Filter. /// Blockchain Filter.
#[derive(Binary, Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct Filter { pub struct Filter {
/// Blockchain will be searched from this block. /// Blockchain will be searched from this block.
pub from_block: BlockId, pub from_block: BlockId,

View File

@ -20,7 +20,8 @@ use util::hash::H256;
use header::BlockNumber; use header::BlockNumber;
/// Uniquely identifies block. /// Uniquely identifies block.
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq, Binary)] #[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub enum BlockId { pub enum BlockId {
/// Block's sha3. /// Block's sha3.
/// Querying by hash is always faster. /// Querying by hash is always faster.
@ -36,7 +37,8 @@ pub enum BlockId {
} }
/// Uniquely identifies transaction. /// Uniquely identifies transaction.
#[derive(Debug, PartialEq, Clone, Hash, Eq, Binary)] #[derive(Debug, PartialEq, Clone, Hash, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub enum TransactionId { pub enum TransactionId {
/// Transaction's sha3. /// Transaction's sha3.
Hash(H256), Hash(H256),
@ -46,7 +48,7 @@ pub enum TransactionId {
} }
/// Uniquely identifies Trace. /// Uniquely identifies Trace.
#[derive(Binary)] #[cfg_attr(feature = "ipc", binary)]
pub struct TraceId { pub struct TraceId {
/// Transaction /// Transaction
pub transaction: TransactionId, pub transaction: TransactionId,
@ -55,7 +57,8 @@ pub struct TraceId {
} }
/// Uniquely identifies Uncle. /// Uniquely identifies Uncle.
#[derive(Debug, PartialEq, Eq, Copy, Clone, Binary)] #[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub struct UncleId { pub struct UncleId {
/// Block id. /// Block id.
pub block: BlockId, pub block: BlockId,

View File

@ -26,7 +26,8 @@ use header::BlockNumber;
use ethjson; use ethjson;
/// A record of execution for a `LOG` operation. /// A record of execution for a `LOG` operation.
#[derive(Default, Debug, Clone, PartialEq, Eq, Binary)] #[derive(Default, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct LogEntry { pub struct LogEntry {
/// The address of the contract executing at the point of the `LOG` operation. /// The address of the contract executing at the point of the `LOG` operation.
pub address: Address, pub address: Address,
@ -81,7 +82,8 @@ impl From<ethjson::state::Log> for LogEntry {
} }
/// Log localized in a blockchain. /// Log localized in a blockchain.
#[derive(Default, Debug, PartialEq, Clone, Binary)] #[derive(Default, Debug, PartialEq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub struct LocalizedLogEntry { pub struct LocalizedLogEntry {
/// Plain log entry. /// Plain log entry.
pub entry: LogEntry, pub entry: LogEntry,

View File

@ -16,5 +16,10 @@
//! Types used in the public api //! Types used in the public api
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues #![cfg_attr(feature = "ipc", allow(dead_code, unused_assignments, unused_variables))] // codegen issues
#[cfg(feature = "ipc")]
include!(concat!(env!("OUT_DIR"), "/mod.rs.in")); include!(concat!(env!("OUT_DIR"), "/mod.rs.in"));
#[cfg(not(feature = "ipc"))]
include!("mod.rs.in");

View File

@ -20,7 +20,8 @@ pub use std::time::Duration;
use client::Mode as ClientMode; use client::Mode as ClientMode;
/// IPC-capable shadow-type for `client::config::Mode` /// IPC-capable shadow-type for `client::config::Mode`
#[derive(Clone, Binary, Debug)] #[derive(Clone, Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub enum Mode { pub enum Mode {
/// Same as `ClientMode::Off`. /// Same as `ClientMode::Off`.
Off, Off,

View File

@ -21,7 +21,8 @@
//! of which portions of the ancient chain and current state trie are stored as well. //! of which portions of the ancient chain and current state trie are stored as well.
/// Client pruning info. See module-level docs for more details. /// Client pruning info. See module-level docs for more details.
#[derive(Debug, Clone, Binary)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub struct PruningInfo { pub struct PruningInfo {
/// The first block which everything can be served after. /// The first block which everything can be served after.
pub earliest_chain: u64, pub earliest_chain: u64,

View File

@ -25,7 +25,8 @@ use header::BlockNumber;
use log_entry::{LogEntry, LocalizedLogEntry}; use log_entry::{LogEntry, LocalizedLogEntry};
/// Information describing execution of a transaction. /// Information describing execution of a transaction.
#[derive(Default, Debug, Clone, Binary)] #[derive(Default, Debug, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub struct Receipt { pub struct Receipt {
/// The state root after executing the transaction. /// The state root after executing the transaction.
pub state_root: H256, pub state_root: H256,
@ -79,7 +80,8 @@ impl HeapSizeOf for Receipt {
} }
/// Receipt with additional info. /// Receipt with additional info.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct RichReceipt { pub struct RichReceipt {
/// Transaction hash. /// Transaction hash.
pub transaction_hash: H256, pub transaction_hash: H256,
@ -100,7 +102,8 @@ pub struct RichReceipt {
} }
/// Receipt with additional info. /// Receipt with additional info.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct LocalizedReceipt { pub struct LocalizedReceipt {
/// Transaction hash. /// Transaction hash.
pub transaction_hash: H256, pub transaction_hash: H256,

View File

@ -17,7 +17,8 @@
//! Restoration status type definition //! Restoration status type definition
/// Statuses for restorations. /// Statuses for restorations.
#[derive(PartialEq, Eq, Clone, Copy, Debug, Binary)] #[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub enum RestorationStatus { pub enum RestorationStatus {
/// No restoration. /// No restoration.
Inactive, Inactive,

View File

@ -19,7 +19,8 @@
use header::BlockNumber; use header::BlockNumber;
/// Indication of how secure the chain is. /// Indication of how secure the chain is.
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq, Binary)] #[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub enum SecurityLevel { pub enum SecurityLevel {
/// All blocks from genesis to chain head are known to have valid state transitions and PoW. /// All blocks from genesis to chain head are known to have valid state transitions and PoW.
FullState, FullState,

View File

@ -21,7 +21,8 @@ use rlp::*;
use util::Bytes; use util::Bytes;
/// Manifest data. /// Manifest data.
#[derive(Debug, Clone, PartialEq, Eq, Binary)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct ManifestData { pub struct ManifestData {
/// List of state chunk hashes. /// List of state chunk hashes.
pub state_hashes: Vec<H256>, pub state_hashes: Vec<H256>,

View File

@ -22,7 +22,8 @@ use std::collections::BTreeMap;
use util::Address; use util::Address;
use account_diff::*; use account_diff::*;
#[derive(Debug, PartialEq, Eq, Clone, Binary)] #[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
/// Expression for the delta between two system states. Encoded the /// Expression for the delta between two system states. Encoded the
/// delta of every altered account. /// delta of every altered account.
pub struct StateDiff { pub struct StateDiff {

View File

@ -21,7 +21,7 @@ use util::{Address};
use types::ids::BlockId; use types::ids::BlockId;
/// Easy to use trace filter. /// Easy to use trace filter.
#[derive(Binary)] #[cfg_attr(feature = "ipc", binary)]
pub struct Filter { pub struct Filter {
/// Range of filtering. /// Range of filtering.
pub range: Range<BlockId>, pub range: Range<BlockId>,

View File

@ -21,7 +21,8 @@ use rlp::{Encodable, RlpStream, Decodable, Decoder, DecoderError, Stream, View};
use evm::Error as EvmError; use evm::Error as EvmError;
/// Trace evm errors. /// Trace evm errors.
#[derive(Debug, PartialEq, Clone, Binary)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub enum Error { pub enum Error {
/// `OutOfGas` is returned when transaction execution runs out of gas. /// `OutOfGas` is returned when transaction execution runs out of gas.
OutOfGas, OutOfGas,

View File

@ -28,7 +28,8 @@ use types::trace_types::trace::{Action, Res};
/// Addresses filter. /// Addresses filter.
/// ///
/// Used to create bloom possibilities and match filters. /// Used to create bloom possibilities and match filters.
#[derive(Debug, Binary)] #[derive(Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub struct AddressesFilter { pub struct AddressesFilter {
list: Vec<Address> list: Vec<Address>
} }
@ -74,7 +75,8 @@ impl AddressesFilter {
} }
} }
#[derive(Debug, Binary)] #[derive(Debug)]
#[cfg_attr(feature = "ipc", binary)]
/// Traces filter. /// Traces filter.
pub struct Filter { pub struct Filter {
/// Block range. /// Block range.

View File

@ -25,7 +25,8 @@ use super::trace::{Action, Res};
/// Trace localized in vector of traces produced by a single transaction. /// Trace localized in vector of traces produced by a single transaction.
/// ///
/// Parent and children indexes refer to positions in this vector. /// Parent and children indexes refer to positions in this vector.
#[derive(Debug, PartialEq, Clone, Binary)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub struct FlatTrace { pub struct FlatTrace {
/// Type of action performed by a transaction. /// Type of action performed by a transaction.
pub action: Action, pub action: Action,

View File

@ -21,7 +21,8 @@ use super::trace::{Action, Res};
use header::BlockNumber; use header::BlockNumber;
/// Localized trace. /// Localized trace.
#[derive(Debug, PartialEq, Clone, Binary)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub struct LocalizedTrace { pub struct LocalizedTrace {
/// Type of action performed by a transaction. /// Type of action performed by a transaction.
pub action: Action, pub action: Action,

View File

@ -27,7 +27,8 @@ use types::executed::CallType;
use super::error::Error; use super::error::Error;
/// `Call` result. /// `Call` result.
#[derive(Debug, Clone, PartialEq, Default, Binary)] #[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "ipc", binary)]
pub struct CallResult { pub struct CallResult {
/// Gas used by call. /// Gas used by call.
pub gas_used: U256, pub gas_used: U256,
@ -56,7 +57,8 @@ impl Decodable for CallResult {
} }
/// `Create` result. /// `Create` result.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct CreateResult { pub struct CreateResult {
/// Gas used by create. /// Gas used by create.
pub gas_used: U256, pub gas_used: U256,
@ -96,7 +98,8 @@ impl CreateResult {
} }
/// Description of a _call_ action, either a `CALL` operation or a message transction. /// Description of a _call_ action, either a `CALL` operation or a message transction.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct Call { pub struct Call {
/// The sending account. /// The sending account.
pub from: Address, pub from: Address,
@ -163,7 +166,8 @@ impl Call {
} }
/// Description of a _create_ action, either a `CREATE` operation or a create transction. /// Description of a _create_ action, either a `CREATE` operation or a create transction.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct Create { pub struct Create {
/// The address of the creator. /// The address of the creator.
pub from: Address, pub from: Address,
@ -219,7 +223,8 @@ impl Create {
} }
/// Suicide action. /// Suicide action.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct Suicide { pub struct Suicide {
/// Suicided address. /// Suicided address.
pub address: Address, pub address: Address,
@ -261,7 +266,8 @@ impl Decodable for Suicide {
/// Description of an action that we trace; will be either a call or a create. /// Description of an action that we trace; will be either a call or a create.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub enum Action { pub enum Action {
/// It's a call action. /// It's a call action.
Call(Call), Call(Call),
@ -316,7 +322,8 @@ impl Action {
} }
/// The result of the performed action. /// The result of the performed action.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
pub enum Res { pub enum Res {
/// Successful call action result. /// Successful call action result.
Call(CallResult), Call(CallResult),
@ -386,7 +393,8 @@ impl Res {
} }
} }
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
/// A diff of some chunk of memory. /// A diff of some chunk of memory.
pub struct MemoryDiff { pub struct MemoryDiff {
/// Offset into memory the change begins. /// Offset into memory the change begins.
@ -413,7 +421,8 @@ impl Decodable for MemoryDiff {
} }
} }
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
/// A diff of some storage value. /// A diff of some storage value.
pub struct StorageDiff { pub struct StorageDiff {
/// Which key in storage is changed. /// Which key in storage is changed.
@ -440,7 +449,8 @@ impl Decodable for StorageDiff {
} }
} }
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "ipc", binary)]
/// A record of an executed VM operation. /// A record of an executed VM operation.
pub struct VMExecutedOperation { pub struct VMExecutedOperation {
/// The total gas used. /// The total gas used.
@ -475,7 +485,8 @@ impl Decodable for VMExecutedOperation {
} }
} }
#[derive(Debug, Clone, PartialEq, Binary, Default)] #[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "ipc", binary)]
/// A record of the execution of a single VM operation. /// A record of the execution of a single VM operation.
pub struct VMOperation { pub struct VMOperation {
/// The program counter. /// The program counter.
@ -512,7 +523,8 @@ impl Decodable for VMOperation {
} }
} }
#[derive(Debug, Clone, PartialEq, Binary, Default)] #[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "ipc", binary)]
/// A record of a full VM trace for a CALL/CREATE. /// A record of a full VM trace for a CALL/CREATE.
pub struct VMTrace { pub struct VMTrace {
/// The step (i.e. index into operations) at which this trace corresponds. /// The step (i.e. index into operations) at which this trace corresponds.

View File

@ -27,7 +27,8 @@ use evm::Schedule;
use header::BlockNumber; use header::BlockNumber;
use ethjson; use ethjson;
#[derive(Debug, Clone, PartialEq, Eq, Binary)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", binary)]
/// Transaction action type. /// Transaction action type.
pub enum Action { pub enum Action {
/// Create creates new contract. /// Create creates new contract.
@ -54,7 +55,8 @@ impl Decodable for Action {
/// A set of information describing an externally-originating message call /// A set of information describing an externally-originating message call
/// or contract creation operation. /// or contract creation operation.
#[derive(Default, Debug, Clone, PartialEq, Eq, Binary)] #[derive(Default, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct Transaction { pub struct Transaction {
/// Nonce. /// Nonce.
pub nonce: U256, pub nonce: U256,
@ -205,7 +207,8 @@ impl Transaction {
} }
/// Signed transaction information. /// Signed transaction information.
#[derive(Debug, Clone, Eq, Binary)] #[derive(Debug, Clone, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct SignedTransaction { pub struct SignedTransaction {
/// Plain Transaction. /// Plain Transaction.
unsigned: Transaction, unsigned: Transaction,
@ -370,7 +373,8 @@ impl SignedTransaction {
} }
/// Signed Transaction that is a part of canon blockchain. /// Signed Transaction that is a part of canon blockchain.
#[derive(Debug, PartialEq, Eq, Binary)] #[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct LocalizedTransaction { pub struct LocalizedTransaction {
/// Signed part. /// Signed part.
pub signed: SignedTransaction, pub signed: SignedTransaction,
@ -391,7 +395,8 @@ impl Deref for LocalizedTransaction {
} }
/// Queued transaction with additional information. /// Queued transaction with additional information.
#[derive(Debug, Clone, PartialEq, Eq, Binary)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", binary)]
pub struct PendingTransaction { pub struct PendingTransaction {
/// Signed transaction data. /// Signed transaction data.
pub transaction: SignedTransaction, pub transaction: SignedTransaction,
@ -495,14 +500,14 @@ fn should_agree_with_vitalik() {
flushln!("networkid: {:?}", signed.network_id()); flushln!("networkid: {:?}", signed.network_id());
}; };
test_vector("f864808504a817c800825208943535353535353535353535353535353535353535808025a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116da0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", "0xf0f6f18bca1b28cd68e4357452947e021241e9ce") test_vector("f864808504a817c800825208943535353535353535353535353535353535353535808025a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116da0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", "0xf0f6f18bca1b28cd68e4357452947e021241e9ce");
test_vector("f864018504a817c80182a410943535353535353535353535353535353535353535018025a0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bcaa0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6", "0x23ef145a395ea3fa3deb533b8a9e1b4c6c25d112") test_vector("f864018504a817c80182a410943535353535353535353535353535353535353535018025a0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bcaa0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6", "0x23ef145a395ea3fa3deb533b8a9e1b4c6c25d112");
test_vector("f864028504a817c80282f618943535353535353535353535353535353535353535088025a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", "0x2e485e0c23b4c3c542628a5f672eeab0ad4888be") test_vector("f864028504a817c80282f618943535353535353535353535353535353535353535088025a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", "0x2e485e0c23b4c3c542628a5f672eeab0ad4888be");
test_vector("f865038504a817c803830148209435353535353535353535353535353535353535351b8025a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4e0a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4de", "0x82a88539669a3fd524d669e858935de5e5410cf0") test_vector("f865038504a817c803830148209435353535353535353535353535353535353535351b8025a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4e0a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4de", "0x82a88539669a3fd524d669e858935de5e5410cf0");
test_vector("f865048504a817c80483019a28943535353535353535353535353535353535353535408025a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c063a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c060", "0xf9358f2538fd5ccfeb848b64a96b743fcc930554") test_vector("f865048504a817c80483019a28943535353535353535353535353535353535353535408025a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c063a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c060", "0xf9358f2538fd5ccfeb848b64a96b743fcc930554");
test_vector("f865058504a817c8058301ec309435353535353535353535353535353535353535357d8025a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", "0xa8f7aba377317440bc5b26198a363ad22af1f3a4") test_vector("f865058504a817c8058301ec309435353535353535353535353535353535353535357d8025a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", "0xa8f7aba377317440bc5b26198a363ad22af1f3a4");
test_vector("f866068504a817c80683023e3894353535353535353535353535353535353535353581d88025a06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2fa06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2d", "0xf1f571dc362a0e5b2696b8e775f8491d3e50de35") test_vector("f866068504a817c80683023e3894353535353535353535353535353535353535353581d88025a06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2fa06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2d", "0xf1f571dc362a0e5b2696b8e775f8491d3e50de35");
test_vector("f867078504a817c807830290409435353535353535353535353535353535353535358201578025a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", "0xd37922162ab7cea97c97a87551ed02c9a38b7332") test_vector("f867078504a817c807830290409435353535353535353535353535353535353535358201578025a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", "0xd37922162ab7cea97c97a87551ed02c9a38b7332");
test_vector("f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", "0x9bddad43f934d313c2b79ca28a432dd2b7281029") test_vector("f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", "0x9bddad43f934d313c2b79ca28a432dd2b7281029");
test_vector("f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", "0x3c24d7329e92f84f08556ceb6df1cdb0104ca49f") test_vector("f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", "0x3c24d7329e92f84f08556ceb6df1cdb0104ca49f");
} }

View File

@ -31,7 +31,8 @@ pub enum TransactionImportResult {
binary_fixed_size!(TransactionImportResult); binary_fixed_size!(TransactionImportResult);
/// Api-level error for transaction import /// Api-level error for transaction import
#[derive(Debug, Clone, Binary)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "ipc", binary)]
pub enum TransactionImportError { pub enum TransactionImportError {
/// Transaction error /// Transaction error
Transaction(TransactionError), Transaction(TransactionError),

View File

@ -19,7 +19,8 @@
use util::H256; use util::H256;
/// Represents a tree route between `from` block and `to` block: /// Represents a tree route between `from` block and `to` block:
#[derive(Debug, Binary)] #[derive(Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub struct TreeRoute { pub struct TreeRoute {
/// A vector of hashes of all blocks, ordered from `from` to `to`. /// A vector of hashes of all blocks, ordered from `from` to `to`.
pub blocks: Vec<H256>, pub blocks: Vec<H256>,

View File

@ -17,7 +17,8 @@
//! Verification queue info types //! Verification queue info types
/// Verification queue status /// Verification queue status
#[derive(Debug, Binary)] #[derive(Debug)]
#[cfg_attr(feature = "ipc", binary)]
pub struct VerificationQueueInfo { pub struct VerificationQueueInfo {
/// Number of queued items pending verification /// Number of queued items pending verification
pub unverified_queue_size: usize, pub unverified_queue_size: usize,

View File

@ -19,7 +19,8 @@
use std::fmt; use std::fmt;
/// A release's track. /// A release's track.
#[derive(PartialEq, Eq, Clone, Copy, Debug, Binary)] #[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[binary]
pub enum ReleaseTrack { pub enum ReleaseTrack {
/// Stable track. /// Stable track.
Stable, Stable,

View File

@ -23,7 +23,8 @@ use util::misc::raw_package_info;
use release_track::ReleaseTrack; use release_track::ReleaseTrack;
/// Version information of a particular release. /// Version information of a particular release.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[binary]
pub struct VersionInfo { pub struct VersionInfo {
/// The track on which it was released. /// The track on which it was released.
pub track: ReleaseTrack, pub track: ReleaseTrack,

View File

@ -111,7 +111,7 @@ fn push_invoke_signature_aster(
let arg_ty = &inputs[skip-1].ty; let arg_ty = &inputs[skip-1].ty;
let mut tree = builder.item() let mut tree = builder.item()
.attr().word("derive(Binary)") .attr().word("binary")
.attr().word("allow(non_camel_case_types)") .attr().word("allow(non_camel_case_types)")
.struct_(name_str.as_str()) .struct_(name_str.as_str())
.field(arg_name.as_str()) .field(arg_name.as_str())
@ -140,7 +140,7 @@ fn push_invoke_signature_aster(
FunctionRetTy::Ty(ref ty) => { FunctionRetTy::Ty(ref ty) => {
let name_str = format!("{}_output", named_signature.ident.name.as_str()); let name_str = format!("{}_output", named_signature.ident.name.as_str());
let tree = builder.item() let tree = builder.item()
.attr().word("derive(Binary)") .attr().word("binary")
.attr().word("allow(non_camel_case_types)") .attr().word("allow(non_camel_case_types)")
.struct_(name_str.as_str()) .struct_(name_str.as_str())
.field(format!("payload")).ty().build(ty.clone()); .field(format!("payload")).ty().build(ty.clone());
@ -326,7 +326,7 @@ pub fn has_ptr(ty: &P<ast::Ty>) -> bool {
/// fn commit(&self, f: u32) -> u32 /// fn commit(&self, f: u32) -> u32
/// ///
/// the expanded implementation will generate method for the client like that /// the expanded implementation will generate method for the client like that
/// #[derive(Serialize)] /// #[binary]
/// struct Request<'a> { /// struct Request<'a> {
/// f: &'a u32, /// f: &'a u32,
/// } /// }
@ -358,7 +358,7 @@ fn implement_client_method_body(
.build(static_ty.clone()); .build(static_ty.clone());
let mut tree = builder.item() let mut tree = builder.item()
.attr().word("derive(Binary)") .attr().word("binary")
.struct_("Request") .struct_("Request")
.generics() .generics()
.lifetime_name("'a") .lifetime_name("'a")

View File

@ -42,6 +42,10 @@ extern crate rustc_plugin;
#[cfg(not(feature = "with-syntex"))] #[cfg(not(feature = "with-syntex"))]
use syntax::feature_gate::AttributeType; use syntax::feature_gate::AttributeType;
#[cfg(feature = "with-syntex")]
use syntax::{ast, fold};
#[cfg(feature = "with-syntex")] #[cfg(feature = "with-syntex")]
include!(concat!(env!("OUT_DIR"), "/lib.rs")); include!(concat!(env!("OUT_DIR"), "/lib.rs"));
@ -56,17 +60,16 @@ pub fn expand(src: &std::path::Path, dst: &std::path::Path) {
} }
#[cfg(feature = "with-syntex")] #[cfg(feature = "with-syntex")]
pub fn register_cleaner(reg: &mut syntex::Registry) { struct StripAttributeFolder<'a> {
use syntax::{ast, fold}; attr_title: &'a str,
}
#[cfg(feature = "with-syntex")] #[cfg(feature = "with-syntex")]
fn strip_attributes(krate: ast::Crate) -> ast::Crate { impl<'a> fold::Folder for StripAttributeFolder<'a> {
struct StripAttributeFolder;
impl fold::Folder for StripAttributeFolder {
fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> { fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
match attr.node.value.node { match attr.node.value.node {
ast::MetaItemKind::List(ref n, _) if n == &"ipc" => { return None; } ast::MetaItemKind::List(ref n, _) if n == self.attr_title => { return None; }
ast::MetaItemKind::Word(ref n) if n == &"ipc" => { return None; } ast::MetaItemKind::Word(ref n) if n == self.attr_title => { return None; }
_ => {} _ => {}
} }
@ -78,7 +81,23 @@ pub fn register_cleaner(reg: &mut syntex::Registry) {
} }
} }
fold::Folder::fold_crate(&mut StripAttributeFolder, krate) #[cfg(feature = "with-syntex")]
pub fn register_cleaner_ipc(reg: &mut syntex::Registry) {
#[cfg(feature = "with-syntex")]
fn strip_attributes(krate: ast::Crate) -> ast::Crate {
let mut folder = StripAttributeFolder { attr_title: "ipc" };
fold::Folder::fold_crate(&mut folder, krate)
}
reg.add_post_expansion_pass(strip_attributes);
}
#[cfg(feature = "with-syntex")]
pub fn register_cleaner_binary(reg: &mut syntex::Registry) {
#[cfg(feature = "with-syntex")]
fn strip_attributes(krate: ast::Crate) -> ast::Crate {
let mut folder = StripAttributeFolder { attr_title: "binary" };
fold::Folder::fold_crate(&mut folder, krate)
} }
reg.add_post_expansion_pass(strip_attributes); reg.add_post_expansion_pass(strip_attributes);
@ -90,9 +109,10 @@ pub fn register(reg: &mut syntex::Registry) {
reg.add_attr("feature(custom_attribute)"); reg.add_attr("feature(custom_attribute)");
reg.add_decorator("ipc", codegen::expand_ipc_implementation); reg.add_decorator("ipc", codegen::expand_ipc_implementation);
reg.add_decorator("derive_Binary", serialization::expand_serialization_implementation); reg.add_decorator("binary", serialization::expand_serialization_implementation);
register_cleaner(reg); register_cleaner_ipc(reg);
register_cleaner_binary(reg);
} }
#[cfg(not(feature = "with-syntex"))] #[cfg(not(feature = "with-syntex"))]
@ -102,11 +122,12 @@ pub fn register(reg: &mut rustc_plugin::Registry) {
syntax::ext::base::MultiDecorator( syntax::ext::base::MultiDecorator(
Box::new(codegen::expand_ipc_implementation))); Box::new(codegen::expand_ipc_implementation)));
reg.register_syntax_extension( reg.register_syntax_extension(
syntax::parse::token::intern("derive_Binary"), syntax::parse::token::intern("binary"),
syntax::ext::base::MultiDecorator( syntax::ext::base::MultiDecorator(
Box::new(serialization::expand_serialization_implementation))); Box::new(serialization::expand_serialization_implementation)));
reg.register_attribute("ipc".to_owned(), AttributeType::Normal); reg.register_attribute("ipc".to_owned(), AttributeType::Normal);
reg.register_attribute("binary".to_owned(), AttributeType::Normal);
} }
#[derive(Debug)] #[derive(Debug)]
@ -124,13 +145,31 @@ pub fn derive_ipc_cond(src_path: &str, has_feature: bool) -> Result<(), Error> {
} }
pub fn cleanup_ipc(src_path: &str) -> Result<(), Error> { pub fn cleanup_ipc(src_path: &str) -> Result<(), Error> {
cleanup(src_path, AttributeKind::Ipc)
}
pub fn cleanup_binary(src_path: &str) -> Result<(), Error> {
cleanup(src_path, AttributeKind::Binary)
}
enum AttributeKind {
Ipc,
Binary,
}
fn cleanup(src_path: &str, attr: AttributeKind) -> Result<(), Error> {
use std::env; use std::env;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
let out_dir = env::var_os("OUT_DIR").unwrap(); let out_dir = env::var_os("OUT_DIR").unwrap();
let file_name = try!(PathBuf::from(src_path).file_name().ok_or(Error::InvalidFileName).map(|val| val.to_str().unwrap().to_owned())); let file_name = try!(PathBuf::from(src_path).file_name().ok_or(Error::InvalidFileName).map(|val| val.to_str().unwrap().to_owned()));
let mut registry = syntex::Registry::new(); let mut registry = syntex::Registry::new();
register_cleaner(&mut registry);
match attr {
AttributeKind::Ipc => { register_cleaner_ipc(&mut registry); }
AttributeKind::Binary => { register_cleaner_binary(&mut registry); }
}
if let Err(_) = registry.expand("", &Path::new(src_path), &Path::new(&out_dir).join(&file_name)) if let Err(_) = registry.expand("", &Path::new(src_path), &Path::new(&out_dir).join(&file_name))
{ {
// will be reported by compiler // will be reported by compiler
@ -190,3 +229,8 @@ pub fn derive_binary(src_path: &str) -> Result<(), Error> {
Ok(()) Ok(())
} }
pub fn derive_binary_cond(src_path: &str, has_feature: bool) -> Result<(), Error> {
if has_feature { derive_binary(src_path) }
else { cleanup_binary(src_path) }
}

View File

@ -17,37 +17,40 @@
use util::Bytes; use util::Bytes;
#[derive(Binary)] #[binary]
pub enum Root { pub enum Root {
Top, Top,
Middle(u32, u64), Middle(u32, u64),
} }
#[derive(Binary, PartialEq, Debug)] #[derive(PartialEq, Debug)]
#[binary]
pub struct DoubleRoot { pub struct DoubleRoot {
pub x1: u32, pub x1: u32,
pub x2: u64, pub x2: u64,
pub x3: u32, pub x3: u32,
} }
#[derive(Binary, PartialEq, Debug)] #[derive(PartialEq, Debug)]
#[binary]
pub struct ReferenceStruct<'a> { pub struct ReferenceStruct<'a> {
pub ref_data: &'a u64, pub ref_data: &'a u64,
} }
#[derive(Binary, PartialEq, Debug)] #[derive(PartialEq, Debug)]
#[binary]
pub enum EnumWithStruct { pub enum EnumWithStruct {
Left, Left,
Right { how_much: u64 }, Right { how_much: u64 },
} }
#[derive(Binary)] #[binary]
pub struct TwoVec { pub struct TwoVec {
v1: Vec<u8>, v1: Vec<u8>,
v2: Vec<u8>, v2: Vec<u8>,
} }
#[derive(Binary)] #[binary]
struct ChunkSet { struct ChunkSet {
items: Vec<Bytes>, items: Vec<Bytes>,
} }

View File

@ -30,7 +30,7 @@ pub trait DBWriter {
impl IpcConfig for DBWriter {} impl IpcConfig for DBWriter {}
#[derive(Binary)] #[binary]
pub enum DBError { Write, Read } pub enum DBError { Write, Read }
#[ipc] #[ipc]

View File

@ -22,7 +22,7 @@ pub struct Service {
pub rollbacks: RwLock<usize>, pub rollbacks: RwLock<usize>,
} }
#[derive(Binary)] #[binary]
pub struct CustomData { pub struct CustomData {
pub a: u64, pub a: u64,
pub b: u64, pub b: u64,

View File

@ -19,7 +19,8 @@ use std::error::Error as StdError;
use util::H256; use util::H256;
use ipc::IpcConfig; use ipc::IpcConfig;
#[derive(Debug, Clone, Binary)] #[derive(Debug, Clone)]
#[binary]
pub enum Error { pub enum Error {
NoWork, NoWork,
NoWorkers, NoWorkers,
@ -53,7 +54,7 @@ pub trait PushWorkHandler: Send + Sync {
fn push_work(&self, payloads: Vec<String>) -> Result<(), Error>; fn push_work(&self, payloads: Vec<String>) -> Result<(), Error>;
} }
#[derive(Binary)] #[binary]
pub struct ServiceConfiguration { pub struct ServiceConfiguration {
pub listen_addr: String, pub listen_addr: String,
pub secret: Option<H256>, pub secret: Option<H256>,

View File

@ -431,7 +431,7 @@ impl ManageNetwork for EthSync {
/// IP fiter /// IP fiter
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub enum AllowIP { pub enum AllowIP {
/// Connect to any address /// Connect to any address
All, All,
@ -454,7 +454,7 @@ impl AllowIP {
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
/// Network service configuration /// Network service configuration
pub struct NetworkConfiguration { pub struct NetworkConfiguration {
/// Directory path to store general network configuration. None means nothing will be saved /// Directory path to store general network configuration. None means nothing will be saved
@ -558,7 +558,7 @@ impl From<BasicNetworkConfiguration> for NetworkConfiguration {
/// Configuration for IPC service. /// Configuration for IPC service.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "ipc", derive(Binary))] #[cfg_attr(feature = "ipc", binary)]
pub struct ServiceConfiguration { pub struct ServiceConfiguration {
/// Sync config. /// Sync config.
pub sync: SyncConfig, pub sync: SyncConfig,

View File

@ -20,7 +20,8 @@ use util::{H256};
pub use ipc_common_types::{VersionInfo, ReleaseTrack}; pub use ipc_common_types::{VersionInfo, ReleaseTrack};
/// Information regarding a particular release of Parity /// Information regarding a particular release of Parity
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[binary]
pub struct ReleaseInfo { pub struct ReleaseInfo {
/// Information on the version. /// Information on the version.
pub version: VersionInfo, pub version: VersionInfo,
@ -33,7 +34,8 @@ pub struct ReleaseInfo {
} }
/// Information on our operations environment. /// Information on our operations environment.
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq)]
#[binary]
pub struct OperationsInfo { pub struct OperationsInfo {
/// Our blockchain's latest fork. /// Our blockchain's latest fork.
pub fork: u64, pub fork: u64,
@ -48,7 +50,8 @@ pub struct OperationsInfo {
} }
/// Information on the current version's consensus capabililty. /// Information on the current version's consensus capabililty.
#[derive(Debug, Clone, Copy, PartialEq, Binary)] #[derive(Debug, Clone, Copy, PartialEq)]
#[binary]
pub enum CapState { pub enum CapState {
/// Unknown. /// Unknown.
Unknown, Unknown,