From cf19e3866366451b2e96beb2f01e35c89f9e2ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 27 May 2016 15:46:07 +0200 Subject: [PATCH] Exposing types from RPC --- Cargo.lock | 2 +- rpc/Cargo.toml | 1 - rpc/src/lib.rs | 1 - rpc/src/v1/mod.rs | 4 +-- rpc/src/v1/types/block.rs | 23 ++++++++++++ rpc/src/v1/types/block_number.rs | 4 +++ {signer/src => rpc/src/v1}/types/bytes.rs | 0 rpc/src/v1/types/call_request.rs | 8 +++++ rpc/src/v1/types/filter.rs | 11 ++++++ rpc/src/v1/types/index.rs | 1 + rpc/src/v1/types/log.rs | 10 ++++++ rpc/src/v1/types/mod.rs | 2 ++ rpc/src/v1/types/mod.rs.in | 6 ++-- rpc/src/v1/types/optionals.rs | 3 ++ rpc/src/v1/types/receipt.rs | 9 +++++ rpc/src/v1/types/sync.rs | 7 ++++ rpc/src/v1/types/trace.rs | 35 +++++++++++++++++++ rpc/src/v1/types/trace_filter.rs | 5 +++ rpc/src/v1/types/transaction.rs | 12 +++++++ .../src/v1}/types/transaction_request.rs | 2 +- signer/Cargo.toml | 3 +- signer/src/lib.rs | 2 +- signer/src/signing_queue.rs | 4 +-- signer/src/types/mod.rs.in | 11 ++++-- signer/src/ws_server.rs | 4 +-- 25 files changed, 154 insertions(+), 16 deletions(-) rename {signer/src => rpc/src/v1}/types/bytes.rs (100%) rename {signer/src => rpc/src/v1}/types/transaction_request.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 66df9192a..6298ef7ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -331,7 +331,6 @@ 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", @@ -353,6 +352,7 @@ version = "1.2.0" dependencies = [ "clippy 0.0.69 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ethcore-rpc 1.2.0", "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)", diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index c8bfa0485..2cdbb0a2b 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -19,7 +19,6 @@ 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 ae824adf2..7d9818615 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -27,7 +27,6 @@ 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/mod.rs b/rpc/src/v1/mod.rs index f3bb450f3..b1ab256c0 100644 --- a/rpc/src/v1/mod.rs +++ b/rpc/src/v1/mod.rs @@ -18,12 +18,12 @@ //! //! Compliant with ethereum rpc. -pub mod traits; mod impls; -mod types; mod helpers; +pub mod traits; pub mod tests; +pub mod types; pub use self::traits::{Web3, Eth, EthFilter, Personal, Net, Ethcore, Traces, Rpc}; pub use self::impls::*; diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index c38949c08..5810c85e5 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -18,9 +18,12 @@ use serde::{Serialize, Serializer}; use util::numbers::*; use v1::types::{Bytes, Transaction, OptionalValue}; +/// Block Transactions #[derive(Debug)] pub enum BlockTransactions { + /// Only hashes Hashes(Vec), + /// Full transactions Full(Vec) } @@ -34,38 +37,58 @@ impl Serialize for BlockTransactions { } } +/// Block representation #[derive(Debug, Serialize)] pub struct Block { + /// Hash of the block pub hash: OptionalValue, + /// Hash of the parent #[serde(rename="parentHash")] pub parent_hash: H256, + /// Hash of the uncles #[serde(rename="sha3Uncles")] pub uncles_hash: H256, + /// Authors address pub author: Address, // TODO: get rid of this one + /// ? pub miner: Address, + /// State root hash #[serde(rename="stateRoot")] pub state_root: H256, + /// Transactions root hash #[serde(rename="transactionsRoot")] pub transactions_root: H256, + /// Transactions receipts root hash #[serde(rename="receiptsRoot")] pub receipts_root: H256, + /// Block number pub number: OptionalValue, + /// Gas Used #[serde(rename="gasUsed")] pub gas_used: U256, + /// Gas Limit #[serde(rename="gasLimit")] pub gas_limit: U256, + /// Extra data #[serde(rename="extraData")] pub extra_data: Bytes, + /// Logs bloom #[serde(rename="logsBloom")] pub logs_bloom: H2048, + /// Timestamp pub timestamp: U256, + /// Difficulty pub difficulty: U256, + /// Total difficulty #[serde(rename="totalDifficulty")] pub total_difficulty: U256, + /// Seal fields #[serde(rename="sealFields")] pub seal_fields: Vec, + /// Uncles' hashes pub uncles: Vec, + /// Transactions pub transactions: BlockTransactions } diff --git a/rpc/src/v1/types/block_number.rs b/rpc/src/v1/types/block_number.rs index 071486afd..e2d150c66 100644 --- a/rpc/src/v1/types/block_number.rs +++ b/rpc/src/v1/types/block_number.rs @@ -21,9 +21,13 @@ use ethcore::client::BlockID; /// Represents rpc api block number param. #[derive(Debug, PartialEq, Clone)] pub enum BlockNumber { + /// Number Num(u64), + /// Latest block Latest, + /// Earliest block (genesis) Earliest, + /// Pending block (being mined) Pending } diff --git a/signer/src/types/bytes.rs b/rpc/src/v1/types/bytes.rs similarity index 100% rename from signer/src/types/bytes.rs rename to rpc/src/v1/types/bytes.rs diff --git a/rpc/src/v1/types/call_request.rs b/rpc/src/v1/types/call_request.rs index 045b1cd9b..50ebbd1f0 100644 --- a/rpc/src/v1/types/call_request.rs +++ b/rpc/src/v1/types/call_request.rs @@ -18,15 +18,23 @@ use util::hash::Address; use util::numbers::U256; use v1::types::Bytes; +/// Call request #[derive(Debug, Default, PartialEq, Deserialize)] pub struct CallRequest { + /// From pub from: Option
, + /// To pub to: Option
, + /// Gas Price #[serde(rename="gasPrice")] pub gas_price: Option, + /// Gas pub gas: Option, + /// Value pub value: Option, + /// Data pub data: Option, + /// Nonce pub nonce: Option, } diff --git a/rpc/src/v1/types/filter.rs b/rpc/src/v1/types/filter.rs index e50ec9c32..77a3f0500 100644 --- a/rpc/src/v1/types/filter.rs +++ b/rpc/src/v1/types/filter.rs @@ -22,10 +22,14 @@ use v1::types::BlockNumber; use ethcore::filter::Filter as EthFilter; use ethcore::client::BlockID; +/// Variadic value #[derive(Debug, PartialEq, Clone)] pub enum VariadicValue where T: Deserialize { + /// Single Single(T), + /// List Multiple(Vec), + /// None Null, } @@ -44,17 +48,24 @@ impl Deserialize for VariadicValue where T: Deserialize { } } +/// Filter Address pub type FilterAddress = VariadicValue
; +/// Topic pub type Topic = VariadicValue; +/// Filter #[derive(Debug, PartialEq, Clone, Deserialize)] #[serde(deny_unknown_fields)] pub struct Filter { + /// From Block #[serde(rename="fromBlock")] pub from_block: Option, + /// To Block #[serde(rename="toBlock")] pub to_block: Option, + /// Address pub address: Option, + /// Topics pub topics: Option>, } diff --git a/rpc/src/v1/types/index.rs b/rpc/src/v1/types/index.rs index e7cbbd255..d7b17aea2 100644 --- a/rpc/src/v1/types/index.rs +++ b/rpc/src/v1/types/index.rs @@ -22,6 +22,7 @@ use serde::de::Visitor; pub struct Index(usize); impl Index { + /// Convert to usize pub fn value(&self) -> usize { self.0 } diff --git a/rpc/src/v1/types/log.rs b/rpc/src/v1/types/log.rs index 426ca68f1..72a482d1b 100644 --- a/rpc/src/v1/types/log.rs +++ b/rpc/src/v1/types/log.rs @@ -18,21 +18,31 @@ use util::numbers::*; use ethcore::log_entry::{LocalizedLogEntry, LogEntry}; use v1::types::Bytes; +/// Log #[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)] pub struct Log { + /// Address pub address: Address, + /// Topics pub topics: Vec, + /// Data pub data: Bytes, + /// Block Hash #[serde(rename="blockHash")] pub block_hash: Option, + /// Block Number #[serde(rename="blockNumber")] pub block_number: Option, + /// Transaction Hash #[serde(rename="transactionHash")] pub transaction_hash: Option, + /// Transaction Index #[serde(rename="transactionIndex")] pub transaction_index: Option, + /// Log Index #[serde(rename="logIndex")] pub log_index: Option, + /// Log Type #[serde(rename="type")] pub log_type: String, } diff --git a/rpc/src/v1/types/mod.rs b/rpc/src/v1/types/mod.rs index adf9be071..c1bc34407 100644 --- a/rpc/src/v1/types/mod.rs +++ b/rpc/src/v1/types/mod.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +//! Structures used in RPC communication + #[cfg(feature = "serde_macros")] include!("mod.rs.in"); diff --git a/rpc/src/v1/types/mod.rs.in b/rpc/src/v1/types/mod.rs.in index 9d7fc882a..824a061ef 100644 --- a/rpc/src/v1/types/mod.rs.in +++ b/rpc/src/v1/types/mod.rs.in @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +mod bytes; mod block; mod block_number; mod filter; @@ -22,13 +23,13 @@ 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::bytes::Bytes; pub use self::block::{Block, BlockTransactions}; pub use self::block_number::BlockNumber; pub use self::filter::Filter; @@ -37,6 +38,7 @@ 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/rpc/src/v1/types/optionals.rs b/rpc/src/v1/types/optionals.rs index 5db272251..2ed272ade 100644 --- a/rpc/src/v1/types/optionals.rs +++ b/rpc/src/v1/types/optionals.rs @@ -17,9 +17,12 @@ use serde::{Serialize, Serializer}; use serde_json::Value; +/// Optional value #[derive(Debug)] pub enum OptionalValue where T: Serialize { + /// Some Value(T), + /// None Null } diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index 51d914e1a..32a7f5945 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -19,22 +19,31 @@ use util::hash::{Address, H256}; use v1::types::Log; use ethcore::receipt::LocalizedReceipt; +/// Receipt #[derive(Debug, Serialize)] pub struct Receipt { + /// Transaction Hash #[serde(rename="transactionHash")] pub transaction_hash: H256, + /// Transaction index #[serde(rename="transactionIndex")] pub transaction_index: U256, + /// Block hash #[serde(rename="blockHash")] pub block_hash: H256, + /// Block number #[serde(rename="blockNumber")] pub block_number: U256, + /// Cumulative gas used #[serde(rename="cumulativeGasUsed")] pub cumulative_gas_used: U256, + /// Gas used #[serde(rename="gasUsed")] pub gas_used: U256, + /// Contract address #[serde(rename="contractAddress")] pub contract_address: Option
, + /// Logs pub logs: Vec, } diff --git a/rpc/src/v1/types/sync.rs b/rpc/src/v1/types/sync.rs index c0e480140..6d750425e 100644 --- a/rpc/src/v1/types/sync.rs +++ b/rpc/src/v1/types/sync.rs @@ -17,19 +17,26 @@ use serde::{Serialize, Serializer}; use util::numbers::*; +/// Sync info #[derive(Default, Debug, Serialize, PartialEq)] pub struct SyncInfo { + /// Starting block #[serde(rename="startingBlock")] pub starting_block: U256, + /// Current block #[serde(rename="currentBlock")] pub current_block: U256, + /// Highest block seen so far #[serde(rename="highestBlock")] pub highest_block: U256, } +/// Sync status #[derive(Debug, PartialEq)] pub enum SyncStatus { + /// Info when syncing Info(SyncInfo), + /// Not syncing None } diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 4cd1ac408..6ea58543a 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -19,11 +19,16 @@ use ethcore::trace::trace; use ethcore::trace::LocalizedTrace; use v1::types::Bytes; +/// Create response #[derive(Debug, Serialize)] pub struct Create { + /// Sender from: Address, + /// Value value: U256, + /// Gas gas: U256, + /// Initialization code init: Bytes, } @@ -38,12 +43,18 @@ impl From for Create { } } +/// Call response #[derive(Debug, Serialize)] pub struct Call { + /// Sender from: Address, + /// Recipient to: Address, + /// Transfered Value value: U256, + /// Gas gas: U256, + /// Input data input: Bytes, } @@ -59,10 +70,13 @@ impl From for Call { } } +/// Action #[derive(Debug, Serialize)] pub enum Action { + /// Call #[serde(rename="call")] Call(Call), + /// Create #[serde(rename="create")] Create(Create), } @@ -76,10 +90,13 @@ impl From for Action { } } +/// Call Result #[derive(Debug, Serialize)] pub struct CallResult { + /// Gas used #[serde(rename="gasUsed")] gas_used: U256, + /// Output bytes output: Bytes, } @@ -92,11 +109,15 @@ impl From for CallResult { } } +/// Craete Result #[derive(Debug, Serialize)] pub struct CreateResult { + /// Gas used #[serde(rename="gasUsed")] gas_used: U256, + /// Code code: Bytes, + /// Assigned address address: Address, } @@ -110,14 +131,19 @@ impl From for CreateResult { } } +/// Response #[derive(Debug, Serialize)] pub enum Res { + /// Call #[serde(rename="call")] Call(CallResult), + /// Create #[serde(rename="create")] Create(CreateResult), + /// Call failure #[serde(rename="failedCall")] FailedCall, + /// Creation failure #[serde(rename="failedCreate")] FailedCreate, } @@ -133,19 +159,28 @@ impl From for Res { } } +/// Trace #[derive(Debug, Serialize)] pub struct Trace { + /// Action action: Action, + /// Result result: Res, + /// Trace address #[serde(rename="traceAddress")] trace_address: Vec, + /// Subtraces subtraces: U256, + /// Transaction position #[serde(rename="transactionPosition")] transaction_position: U256, + /// Transaction hash #[serde(rename="transactionHash")] transaction_hash: H256, + /// Block Number #[serde(rename="blockNumber")] block_number: U256, + /// Block Hash #[serde(rename="blockHash")] block_hash: H256, } diff --git a/rpc/src/v1/types/trace_filter.rs b/rpc/src/v1/types/trace_filter.rs index 3d45f4c79..ee2f231f0 100644 --- a/rpc/src/v1/types/trace_filter.rs +++ b/rpc/src/v1/types/trace_filter.rs @@ -21,14 +21,19 @@ use ethcore::client::BlockID; use ethcore::client; use super::BlockNumber; +/// Trace filter #[derive(Debug, PartialEq, Deserialize)] pub struct TraceFilter { + /// From block #[serde(rename="fromBlock")] pub from_block: Option, + /// To block #[serde(rename="toBlock")] pub to_block: Option, + /// From address #[serde(rename="fromAddress")] pub from_address: Option>, + /// To address #[serde(rename="toAddress")] pub to_address: Option>, } diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index 8a46d5e15..1c9a41084 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -18,22 +18,34 @@ use util::numbers::*; use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction}; use v1::types::{Bytes, OptionalValue}; +/// Transaction #[derive(Debug, Default, Serialize)] pub struct Transaction { + /// Hash pub hash: H256, + /// Nonce pub nonce: U256, + /// Block hash #[serde(rename="blockHash")] pub block_hash: OptionalValue, + /// Block number #[serde(rename="blockNumber")] pub block_number: OptionalValue, + /// Transaction Index #[serde(rename="transactionIndex")] pub transaction_index: OptionalValue, + /// Sender pub from: Address, + /// Recipient pub to: OptionalValue
, + /// Transfered value pub value: U256, + /// Gas Price #[serde(rename="gasPrice")] pub gas_price: U256, + /// Gas pub gas: U256, + /// Data pub input: Bytes } diff --git a/signer/src/types/transaction_request.rs b/rpc/src/v1/types/transaction_request.rs similarity index 99% rename from signer/src/types/transaction_request.rs rename to rpc/src/v1/types/transaction_request.rs index 83840515b..2fc806912 100644 --- a/signer/src/types/transaction_request.rs +++ b/rpc/src/v1/types/transaction_request.rs @@ -18,7 +18,7 @@ use util::hash::Address; use util::numbers::U256; -use types::bytes::Bytes; +use v1::types::bytes::Bytes; /// Transaction request coming from RPC #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize)] diff --git a/signer/Cargo.toml b/signer/Cargo.toml index be77a3fd9..59c7f90b2 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -16,10 +16,11 @@ syntex = "^0.32.0" serde = "0.7.0" serde_json = "0.7.0" rustc-serialize = "0.3" -ethcore-util = { path = "../util" } log = "0.3" env_logger = "0.3" ws = "0.4.7" +ethcore-util = { path = "../util" } +ethcore-rpc = { path = "../rpc" } serde_macros = { version = "0.7.0", optional = true } clippy = { version = "0.0.69", optional = true} diff --git a/signer/src/lib.rs b/signer/src/lib.rs index 13f8d2fa6..4317338e0 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -49,11 +49,11 @@ extern crate serde_json; extern crate rustc_serialize; extern crate ethcore_util as util; +extern crate ethcore_rpc as rpc; extern crate ws; mod signing_queue; mod ws_server; -pub mod types; pub use ws_server::*; diff --git a/signer/src/signing_queue.rs b/signer/src/signing_queue.rs index 7758f5df3..d320d2375 100644 --- a/signer/src/signing_queue.rs +++ b/signer/src/signing_queue.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use std::collections::HashSet; -use types::transaction_request::TransactionRequest; +use rpc::v1::types::TransactionRequest; pub trait SigningQueue { fn add_request(&mut self, transaction: TransactionRequest); @@ -45,7 +45,7 @@ mod test { use std::collections::HashSet; use util::hash::Address; use util::numbers::U256; - use types::transaction_request::TransactionRequest; + use rpc::v1::types::transaction_request::TransactionRequest; use super::*; #[test] diff --git a/signer/src/types/mod.rs.in b/signer/src/types/mod.rs.in index 986e3d6e2..a59f81ece 100644 --- a/signer/src/types/mod.rs.in +++ b/signer/src/types/mod.rs.in @@ -14,5 +14,12 @@ // 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; + + + + + + + + +// TODO [ToDr] Types are empty for now. But they are about to come. diff --git a/signer/src/ws_server.rs b/signer/src/ws_server.rs index 9be392e69..d2ab02d66 100644 --- a/signer/src/ws_server.rs +++ b/signer/src/ws_server.rs @@ -31,14 +31,14 @@ pub enum ServerError { /// Wrapped `std::io::Error` IoError(std::io::Error), /// Other `ws-rs` error - Other(ws::Error) + WebSocket(ws::Error) } impl From for ServerError { fn from(err: ws::Error) -> Self { match err.kind { ws::ErrorKind::Io(e) => ServerError::IoError(e), - _ => ServerError::Other(err), + _ => ServerError::WebSocket(err), } } }