diff --git a/Cargo.lock b/Cargo.lock index 11c04d77d..39404a419 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -301,6 +301,7 @@ dependencies = [ "clippy 0.0.69 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.2.0", "ethcore 1.2.0", + "ethcore-signer 1.2.0", "ethcore-util 1.2.0", "ethminer 1.2.0", "ethsync 1.2.0", @@ -324,7 +325,12 @@ dependencies = [ "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-util 1.2.0", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_codegen 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 2cdbb0a2b..c8bfa0485 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -19,6 +19,7 @@ ethcore = { path = "../ethcore" } ethash = { path = "../ethash" } ethsync = { path = "../sync" } ethminer = { path = "../miner" } +ethcore-signer = { path = "../signer" } rustc-serialize = "0.3" transient-hashmap = "0.1" serde_macros = { version = "0.7.0", optional = true } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 7d9818615..ae824adf2 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -27,6 +27,7 @@ extern crate serde_json; extern crate jsonrpc_core; extern crate jsonrpc_http_server; extern crate ethcore_util as util; +extern crate ethcore_signer as signer; extern crate ethcore; extern crate ethsync; extern crate ethminer; diff --git a/rpc/src/v1/types/mod.rs.in b/rpc/src/v1/types/mod.rs.in index d896a64dc..9b56221b5 100644 --- a/rpc/src/v1/types/mod.rs.in +++ b/rpc/src/v1/types/mod.rs.in @@ -14,31 +14,31 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +// TODO import signer types + mod block; mod block_number; -mod bytes; mod filter; mod index; mod log; mod optionals; mod sync; mod transaction; -mod transaction_request; mod call_request; mod receipt; mod trace; mod trace_filter; +pub use signer::types::bytes::Bytes; +pub use signer::types::transaction_request::TransactionRequest; pub use self::block::{Block, BlockTransactions}; pub use self::block_number::BlockNumber; -pub use self::bytes::Bytes; pub use self::filter::Filter; pub use self::index::Index; pub use self::log::Log; pub use self::optionals::OptionalValue; pub use self::sync::{SyncStatus, SyncInfo}; pub use self::transaction::Transaction; -pub use self::transaction_request::TransactionRequest; pub use self::call_request::CallRequest; pub use self::receipt::Receipt; pub use self::trace::Trace; diff --git a/signer/Cargo.toml b/signer/Cargo.toml index f72865f4f..0d7f562ab 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -9,13 +9,20 @@ build = "build.rs" [build-dependencies] rustc_version = "0.1" +serde_codegen = { version = "0.7.0", optional = true } +syntex = "^0.32.0" [dependencies] +serde = "0.7.0" +serde_json = "0.7.0" +serde_macros = { version = "0.7.0", optional = true } +rustc-serialize = "0.3" ethcore-util = { path = "../util" } log = "0.3" env_logger = "0.3" clippy = { version = "0.0.69", optional = true} [features] -default = [] +default = ["serde_codegen"] +nightly = ["serde_macros"] dev = ["clippy"] diff --git a/signer/build.rs b/signer/build.rs index 41b9a1b3e..2bcfc7da5 100644 --- a/signer/build.rs +++ b/signer/build.rs @@ -19,7 +19,34 @@ extern crate rustc_version; use rustc_version::{version_meta, Channel}; fn main() { + serde::main(); if let Channel::Nightly = version_meta().channel { println!("cargo:rustc-cfg=nightly"); } } + +#[cfg(not(feature = "serde_macros"))] +mod serde { + extern crate syntex; + extern crate serde_codegen; + + use std::env; + use std::path::Path; + + pub fn main() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + + let src = Path::new("src/types/mod.rs.in"); + let dst = Path::new(&out_dir).join("mod.rs"); + + let mut registry = syntex::Registry::new(); + + serde_codegen::register(&mut registry); + registry.expand("", &src, &dst).unwrap(); + } +} + +#[cfg(feature = "serde_macros")] +mod serde { + pub fn main() {} +} diff --git a/signer/src/lib.rs b/signer/src/lib.rs index fd17758d2..ed8ec12ce 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -34,6 +34,15 @@ extern crate log; extern crate env_logger; +extern crate serde; +extern crate serde_json; +extern crate rustc_serialize; + +extern crate ethcore_util as util; + +mod signing_queue; +pub mod types; + #[cfg(test)] mod tests { #[test] diff --git a/signer/src/signing_queue.rs b/signer/src/signing_queue.rs new file mode 100644 index 000000000..7758f5df3 --- /dev/null +++ b/signer/src/signing_queue.rs @@ -0,0 +1,74 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +use std::collections::HashSet; +use types::transaction_request::TransactionRequest; + +pub trait SigningQueue { + fn add_request(&mut self, transaction: TransactionRequest); + + fn remove_request(&mut self, id: TransactionRequest); + + fn requests(&self) -> &HashSet; +} + +impl SigningQueue for HashSet { + fn add_request(&mut self, transaction: TransactionRequest) { + self.insert(transaction); + } + + fn remove_request(&mut self, id: TransactionRequest) { + self.remove(&id); + } + + fn requests(&self) -> &HashSet { + self + } +} + + +#[cfg(test)] +mod test { + use std::collections::HashSet; + use util::hash::Address; + use util::numbers::U256; + use types::transaction_request::TransactionRequest; + use super::*; + + #[test] + fn should_work_for_hashset() { + // given + let mut queue = HashSet::new(); + + let request = TransactionRequest { + from: Address::from(1), + to: Some(Address::from(2)), + gas_price: None, + gas: None, + value: Some(U256::from(10_000_000)), + data: None, + nonce: None, + }; + + // when + queue.add_request(request.clone()); + let all = queue.requests(); + + // then + assert_eq!(all.len(), 1); + assert!(all.contains(&request)); + } +} diff --git a/rpc/src/v1/types/bytes.rs b/signer/src/types/bytes.rs similarity index 77% rename from rpc/src/v1/types/bytes.rs rename to signer/src/types/bytes.rs index 4febacec9..aa2772894 100644 --- a/rpc/src/v1/types/bytes.rs +++ b/signer/src/types/bytes.rs @@ -14,6 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + use rustc_serialize::hex::ToHex; use serde::{Serialize, Serializer, Deserialize, Deserializer, Error}; use serde::de::Visitor; @@ -80,4 +96,3 @@ mod tests { } } - diff --git a/signer/src/types/mod.rs b/signer/src/types/mod.rs new file mode 100644 index 000000000..adf9be071 --- /dev/null +++ b/signer/src/types/mod.rs @@ -0,0 +1,21 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +#[cfg(feature = "serde_macros")] +include!("mod.rs.in"); + +#[cfg(not(feature = "serde_macros"))] +include!(concat!(env!("OUT_DIR"), "/mod.rs")); diff --git a/signer/src/types/mod.rs.in b/signer/src/types/mod.rs.in new file mode 100644 index 000000000..7040780f3 --- /dev/null +++ b/signer/src/types/mod.rs.in @@ -0,0 +1,19 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + + +pub mod transaction_request; +pub mod bytes; diff --git a/rpc/src/v1/types/transaction_request.rs b/signer/src/types/transaction_request.rs similarity index 97% rename from rpc/src/v1/types/transaction_request.rs rename to signer/src/types/transaction_request.rs index f00fa9ef0..f95d7ff4c 100644 --- a/rpc/src/v1/types/transaction_request.rs +++ b/signer/src/types/transaction_request.rs @@ -16,9 +16,9 @@ use util::hash::Address; use util::numbers::U256; -use v1::types::Bytes; +use types::bytes::Bytes; -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize)] pub struct TransactionRequest { pub from: Address, pub to: Option
, @@ -37,7 +37,7 @@ mod tests { use serde_json; use util::numbers::{U256}; use util::hash::Address; - use v1::types::Bytes; + use types::bytes::Bytes; use super::*; #[test] @@ -126,3 +126,4 @@ mod tests { }); } } +