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.
#[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<u64> 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<H256>
@ -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<H256>,
@ -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<StateProof>,
@ -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<ContractCode>,
@ -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<HeaderProof>,
@ -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),

View File

@ -17,7 +17,6 @@
//! 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"));

View File

@ -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<T> where T: Eq + BinaryConvertable {
/// 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 }}
}
#[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<H256, Diff<H256>>,
}
#[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 {

View File

@ -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),

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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<ethjson::state::Log> 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,

View File

@ -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");

View File

@ -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,

View File

@ -21,7 +21,8 @@
//! 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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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<H256>,

View File

@ -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 {

View File

@ -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<BlockId>,

View File

@ -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,

View File

@ -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<Address>
}
@ -74,7 +75,8 @@ impl AddressesFilter {
}
}
#[derive(Debug, Binary)]
#[derive(Debug)]
#[cfg_attr(feature = "ipc", binary)]
/// Traces filter.
pub struct Filter {
/// Block range.

View File

@ -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,

View File

@ -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,

View File

@ -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.

View File

@ -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");
}

View File

@ -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),

View File

@ -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<H256>,

View File

@ -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,

View File

@ -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,

View File

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

View File

@ -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<ast::Ty>) -> 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")

View File

@ -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,17 +60,16 @@ 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 {
#[cfg(feature = "with-syntex")]
impl<'a> fold::Folder for StripAttributeFolder<'a> {
fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
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; }
ast::MetaItemKind::List(ref n, _) if n == self.attr_title => { return None; }
ast::MetaItemKind::Word(ref n) if n == self.attr_title => { return None; }
_ => {}
}
@ -76,9 +79,25 @@ pub fn register_cleaner(reg: &mut syntex::Registry) {
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)
}
fold::Folder::fold_crate(&mut StripAttributeFolder, 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) }
}

View File

@ -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<u8>,
v2: Vec<u8>,
}
#[derive(Binary)]
#[binary]
struct ChunkSet {
items: Vec<Bytes>,
}

View File

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

View File

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

View File

@ -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<String>) -> Result<(), Error>;
}
#[derive(Binary)]
#[binary]
pub struct ServiceConfiguration {
pub listen_addr: String,
pub secret: Option<H256>,

View File

@ -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<BasicNetworkConfiguration> 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,

View File

@ -20,7 +20,8 @@ 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,
@ -33,7 +34,8 @@ pub struct ReleaseInfo {
}
/// 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,
@ -48,7 +50,8 @@ pub struct OperationsInfo {
}
/// 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,