Simple signing queue, confirmation APIs exposed in signer WebSockets. (#1182)
* Splitting methods requiring signing into separate trait * Single place where RPC apis are created. * Separating eth_filter * Separating eth_signing * Stubs for Personal Signer methods * Test for EthSigningQueueClient * TransactionConfirmation API * Exposing PersonalSigner API * Defining ApiSets dependent on context * Removing types * Fixing default impl * Fixing un-mocked tests * Update signing_queue.rs [ci skip] * Removing unused import [ci skip]
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(all(nightly, feature="dev"), feature(plugin))]
|
||||
#![cfg_attr(all(nightly, feature="dev"), plugin(clippy))]
|
||||
// Generated by serde
|
||||
#![cfg_attr(all(nightly, feature="dev"), allow(redundant_closure_call))]
|
||||
|
||||
//! Signer module
|
||||
//!
|
||||
@@ -45,18 +43,12 @@
|
||||
extern crate log;
|
||||
extern crate env_logger;
|
||||
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate rustc_serialize;
|
||||
|
||||
extern crate ethcore_util as util;
|
||||
extern crate ethcore_rpc as rpc;
|
||||
extern crate jsonrpc_core;
|
||||
extern crate ws;
|
||||
|
||||
mod signing_queue;
|
||||
mod ws_server;
|
||||
|
||||
pub use ws_server::*;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
// 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 rpc::v1::types::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 rpc::v1::types::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));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
// 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/>.
|
||||
|
||||
//! Reusable types with JSON Serialization.
|
||||
|
||||
#[cfg(feature = "serde_macros")]
|
||||
include!("mod.rs.in");
|
||||
|
||||
#[cfg(not(feature = "serde_macros"))]
|
||||
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
|
||||
@@ -1,25 +0,0 @@
|
||||
// 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/>.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO [ToDr] Types are empty for now. But they are about to come.
|
||||
@@ -25,6 +25,7 @@ use std::sync::Arc;
|
||||
use std::net::SocketAddr;
|
||||
use util::panics::{PanicHandler, OnPanicListener, MayPanic};
|
||||
use jsonrpc_core::{IoHandler, IoDelegate};
|
||||
use rpc::Extendable;
|
||||
|
||||
mod session;
|
||||
|
||||
@@ -57,6 +58,12 @@ impl Default for ServerBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Extendable for ServerBuilder {
|
||||
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>) {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerBuilder {
|
||||
/// Creates new `ServerBuilder`
|
||||
pub fn new() -> Self {
|
||||
@@ -65,11 +72,6 @@ impl ServerBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds rpc delegate
|
||||
pub fn add_delegate<D>(&self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
|
||||
self.handler.add_delegate(delegate);
|
||||
}
|
||||
|
||||
/// Starts a new `WebSocket` server in separate thread.
|
||||
/// Returns a `Server` handle which closes the server when droped.
|
||||
pub fn start(self, addr: SocketAddr) -> Result<Server, ServerError> {
|
||||
|
||||
Reference in New Issue
Block a user