From af501e64678c384593f9df1b9ddb00bc0caedd29 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Wed, 21 Dec 2016 18:09:35 +0400 Subject: [PATCH] Custom attribute for binary serialization (#3922) * derive(Binary) -> binary * ethcore types refact * fixup ethcore * make binary optional * fix common types * fix updater * remove condition --- ethcore/light/src/types/les_request.rs | 26 +++--- ethcore/light/src/types/mod.rs | 3 +- ethcore/src/types/account_diff.rs | 9 +- ethcore/src/types/block_import_error.rs | 3 +- ethcore/src/types/block_status.rs | 5 +- ethcore/src/types/blockchain_info.rs | 5 +- ethcore/src/types/call_analytics.rs | 3 +- ethcore/src/types/executed.rs | 12 ++- ethcore/src/types/filter.rs | 3 +- ethcore/src/types/ids.rs | 11 ++- ethcore/src/types/log_entry.rs | 6 +- ethcore/src/types/mod.rs | 7 +- ethcore/src/types/mode.rs | 3 +- ethcore/src/types/pruning_info.rs | 5 +- ethcore/src/types/receipt.rs | 9 +- ethcore/src/types/restoration_status.rs | 3 +- ethcore/src/types/security_level.rs | 7 +- ethcore/src/types/snapshot_manifest.rs | 3 +- ethcore/src/types/state_diff.rs | 3 +- ethcore/src/types/trace_filter.rs | 2 +- ethcore/src/types/trace_types/error.rs | 3 +- ethcore/src/types/trace_types/filter.rs | 6 +- ethcore/src/types/trace_types/flat.rs | 3 +- ethcore/src/types/trace_types/localized.rs | 3 +- ethcore/src/types/trace_types/trace.rs | 36 +++++--- ethcore/src/types/transaction.rs | 35 ++++---- ethcore/src/types/transaction_import.rs | 3 +- ethcore/src/types/tree_route.rs | 3 +- ethcore/src/types/verification_queue_info.rs | 5 +- ipc-common-types/src/types/release_track.rs | 45 +++++----- ipc-common-types/src/types/version_info.rs | 5 +- ipc/codegen/src/codegen.rs | 8 +- ipc/codegen/src/lib.rs | 92 +++++++++++++++----- ipc/tests/binary.rs.in | 15 ++-- ipc/tests/nested.rs.in | 2 +- ipc/tests/service.rs.in | 2 +- stratum/src/traits.rs | 5 +- sync/src/api.rs | 8 +- updater/src/types/all.rs | 21 +++-- 39 files changed, 268 insertions(+), 160 deletions(-) diff --git a/ethcore/light/src/types/les_request.rs b/ethcore/light/src/types/les_request.rs index 864f2d4f8..dde8ac2f8 100644 --- a/ethcore/light/src/types/les_request.rs +++ b/ethcore/light/src/types/les_request.rs @@ -20,7 +20,7 @@ use util::H256; /// Either a hash or a number. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub enum HashOrNumber { /// Block hash variant. Hash(H256), @@ -42,7 +42,7 @@ impl From for HashOrNumber { /// A request for block headers. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct Headers { /// Starting block number or hash. pub start: HashOrNumber, @@ -56,7 +56,7 @@ pub struct Headers { /// A request for specific block bodies. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct Bodies { /// Hashes which bodies are being requested for. pub block_hashes: Vec @@ -67,7 +67,7 @@ pub struct Bodies { /// This request is answered with a list of transaction receipts for each block /// requested. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct Receipts { /// Block hashes to return receipts for. pub block_hashes: Vec, @@ -75,7 +75,7 @@ pub struct Receipts { /// A request for a state proof #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct StateProof { /// Block hash to query state from. pub block: H256, @@ -90,7 +90,7 @@ pub struct StateProof { /// A request for state proofs. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct StateProofs { /// All the proof requests. pub requests: Vec, @@ -98,7 +98,7 @@ pub struct StateProofs { /// A request for contract code. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct ContractCode { /// Block hash pub block_hash: H256, @@ -108,7 +108,7 @@ pub struct ContractCode { /// A request for contract code. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct ContractCodes { /// Block hash and account key (== sha3(address)) pairs to fetch code for. pub code_requests: Vec, @@ -116,7 +116,7 @@ pub struct ContractCodes { /// A request for a header proof from the Canonical Hash Trie. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct HeaderProof { /// Number of the CHT. pub cht_number: u64, @@ -128,7 +128,7 @@ pub struct HeaderProof { /// A request for header proofs from the CHT. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct HeaderProofs { /// All the proof requests. pub requests: Vec, @@ -136,7 +136,7 @@ pub struct HeaderProofs { /// Kinds of requests. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub enum Kind { /// Requesting headers. Headers, @@ -154,7 +154,7 @@ pub enum Kind { /// Encompasses all possible types of requests in a single structure. #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub enum Request { /// Requesting headers. Headers(Headers), @@ -194,4 +194,4 @@ impl Request { Request::HeaderProofs(ref req) => req.requests.len(), } } -} \ No newline at end of file +} diff --git a/ethcore/light/src/types/mod.rs b/ethcore/light/src/types/mod.rs index 86d269766..60765dfc5 100644 --- a/ethcore/light/src/types/mod.rs +++ b/ethcore/light/src/types/mod.rs @@ -17,9 +17,8 @@ //! 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(feature = "ipc")] include!(concat!(env!("OUT_DIR"), "/mod.rs.in")); #[cfg(not(feature = "ipc"))] -include!("mod.rs.in"); \ No newline at end of file +include!("mod.rs.in"); diff --git a/ethcore/src/types/account_diff.rs b/ethcore/src/types/account_diff.rs index c8d5c9eec..96180aefd 100644 --- a/ethcore/src/types/account_diff.rs +++ b/ethcore/src/types/account_diff.rs @@ -22,7 +22,8 @@ use std::collections::BTreeMap; use util::{U256, H256, Uint, Bytes}; 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). pub enum Diff where T: Eq + BinaryConvertable { /// Both sides are the same. @@ -49,7 +50,8 @@ impl Diff where T: Eq + BinaryConvertable { 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. pub struct AccountDiff { /// Change in balance, allowed to be `Diff::Same`. @@ -62,7 +64,8 @@ pub struct AccountDiff { pub storage: BTreeMap>, } -#[derive(Debug, PartialEq, Eq, Clone, Binary)] +#[derive(Debug, PartialEq, Eq, Clone)] +#[cfg_attr(feature = "ipc", binary)] /// Change in existance type. // TODO: include other types of change. pub enum Existance { diff --git a/ethcore/src/types/block_import_error.rs b/ethcore/src/types/block_import_error.rs index e229db6d2..ae29dd5a5 100644 --- a/ethcore/src/types/block_import_error.rs +++ b/ethcore/src/types/block_import_error.rs @@ -20,7 +20,8 @@ use error::{ImportError, BlockError, Error}; use std::convert::From; /// Error dedicated to import block function -#[derive(Binary, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "ipc", binary)] pub enum BlockImportError { /// Import error Import(ImportError), diff --git a/ethcore/src/types/block_status.rs b/ethcore/src/types/block_status.rs index d1c6c7d5b..33ca3f352 100644 --- a/ethcore/src/types/block_status.rs +++ b/ethcore/src/types/block_status.rs @@ -18,7 +18,8 @@ use verification::queue::Status as QueueStatus; /// General block status -#[derive(Debug, Eq, PartialEq, Binary)] +#[derive(Debug, Eq, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub enum BlockStatus { /// Part of the blockchain. InChain, @@ -38,4 +39,4 @@ impl From for BlockStatus { QueueStatus::Unknown => BlockStatus::Unknown, } } -} \ No newline at end of file +} diff --git a/ethcore/src/types/blockchain_info.rs b/ethcore/src/types/blockchain_info.rs index 33657ff0e..50887c0b7 100644 --- a/ethcore/src/types/blockchain_info.rs +++ b/ethcore/src/types/blockchain_info.rs @@ -21,7 +21,8 @@ use header::BlockNumber; use types::security_level::SecurityLevel; /// Information about the blockchain gathered together. -#[derive(Clone, Debug, Binary)] +#[derive(Clone, Debug)] +#[cfg_attr(feature = "ipc", binary)] pub struct BlockChainInfo { /// Blockchain difficulty. pub total_difficulty: U256, @@ -53,4 +54,4 @@ impl BlockChainInfo { SecurityLevel::PartialProofOfWork(self.best_block_number - self.first_block_number.expect("Guard condition means this is not none")) } } -} \ No newline at end of file +} diff --git a/ethcore/src/types/call_analytics.rs b/ethcore/src/types/call_analytics.rs index 9da2d11ae..5274adfac 100644 --- a/ethcore/src/types/call_analytics.rs +++ b/ethcore/src/types/call_analytics.rs @@ -17,7 +17,8 @@ //! Call analytics related types /// 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 { /// Make a transaction trace. pub transaction_tracing: bool, diff --git a/ethcore/src/types/executed.rs b/ethcore/src/types/executed.rs index 3ce8d2634..1f0ef33c7 100644 --- a/ethcore/src/types/executed.rs +++ b/ethcore/src/types/executed.rs @@ -24,7 +24,8 @@ use types::state_diff::StateDiff; use std::fmt; /// The type of the call-like instruction. -#[derive(Debug, PartialEq, Clone, Binary)] +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub enum CallType { /// Not a CALL. None, @@ -61,7 +62,8 @@ impl Decodable for CallType { } /// Transaction execution receipt. -#[derive(Debug, PartialEq, Clone, Binary)] +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub struct Executed { /// Gas paid up front for execution of transaction. pub gas: U256, @@ -101,7 +103,8 @@ pub struct Executed { } /// Result of executing the transaction. -#[derive(PartialEq, Debug, Clone, Binary)] +#[derive(PartialEq, Debug, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub enum ExecutionError { /// Returned when there gas paid for transaction execution is /// lower than base gas required. @@ -168,7 +171,8 @@ impl fmt::Display for ExecutionError { } /// Result of executing the transaction. -#[derive(PartialEq, Debug, Clone, Binary)] +#[derive(PartialEq, Debug, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub enum CallError { /// Couldn't find the transaction in the chain. TransactionNotFound, diff --git a/ethcore/src/types/filter.rs b/ethcore/src/types/filter.rs index 8aecef43b..f940423e3 100644 --- a/ethcore/src/types/filter.rs +++ b/ethcore/src/types/filter.rs @@ -22,7 +22,8 @@ use client::BlockId; use log_entry::LogEntry; /// Blockchain Filter. -#[derive(Binary, Debug, PartialEq)] +#[derive(Debug, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub struct Filter { /// Blockchain will be searched from this block. pub from_block: BlockId, diff --git a/ethcore/src/types/ids.rs b/ethcore/src/types/ids.rs index 2828c4798..42b51c54e 100644 --- a/ethcore/src/types/ids.rs +++ b/ethcore/src/types/ids.rs @@ -20,7 +20,8 @@ use util::hash::H256; use header::BlockNumber; /// 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 { /// Block's sha3. /// Querying by hash is always faster. @@ -36,7 +37,8 @@ pub enum BlockId { } /// Uniquely identifies transaction. -#[derive(Debug, PartialEq, Clone, Hash, Eq, Binary)] +#[derive(Debug, PartialEq, Clone, Hash, Eq)] +#[cfg_attr(feature = "ipc", binary)] pub enum TransactionId { /// Transaction's sha3. Hash(H256), @@ -46,7 +48,7 @@ pub enum TransactionId { } /// Uniquely identifies Trace. -#[derive(Binary)] +#[cfg_attr(feature = "ipc", binary)] pub struct TraceId { /// Transaction pub transaction: TransactionId, @@ -55,7 +57,8 @@ pub struct TraceId { } /// Uniquely identifies Uncle. -#[derive(Debug, PartialEq, Eq, Copy, Clone, Binary)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub struct UncleId { /// Block id. pub block: BlockId, diff --git a/ethcore/src/types/log_entry.rs b/ethcore/src/types/log_entry.rs index 19531a9e9..7407952ba 100644 --- a/ethcore/src/types/log_entry.rs +++ b/ethcore/src/types/log_entry.rs @@ -26,7 +26,8 @@ use header::BlockNumber; use ethjson; /// 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 { /// The address of the contract executing at the point of the `LOG` operation. pub address: Address, @@ -81,7 +82,8 @@ impl From for LogEntry { } /// Log localized in a blockchain. -#[derive(Default, Debug, PartialEq, Clone, Binary)] +#[derive(Default, Debug, PartialEq, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub struct LocalizedLogEntry { /// Plain log entry. pub entry: LogEntry, diff --git a/ethcore/src/types/mod.rs b/ethcore/src/types/mod.rs index 959ff694a..6d2072ce2 100644 --- a/ethcore/src/types/mod.rs +++ b/ethcore/src/types/mod.rs @@ -16,5 +16,10 @@ //! 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")); + +#[cfg(not(feature = "ipc"))] +include!("mod.rs.in"); diff --git a/ethcore/src/types/mode.rs b/ethcore/src/types/mode.rs index a1df3c76f..95bcd0d2b 100644 --- a/ethcore/src/types/mode.rs +++ b/ethcore/src/types/mode.rs @@ -20,7 +20,8 @@ pub use std::time::Duration; use client::Mode as ClientMode; /// IPC-capable shadow-type for `client::config::Mode` -#[derive(Clone, Binary, Debug)] +#[derive(Clone, Debug)] +#[cfg_attr(feature = "ipc", binary)] pub enum Mode { /// Same as `ClientMode::Off`. Off, diff --git a/ethcore/src/types/pruning_info.rs b/ethcore/src/types/pruning_info.rs index fd5689d2d..80c3e0ce2 100644 --- a/ethcore/src/types/pruning_info.rs +++ b/ethcore/src/types/pruning_info.rs @@ -21,10 +21,11 @@ //! 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. -#[derive(Debug, Clone, Binary)] +#[derive(Debug, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub struct PruningInfo { /// The first block which everything can be served after. pub earliest_chain: u64, /// The first block where state requests may be served. pub earliest_state: u64, -} \ No newline at end of file +} diff --git a/ethcore/src/types/receipt.rs b/ethcore/src/types/receipt.rs index c15f039bc..524526ff6 100644 --- a/ethcore/src/types/receipt.rs +++ b/ethcore/src/types/receipt.rs @@ -25,7 +25,8 @@ use header::BlockNumber; use log_entry::{LogEntry, LocalizedLogEntry}; /// Information describing execution of a transaction. -#[derive(Default, Debug, Clone, Binary)] +#[derive(Default, Debug, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub struct Receipt { /// The state root after executing the transaction. pub state_root: H256, @@ -79,7 +80,8 @@ impl HeapSizeOf for Receipt { } /// Receipt with additional info. -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub struct RichReceipt { /// Transaction hash. pub transaction_hash: H256, @@ -100,7 +102,8 @@ pub struct RichReceipt { } /// Receipt with additional info. -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub struct LocalizedReceipt { /// Transaction hash. pub transaction_hash: H256, diff --git a/ethcore/src/types/restoration_status.rs b/ethcore/src/types/restoration_status.rs index 507659d5b..065946ea2 100644 --- a/ethcore/src/types/restoration_status.rs +++ b/ethcore/src/types/restoration_status.rs @@ -17,7 +17,8 @@ //! Restoration status type definition /// Statuses for restorations. -#[derive(PartialEq, Eq, Clone, Copy, Debug, Binary)] +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[cfg_attr(feature = "ipc", binary)] pub enum RestorationStatus { /// No restoration. Inactive, diff --git a/ethcore/src/types/security_level.rs b/ethcore/src/types/security_level.rs index 0415b9bb1..48d252b28 100644 --- a/ethcore/src/types/security_level.rs +++ b/ethcore/src/types/security_level.rs @@ -19,7 +19,8 @@ use header::BlockNumber; /// 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 { /// All blocks from genesis to chain head are known to have valid state transitions and PoW. FullState, @@ -35,6 +36,6 @@ impl SecurityLevel { match *self { SecurityLevel::FullState | SecurityLevel::FullProofOfWork => true, _ => false, - } + } } -} \ No newline at end of file +} diff --git a/ethcore/src/types/snapshot_manifest.rs b/ethcore/src/types/snapshot_manifest.rs index dac164b0b..1c1e801cb 100644 --- a/ethcore/src/types/snapshot_manifest.rs +++ b/ethcore/src/types/snapshot_manifest.rs @@ -21,7 +21,8 @@ use rlp::*; use util::Bytes; /// Manifest data. -#[derive(Debug, Clone, PartialEq, Eq, Binary)] +#[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "ipc", binary)] pub struct ManifestData { /// List of state chunk hashes. pub state_hashes: Vec, diff --git a/ethcore/src/types/state_diff.rs b/ethcore/src/types/state_diff.rs index 6b8242db6..cb3db1ba9 100644 --- a/ethcore/src/types/state_diff.rs +++ b/ethcore/src/types/state_diff.rs @@ -22,7 +22,8 @@ use std::collections::BTreeMap; use util::Address; 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 /// delta of every altered account. pub struct StateDiff { diff --git a/ethcore/src/types/trace_filter.rs b/ethcore/src/types/trace_filter.rs index 5a7ed8429..4085c5bd0 100644 --- a/ethcore/src/types/trace_filter.rs +++ b/ethcore/src/types/trace_filter.rs @@ -21,7 +21,7 @@ use util::{Address}; use types::ids::BlockId; /// Easy to use trace filter. -#[derive(Binary)] +#[cfg_attr(feature = "ipc", binary)] pub struct Filter { /// Range of filtering. pub range: Range, diff --git a/ethcore/src/types/trace_types/error.rs b/ethcore/src/types/trace_types/error.rs index 72b873fc9..2294f673a 100644 --- a/ethcore/src/types/trace_types/error.rs +++ b/ethcore/src/types/trace_types/error.rs @@ -21,7 +21,8 @@ use rlp::{Encodable, RlpStream, Decodable, Decoder, DecoderError, Stream, View}; use evm::Error as EvmError; /// Trace evm errors. -#[derive(Debug, PartialEq, Clone, Binary)] +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub enum Error { /// `OutOfGas` is returned when transaction execution runs out of gas. OutOfGas, diff --git a/ethcore/src/types/trace_types/filter.rs b/ethcore/src/types/trace_types/filter.rs index b12112acd..282aeab9b 100644 --- a/ethcore/src/types/trace_types/filter.rs +++ b/ethcore/src/types/trace_types/filter.rs @@ -28,7 +28,8 @@ use types::trace_types::trace::{Action, Res}; /// Addresses filter. /// /// Used to create bloom possibilities and match filters. -#[derive(Debug, Binary)] +#[derive(Debug)] +#[cfg_attr(feature = "ipc", binary)] pub struct AddressesFilter { list: Vec
} @@ -74,7 +75,8 @@ impl AddressesFilter { } } -#[derive(Debug, Binary)] +#[derive(Debug)] +#[cfg_attr(feature = "ipc", binary)] /// Traces filter. pub struct Filter { /// Block range. diff --git a/ethcore/src/types/trace_types/flat.rs b/ethcore/src/types/trace_types/flat.rs index 8a949c210..b79cabb49 100644 --- a/ethcore/src/types/trace_types/flat.rs +++ b/ethcore/src/types/trace_types/flat.rs @@ -25,7 +25,8 @@ use super::trace::{Action, Res}; /// Trace localized in vector of traces produced by a single transaction. /// /// 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 { /// Type of action performed by a transaction. pub action: Action, diff --git a/ethcore/src/types/trace_types/localized.rs b/ethcore/src/types/trace_types/localized.rs index f65c47415..1b8cbd1b8 100644 --- a/ethcore/src/types/trace_types/localized.rs +++ b/ethcore/src/types/trace_types/localized.rs @@ -21,7 +21,8 @@ use super::trace::{Action, Res}; use header::BlockNumber; /// Localized trace. -#[derive(Debug, PartialEq, Clone, Binary)] +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub struct LocalizedTrace { /// Type of action performed by a transaction. pub action: Action, diff --git a/ethcore/src/types/trace_types/trace.rs b/ethcore/src/types/trace_types/trace.rs index 7f5149905..55494c533 100644 --- a/ethcore/src/types/trace_types/trace.rs +++ b/ethcore/src/types/trace_types/trace.rs @@ -27,7 +27,8 @@ use types::executed::CallType; use super::error::Error; /// `Call` result. -#[derive(Debug, Clone, PartialEq, Default, Binary)] +#[derive(Debug, Clone, PartialEq, Default)] +#[cfg_attr(feature = "ipc", binary)] pub struct CallResult { /// Gas used by call. pub gas_used: U256, @@ -56,7 +57,8 @@ impl Decodable for CallResult { } /// `Create` result. -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub struct CreateResult { /// Gas used by create. pub gas_used: U256, @@ -96,7 +98,8 @@ impl CreateResult { } /// 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 { /// The sending account. pub from: Address, @@ -163,7 +166,8 @@ impl Call { } /// 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 { /// The address of the creator. pub from: Address, @@ -219,7 +223,8 @@ impl Create { } /// Suicide action. -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub struct Suicide { /// Suicided 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. -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub enum Action { /// It's a call action. Call(Call), @@ -316,7 +322,8 @@ impl Action { } /// The result of the performed action. -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "ipc", binary)] pub enum Res { /// Successful call action result. 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. pub struct MemoryDiff { /// 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. pub struct StorageDiff { /// 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. pub struct VMExecutedOperation { /// 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. pub struct VMOperation { /// 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. pub struct VMTrace { /// The step (i.e. index into operations) at which this trace corresponds. diff --git a/ethcore/src/types/transaction.rs b/ethcore/src/types/transaction.rs index 2cd001bdb..32fe9acab 100644 --- a/ethcore/src/types/transaction.rs +++ b/ethcore/src/types/transaction.rs @@ -27,7 +27,8 @@ use evm::Schedule; use header::BlockNumber; use ethjson; -#[derive(Debug, Clone, PartialEq, Eq, Binary)] +#[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "ipc", binary)] /// Transaction action type. pub enum Action { /// Create creates new contract. @@ -54,7 +55,8 @@ impl Decodable for Action { /// A set of information describing an externally-originating message call /// 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 { /// Nonce. pub nonce: U256, @@ -205,7 +207,8 @@ impl Transaction { } /// Signed transaction information. -#[derive(Debug, Clone, Eq, Binary)] +#[derive(Debug, Clone, Eq)] +#[cfg_attr(feature = "ipc", binary)] pub struct SignedTransaction { /// Plain Transaction. unsigned: Transaction, @@ -370,7 +373,8 @@ impl SignedTransaction { } /// 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 { /// Signed part. pub signed: SignedTransaction, @@ -391,7 +395,8 @@ impl Deref for LocalizedTransaction { } /// Queued transaction with additional information. -#[derive(Debug, Clone, PartialEq, Eq, Binary)] +#[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "ipc", binary)] pub struct PendingTransaction { /// Signed transaction data. pub transaction: SignedTransaction, @@ -495,14 +500,14 @@ fn should_agree_with_vitalik() { flushln!("networkid: {:?}", signed.network_id()); }; - test_vector("f864808504a817c800825208943535353535353535353535353535353535353535808025a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116da0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", "0xf0f6f18bca1b28cd68e4357452947e021241e9ce") - test_vector("f864018504a817c80182a410943535353535353535353535353535353535353535018025a0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bcaa0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6", "0x23ef145a395ea3fa3deb533b8a9e1b4c6c25d112") - test_vector("f864028504a817c80282f618943535353535353535353535353535353535353535088025a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", "0x2e485e0c23b4c3c542628a5f672eeab0ad4888be") - test_vector("f865038504a817c803830148209435353535353535353535353535353535353535351b8025a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4e0a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4de", "0x82a88539669a3fd524d669e858935de5e5410cf0") - test_vector("f865048504a817c80483019a28943535353535353535353535353535353535353535408025a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c063a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c060", "0xf9358f2538fd5ccfeb848b64a96b743fcc930554") - test_vector("f865058504a817c8058301ec309435353535353535353535353535353535353535357d8025a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", "0xa8f7aba377317440bc5b26198a363ad22af1f3a4") - test_vector("f866068504a817c80683023e3894353535353535353535353535353535353535353581d88025a06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2fa06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2d", "0xf1f571dc362a0e5b2696b8e775f8491d3e50de35") - test_vector("f867078504a817c807830290409435353535353535353535353535353535353535358201578025a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", "0xd37922162ab7cea97c97a87551ed02c9a38b7332") - test_vector("f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", "0x9bddad43f934d313c2b79ca28a432dd2b7281029") - test_vector("f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", "0x3c24d7329e92f84f08556ceb6df1cdb0104ca49f") + test_vector("f864808504a817c800825208943535353535353535353535353535353535353535808025a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116da0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", "0xf0f6f18bca1b28cd68e4357452947e021241e9ce"); + test_vector("f864018504a817c80182a410943535353535353535353535353535353535353535018025a0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bcaa0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6", "0x23ef145a395ea3fa3deb533b8a9e1b4c6c25d112"); + test_vector("f864028504a817c80282f618943535353535353535353535353535353535353535088025a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", "0x2e485e0c23b4c3c542628a5f672eeab0ad4888be"); + test_vector("f865038504a817c803830148209435353535353535353535353535353535353535351b8025a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4e0a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4de", "0x82a88539669a3fd524d669e858935de5e5410cf0"); + test_vector("f865048504a817c80483019a28943535353535353535353535353535353535353535408025a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c063a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c060", "0xf9358f2538fd5ccfeb848b64a96b743fcc930554"); + test_vector("f865058504a817c8058301ec309435353535353535353535353535353535353535357d8025a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", "0xa8f7aba377317440bc5b26198a363ad22af1f3a4"); + test_vector("f866068504a817c80683023e3894353535353535353535353535353535353535353581d88025a06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2fa06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2d", "0xf1f571dc362a0e5b2696b8e775f8491d3e50de35"); + test_vector("f867078504a817c807830290409435353535353535353535353535353535353535358201578025a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", "0xd37922162ab7cea97c97a87551ed02c9a38b7332"); + test_vector("f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", "0x9bddad43f934d313c2b79ca28a432dd2b7281029"); + test_vector("f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", "0x3c24d7329e92f84f08556ceb6df1cdb0104ca49f"); } diff --git a/ethcore/src/types/transaction_import.rs b/ethcore/src/types/transaction_import.rs index cfd3d5243..9be235fb0 100644 --- a/ethcore/src/types/transaction_import.rs +++ b/ethcore/src/types/transaction_import.rs @@ -31,7 +31,8 @@ pub enum TransactionImportResult { binary_fixed_size!(TransactionImportResult); /// Api-level error for transaction import -#[derive(Debug, Clone, Binary)] +#[derive(Debug, Clone)] +#[cfg_attr(feature = "ipc", binary)] pub enum TransactionImportError { /// Transaction error Transaction(TransactionError), diff --git a/ethcore/src/types/tree_route.rs b/ethcore/src/types/tree_route.rs index 7a97cac03..ff7362ad2 100644 --- a/ethcore/src/types/tree_route.rs +++ b/ethcore/src/types/tree_route.rs @@ -19,7 +19,8 @@ use util::H256; /// Represents a tree route between `from` block and `to` block: -#[derive(Debug, Binary)] +#[derive(Debug)] +#[cfg_attr(feature = "ipc", binary)] pub struct TreeRoute { /// A vector of hashes of all blocks, ordered from `from` to `to`. pub blocks: Vec, diff --git a/ethcore/src/types/verification_queue_info.rs b/ethcore/src/types/verification_queue_info.rs index 3361155df..aba7785d8 100644 --- a/ethcore/src/types/verification_queue_info.rs +++ b/ethcore/src/types/verification_queue_info.rs @@ -17,7 +17,8 @@ //! Verification queue info types /// Verification queue status -#[derive(Debug, Binary)] +#[derive(Debug)] +#[cfg_attr(feature = "ipc", binary)] pub struct VerificationQueueInfo { /// Number of queued items pending verification pub unverified_queue_size: usize, @@ -50,4 +51,4 @@ impl VerificationQueueInfo { pub fn is_empty(&self) -> bool { self.unverified_queue_size + self.verified_queue_size + self.verifying_queue_size == 0 } -} \ No newline at end of file +} diff --git a/ipc-common-types/src/types/release_track.rs b/ipc-common-types/src/types/release_track.rs index 3fcc0bb64..0e68a9a31 100644 --- a/ipc-common-types/src/types/release_track.rs +++ b/ipc-common-types/src/types/release_track.rs @@ -19,7 +19,8 @@ use std::fmt; /// A release's track. -#[derive(PartialEq, Eq, Clone, Copy, Debug, Binary)] +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[binary] pub enum ReleaseTrack { /// Stable track. Stable, @@ -36,9 +37,9 @@ pub enum ReleaseTrack { impl fmt::Display for ReleaseTrack { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(f, "{}", match *self { - ReleaseTrack::Stable => "stable", - ReleaseTrack::Beta => "beta", - ReleaseTrack::Nightly => "nightly", + ReleaseTrack::Stable => "stable", + ReleaseTrack::Beta => "beta", + ReleaseTrack::Nightly => "nightly", ReleaseTrack::Testing => "testing", ReleaseTrack::Unknown => "unknown", }) @@ -48,35 +49,35 @@ impl fmt::Display for ReleaseTrack { impl<'a> From<&'a str> for ReleaseTrack { fn from(s: &'a str) -> Self { match s { - "stable" => ReleaseTrack::Stable, - "beta" => ReleaseTrack::Beta, - "nightly" => ReleaseTrack::Nightly, - "testing" => ReleaseTrack::Testing, - _ => ReleaseTrack::Unknown, - } + "stable" => ReleaseTrack::Stable, + "beta" => ReleaseTrack::Beta, + "nightly" => ReleaseTrack::Nightly, + "testing" => ReleaseTrack::Testing, + _ => ReleaseTrack::Unknown, + } } } impl From for ReleaseTrack { fn from(i: u8) -> Self { match i { - 1 => ReleaseTrack::Stable, - 2 => ReleaseTrack::Beta, - 3 => ReleaseTrack::Nightly, - 4 => ReleaseTrack::Testing, - _ => ReleaseTrack::Unknown, - } + 1 => ReleaseTrack::Stable, + 2 => ReleaseTrack::Beta, + 3 => ReleaseTrack::Nightly, + 4 => ReleaseTrack::Testing, + _ => ReleaseTrack::Unknown, + } } } impl Into for ReleaseTrack { fn into(self) -> u8 { match self { - ReleaseTrack::Stable => 1, - ReleaseTrack::Beta => 2, - ReleaseTrack::Nightly => 3, - ReleaseTrack::Testing => 4, - ReleaseTrack::Unknown => 0, - } + ReleaseTrack::Stable => 1, + ReleaseTrack::Beta => 2, + ReleaseTrack::Nightly => 3, + ReleaseTrack::Testing => 4, + ReleaseTrack::Unknown => 0, + } } } diff --git a/ipc-common-types/src/types/version_info.rs b/ipc-common-types/src/types/version_info.rs index cbffbe198..bd869bf01 100644 --- a/ipc-common-types/src/types/version_info.rs +++ b/ipc-common-types/src/types/version_info.rs @@ -22,8 +22,9 @@ use util::{H160}; use util::misc::raw_package_info; use release_track::ReleaseTrack; -/// Version information of a particular release. -#[derive(Debug, Clone, PartialEq, Binary)] +/// Version information of a particular release. +#[derive(Debug, Clone, PartialEq)] +#[binary] pub struct VersionInfo { /// The track on which it was released. pub track: ReleaseTrack, diff --git a/ipc/codegen/src/codegen.rs b/ipc/codegen/src/codegen.rs index 27eb8fb0b..9cc49d53f 100644 --- a/ipc/codegen/src/codegen.rs +++ b/ipc/codegen/src/codegen.rs @@ -111,7 +111,7 @@ fn push_invoke_signature_aster( let arg_ty = &inputs[skip-1].ty; let mut tree = builder.item() - .attr().word("derive(Binary)") + .attr().word("binary") .attr().word("allow(non_camel_case_types)") .struct_(name_str.as_str()) .field(arg_name.as_str()) @@ -140,7 +140,7 @@ fn push_invoke_signature_aster( FunctionRetTy::Ty(ref ty) => { let name_str = format!("{}_output", named_signature.ident.name.as_str()); let tree = builder.item() - .attr().word("derive(Binary)") + .attr().word("binary") .attr().word("allow(non_camel_case_types)") .struct_(name_str.as_str()) .field(format!("payload")).ty().build(ty.clone()); @@ -326,7 +326,7 @@ pub fn has_ptr(ty: &P) -> bool { /// fn commit(&self, f: u32) -> u32 /// /// the expanded implementation will generate method for the client like that -/// #[derive(Serialize)] +/// #[binary] /// struct Request<'a> { /// f: &'a u32, /// } @@ -358,7 +358,7 @@ fn implement_client_method_body( .build(static_ty.clone()); let mut tree = builder.item() - .attr().word("derive(Binary)") + .attr().word("binary") .struct_("Request") .generics() .lifetime_name("'a") diff --git a/ipc/codegen/src/lib.rs b/ipc/codegen/src/lib.rs index caa0228fc..b4825d7f9 100644 --- a/ipc/codegen/src/lib.rs +++ b/ipc/codegen/src/lib.rs @@ -42,6 +42,10 @@ extern crate rustc_plugin; #[cfg(not(feature = "with-syntex"))] use syntax::feature_gate::AttributeType; +#[cfg(feature = "with-syntex")] +use syntax::{ast, fold}; + + #[cfg(feature = "with-syntex")] include!(concat!(env!("OUT_DIR"), "/lib.rs")); @@ -56,29 +60,44 @@ pub fn expand(src: &std::path::Path, dst: &std::path::Path) { } #[cfg(feature = "with-syntex")] -pub fn register_cleaner(reg: &mut syntex::Registry) { - use syntax::{ast, fold}; +struct StripAttributeFolder<'a> { + attr_title: &'a str, +} - #[cfg(feature = "with-syntex")] - fn strip_attributes(krate: ast::Crate) -> ast::Crate { - struct StripAttributeFolder; - impl fold::Folder for StripAttributeFolder { - fn fold_attribute(&mut self, attr: ast::Attribute) -> Option { - match attr.node.value.node { - ast::MetaItemKind::List(ref n, _) if n == &"ipc" => { return None; } - ast::MetaItemKind::Word(ref n) if n == &"ipc" => { return None; } - _ => {} - } - - Some(attr) - } - - fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { - fold::noop_fold_mac(mac, self) - } +#[cfg(feature = "with-syntex")] +impl<'a> fold::Folder for StripAttributeFolder<'a> { + fn fold_attribute(&mut self, attr: ast::Attribute) -> Option { + match attr.node.value.node { + ast::MetaItemKind::List(ref n, _) if n == self.attr_title => { return None; } + ast::MetaItemKind::Word(ref n) if n == self.attr_title => { return None; } + _ => {} } - fold::Folder::fold_crate(&mut StripAttributeFolder, krate) + Some(attr) + } + + fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { + fold::noop_fold_mac(mac, self) + } +} + +#[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); @@ -90,9 +109,10 @@ pub fn register(reg: &mut syntex::Registry) { reg.add_attr("feature(custom_attribute)"); 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"))] @@ -102,11 +122,12 @@ pub fn register(reg: &mut rustc_plugin::Registry) { syntax::ext::base::MultiDecorator( Box::new(codegen::expand_ipc_implementation))); reg.register_syntax_extension( - syntax::parse::token::intern("derive_Binary"), + syntax::parse::token::intern("binary"), syntax::ext::base::MultiDecorator( Box::new(serialization::expand_serialization_implementation))); reg.register_attribute("ipc".to_owned(), AttributeType::Normal); + reg.register_attribute("binary".to_owned(), AttributeType::Normal); } #[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> { + 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::path::{Path, PathBuf}; 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 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)) { // will be reported by compiler @@ -190,3 +229,8 @@ pub fn derive_binary(src_path: &str) -> Result<(), Error> { 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) } +} diff --git a/ipc/tests/binary.rs.in b/ipc/tests/binary.rs.in index 34e33609f..513007b22 100644 --- a/ipc/tests/binary.rs.in +++ b/ipc/tests/binary.rs.in @@ -17,37 +17,40 @@ use util::Bytes; -#[derive(Binary)] +#[binary] pub enum Root { Top, Middle(u32, u64), } -#[derive(Binary, PartialEq, Debug)] +#[derive(PartialEq, Debug)] +#[binary] pub struct DoubleRoot { pub x1: u32, pub x2: u64, pub x3: u32, } -#[derive(Binary, PartialEq, Debug)] +#[derive(PartialEq, Debug)] +#[binary] pub struct ReferenceStruct<'a> { pub ref_data: &'a u64, } -#[derive(Binary, PartialEq, Debug)] +#[derive(PartialEq, Debug)] +#[binary] pub enum EnumWithStruct { Left, Right { how_much: u64 }, } -#[derive(Binary)] +#[binary] pub struct TwoVec { v1: Vec, v2: Vec, } -#[derive(Binary)] +#[binary] struct ChunkSet { items: Vec, } diff --git a/ipc/tests/nested.rs.in b/ipc/tests/nested.rs.in index a12371ecf..763cd9e71 100644 --- a/ipc/tests/nested.rs.in +++ b/ipc/tests/nested.rs.in @@ -30,7 +30,7 @@ pub trait DBWriter { impl IpcConfig for DBWriter {} -#[derive(Binary)] +#[binary] pub enum DBError { Write, Read } #[ipc] diff --git a/ipc/tests/service.rs.in b/ipc/tests/service.rs.in index 9bfe93cb3..84cc38427 100644 --- a/ipc/tests/service.rs.in +++ b/ipc/tests/service.rs.in @@ -22,7 +22,7 @@ pub struct Service { pub rollbacks: RwLock, } -#[derive(Binary)] +#[binary] pub struct CustomData { pub a: u64, pub b: u64, diff --git a/stratum/src/traits.rs b/stratum/src/traits.rs index 98a6ba763..8f172bef2 100644 --- a/stratum/src/traits.rs +++ b/stratum/src/traits.rs @@ -19,7 +19,8 @@ use std::error::Error as StdError; use util::H256; use ipc::IpcConfig; -#[derive(Debug, Clone, Binary)] +#[derive(Debug, Clone)] +#[binary] pub enum Error { NoWork, NoWorkers, @@ -53,7 +54,7 @@ pub trait PushWorkHandler: Send + Sync { fn push_work(&self, payloads: Vec) -> Result<(), Error>; } -#[derive(Binary)] +#[binary] pub struct ServiceConfiguration { pub listen_addr: String, pub secret: Option, diff --git a/sync/src/api.rs b/sync/src/api.rs index 45a9c1eb7..d623ba9c3 100644 --- a/sync/src/api.rs +++ b/sync/src/api.rs @@ -304,7 +304,7 @@ impl ChainNotify for EthSync { Some(lp) => lp, None => return, }; - + let chain_info = self.eth_handler.chain.chain_info(); light_proto.make_announcement(context, Announcement { head_hash: chain_info.best_block_hash, @@ -431,7 +431,7 @@ impl ManageNetwork for EthSync { /// IP fiter #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub enum AllowIP { /// Connect to any address All, @@ -454,7 +454,7 @@ impl AllowIP { } #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] /// Network service configuration pub struct NetworkConfiguration { /// Directory path to store general network configuration. None means nothing will be saved @@ -558,7 +558,7 @@ impl From for NetworkConfiguration { /// Configuration for IPC service. #[derive(Debug, Clone)] -#[cfg_attr(feature = "ipc", derive(Binary))] +#[cfg_attr(feature = "ipc", binary)] pub struct ServiceConfiguration { /// Sync config. pub sync: SyncConfig, diff --git a/updater/src/types/all.rs b/updater/src/types/all.rs index 5a602afcd..2337dfac5 100644 --- a/updater/src/types/all.rs +++ b/updater/src/types/all.rs @@ -20,43 +20,46 @@ use util::{H256}; pub use ipc_common_types::{VersionInfo, ReleaseTrack}; /// Information regarding a particular release of Parity -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[binary] pub struct ReleaseInfo { /// Information on the version. pub version: VersionInfo, - /// Does this release contain critical security updates? + /// Does this release contain critical security updates? pub is_critical: bool, /// The latest fork that this release can handle. pub fork: u64, - /// Our platform's binary, if known. + /// Our platform's binary, if known. pub binary: Option, } /// Information on our operations environment. -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq)] +#[binary] pub struct OperationsInfo { /// Our blockchain's latest fork. pub fork: u64, - /// Last fork our client supports, if known. + /// Last fork our client supports, if known. pub this_fork: Option, - /// Information on our track's latest release. + /// Information on our track's latest release. pub track: ReleaseInfo, /// Information on our minor version's latest release. pub minor: Option, } /// Information on the current version's consensus capabililty. -#[derive(Debug, Clone, Copy, PartialEq, Binary)] +#[derive(Debug, Clone, Copy, PartialEq)] +#[binary] pub enum CapState { /// Unknown. Unknown, /// Capable of consensus indefinitely. Capable, - /// Capable of consensus up until a definite block. + /// Capable of consensus up until a definite block. CapableUntil(u64), - /// Incapable of consensus since a particular block. + /// Incapable of consensus since a particular block. IncapableSince(u64), }