Basic signing queue

This commit is contained in:
Tomasz Drwięga 2016-05-26 17:46:44 +02:00
parent 09d9697985
commit 28391d2f52
12 changed files with 190 additions and 9 deletions

6
Cargo.lock generated
View File

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

View File

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

View File

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

View File

@ -14,31 +14,31 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
// 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;

View File

@ -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"]

View File

@ -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() {}
}

View File

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

View File

@ -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 <http://www.gnu.org/licenses/>.
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<TransactionRequest>;
}
impl SigningQueue for HashSet<TransactionRequest> {
fn add_request(&mut self, transaction: TransactionRequest) {
self.insert(transaction);
}
fn remove_request(&mut self, id: TransactionRequest) {
self.remove(&id);
}
fn requests(&self) -> &HashSet<TransactionRequest> {
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));
}
}

View File

@ -14,6 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use rustc_serialize::hex::ToHex;
use serde::{Serialize, Serializer, Deserialize, Deserializer, Error};
use serde::de::Visitor;
@ -80,4 +96,3 @@ mod tests {
}
}

21
signer/src/types/mod.rs Normal file
View File

@ -0,0 +1,21 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
#[cfg(feature = "serde_macros")]
include!("mod.rs.in");
#[cfg(not(feature = "serde_macros"))]
include!(concat!(env!("OUT_DIR"), "/mod.rs"));

View File

@ -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 <http://www.gnu.org/licenses/>.
pub mod transaction_request;
pub mod bytes;

View File

@ -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<Address>,
@ -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 {
});
}
}