From 9241c6a9b5ecff50416fc0abb6c2ee9a2c2b9339 Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Sat, 1 Jul 2017 23:20:49 +0800 Subject: [PATCH 1/7] config: don't allow dev chain with force sealing option --- parity/configuration.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/parity/configuration.rs b/parity/configuration.rs index adad91e1a..81117db05 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -515,6 +515,10 @@ impl Configuration { } fn miner_options(&self, reseal_min_period: u64) -> Result { + if self.args.flag_force_sealing && reseal_min_period == 0 { + return Err("Force sealing can't be used with reseal_min_period = 0".into()); + } + let reseal = self.args.flag_reseal_on_txs.parse::()?; let options = MinerOptions { @@ -1334,6 +1338,13 @@ mod tests { assert_eq!(conf3.miner_options(min_period).unwrap(), mining_options); } + #[test] + fn should_fail_on_force_reseal_and_reseal_min_period() { + let conf = parse(&["parity", "--chain", "dev", "--force-sealing"]); + + assert!(conf.miner_options(0).is_err()); + } + #[test] fn should_parse_updater_options() { // when From 7240eee5a8e875082f9d0a29a9f69e3cecac7134 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 3 Jul 2017 00:53:40 +0100 Subject: [PATCH 2/7] Update lockfile for miniz-sys and gcc Fixes build with VS 2017. --- Cargo.lock | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63597b890..ee6ce5e2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -338,7 +338,7 @@ version = "0.5.6" source = "git+https://github.com/paritytech/rust-secp256k1#b6b67055edc929057e97d64f036c78ad91f58a7f" dependencies = [ "arrayvec 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -814,7 +814,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -844,10 +844,10 @@ dependencies = [ [[package]] name = "gcc" -version = "0.3.43" +version = "0.3.51" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -920,7 +920,7 @@ name = "hidapi" version = "0.3.1" source = "git+https://github.com/paritytech/hidapi-rs#9a127c1dca7e327e4fdd428406a76c9f5ef48563" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1204,7 +1204,7 @@ name = "libusb-sys" version = "0.2.3" source = "git+https://github.com/paritytech/libusb-sys#c10b1180646c9dc3f23a9b6bb825abcd3b7487ce" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1275,10 +1275,10 @@ dependencies = [ [[package]] name = "miniz-sys" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1383,7 +1383,7 @@ name = "nanomsg-sys" version = "0.5.0" source = "git+https://github.com/paritytech/nanomsg.rs.git?branch=parity-1.7#673b79beef6e149273899850d7692335a481a920" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1556,7 +1556,7 @@ name = "openssl-sys" version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2046,17 +2046,6 @@ dependencies = [ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rayon" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rayon" version = "0.7.0" @@ -2118,7 +2107,7 @@ name = "ring" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2151,7 +2140,7 @@ name = "rocksdb-sys" version = "0.3.0" source = "git+https://github.com/paritytech/rust-rocksdb#4364caec4dd5da1a1d78c39276774ee65bf55c7d" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2206,7 +2195,7 @@ name = "rust-crypto" version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2386,7 +2375,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "sha3" version = "0.1.0" dependencies = [ - "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2961,7 +2950,7 @@ dependencies = [ "checksum foreign-types 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e4056b9bd47f8ac5ba12be771f77a0dae796d1bbaaf5fd0b9c2d38b69b8a29d" "checksum futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8e51e7f9c150ba7fd4cee9df8bf6ea3dea5b63b68955ddad19ccd35b71dcfb4d" "checksum futures-cpupool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bb982bb25cd8fa5da6a8eb3a460354c984ff1113da82bcb4f0b0862b5795db82" -"checksum gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)" = "c07c758b972368e703a562686adb39125707cc1ef3399da8c019fc6c2498a75d" +"checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" "checksum gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0912515a8ff24ba900422ecda800b52f4016a56251922d397c576bf92c690518" "checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" @@ -3007,7 +2996,7 @@ dependencies = [ "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a74cc2587bf97c49f3f5bab62860d6abf3902ca73b66b51d9b049fbdcd727bd2" "checksum mime_guess 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e50bf542f81754ef69e5cea856946a3819f7c09ea97b4903c8bc8a89f74e7b6" -"checksum miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d1f4d337a01c32e1f2122510fed46393d53ca35a7f429cb0450abaedfa3ed54" +"checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726" "checksum mio 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ba718a36791275c6782c0445a5f79b5ef4e68c01a4e60ac04aae28290e4957" "checksum mio-named-pipes 0.1.4 (git+https://github.com/alexcrichton/mio-named-pipes)" = "" "checksum mio-uds 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "78437f00d9615c366932cbfe79790b5c2945706ba67cf78378ffacc0069ed9de" @@ -3063,7 +3052,6 @@ dependencies = [ "checksum quine-mc_cluskey 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6683b0e23d80813b1a535841f0048c1537d3f86d63c999e8373b39a9b0eb74a" "checksum quote 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6732e32663c9c271bfc7c1823486b471f18c47a2dbf87c066897b7b51afc83be" "checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5" -"checksum rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50c575b58c2b109e2fbc181820cbe177474f35610ff9e357dc75f6bac854ffbf" "checksum rayon 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c83adcb08e5b922e804fe1918142b422602ef11f2fd670b0b52218cb5984a20" "checksum rayon-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "767d91bacddf07d442fe39257bf04fd95897d1c47c545d009f6beb03efd038f8" "checksum regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4278c17d0f6d62dfef0ab00028feb45bd7d2102843f80763474eeb1be8a10c01" From 2e90e02a2c746ea6b25cc21687eef19a62f21b2a Mon Sep 17 00:00:00 2001 From: Vurich Date: Mon, 3 Jul 2017 16:49:06 +0200 Subject: [PATCH 3/7] Fix underflow --- ethcore/src/ethereum/ethash.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 78f1efde4..3b48ab321 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -453,11 +453,14 @@ impl Ethash { let parent_has_uncles = parent.uncles_hash() != &sha3::SHA3_EMPTY_LIST_RLP; let min_difficulty = self.ethash_params.minimum_difficulty; + let difficulty_hardfork = header.number() >= self.ethash_params.difficulty_hardfork_transition; - let difficulty_bound_divisor = match difficulty_hardfork { - true => self.ethash_params.difficulty_hardfork_bound_divisor, - false => self.ethash_params.difficulty_bound_divisor, + let difficulty_bound_divisor = if difficulty_hardfork { + self.ethash_params.difficulty_hardfork_bound_divisor + } else { + self.ethash_params.difficulty_bound_divisor }; + let duration_limit = self.ethash_params.duration_limit; let frontier_limit = self.ethash_params.homestead_transition; @@ -483,7 +486,10 @@ impl Ethash { if diff_inc <= threshold { *parent.difficulty() + *parent.difficulty() / difficulty_bound_divisor * (threshold - diff_inc).into() } else { - *parent.difficulty() - *parent.difficulty() / difficulty_bound_divisor * min(diff_inc - threshold, 99).into() + let multiplier = min(diff_inc - threshold, 99).into(); + parent.difficulty().saturating_sub( + *parent.difficulty() / difficulty_bound_divisor * multiplier + ) } }; target = max(min_difficulty, target); From 59e87b6a5128c15a9cac55fba355295b2daf5477 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Tue, 4 Jul 2017 17:01:06 +0200 Subject: [PATCH 4/7] Clean up function naming in RPC error module --- rpc/src/v1/helpers/dispatch.rs | 12 ++++++------ rpc/src/v1/helpers/errors.rs | 18 +++++++++--------- rpc/src/v1/helpers/ipfs.rs | 2 +- rpc/src/v1/helpers/secretstore.rs | 6 +++--- rpc/src/v1/impls/eth.rs | 18 +++++++++--------- rpc/src/v1/impls/light/eth.rs | 8 ++++---- rpc/src/v1/impls/light/parity.rs | 2 +- rpc/src/v1/impls/light/parity_set.rs | 4 ++-- rpc/src/v1/impls/parity.rs | 2 +- rpc/src/v1/impls/parity_set.rs | 6 +++--- rpc/src/v1/impls/signer.rs | 2 +- rpc/src/v1/impls/traces.rs | 8 ++++---- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index ce978422d..ff950d346 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -162,7 +162,7 @@ impl Dispatcher for FullDispatcher accounts.sign(address, Some(pass), hash).map(WithToken::No), SignWith::Token(token) => accounts.sign_with_token(address, token, hash).map(Into::into), }.map_err(|e| match password { - SignWith::Nothing => errors::from_signing_error(e), - _ => errors::from_password_error(e), + SignWith::Nothing => errors::signing(e), + _ => errors::password(e), }) } @@ -570,8 +570,8 @@ fn decrypt(accounts: &AccountProvider, address: Address, msg: Bytes, password: S SignWith::Password(pass) => accounts.decrypt(address, Some(pass), &DEFAULT_MAC, &msg).map(WithToken::No), SignWith::Token(token) => accounts.decrypt_with_token(address, token, &DEFAULT_MAC, &msg).map(Into::into), }.map_err(|e| match password { - SignWith::Nothing => errors::from_signing_error(e), - _ => errors::from_password_error(e), + SignWith::Nothing => errors::signing(e), + _ => errors::password(e), }) } diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index df7d65067..30e6d7f94 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -221,7 +221,7 @@ pub fn network_disabled() -> Error { } } -pub fn encryption_error(error: T) -> Error { +pub fn encryption(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::ENCRYPTION_ERROR), message: "Encryption error.".into(), @@ -229,7 +229,7 @@ pub fn encryption_error(error: T) -> Error { } } -pub fn encoding_error(error: T) -> Error { +pub fn encoding(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::ENCODING_ERROR), message: "Encoding error.".into(), @@ -237,7 +237,7 @@ pub fn encoding_error(error: T) -> Error { } } -pub fn database_error(error: T) -> Error { +pub fn database(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::DATABASE_ERROR), message: "Database error.".into(), @@ -245,7 +245,7 @@ pub fn database_error(error: T) -> Error { } } -pub fn from_fetch_error(error: T) -> Error { +pub fn fetch(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::FETCH_ERROR), message: "Error while fetching content.".into(), @@ -253,7 +253,7 @@ pub fn from_fetch_error(error: T) -> Error { } } -pub fn from_signing_error(error: AccountError) -> Error { +pub fn signing(error: AccountError) -> Error { Error { code: ErrorCode::ServerError(codes::ACCOUNT_LOCKED), message: "Your account is locked. Unlock the account via CLI, personal_unlockAccount or use Trusted Signer.".into(), @@ -261,7 +261,7 @@ pub fn from_signing_error(error: AccountError) -> Error { } } -pub fn from_password_error(error: AccountError) -> Error { +pub fn password(error: AccountError) -> Error { Error { code: ErrorCode::ServerError(codes::PASSWORD_INVALID), message: "Account password is invalid or account does not exist.".into(), @@ -301,7 +301,7 @@ pub fn transaction_message(error: TransactionError) -> String { } } -pub fn from_transaction_error(error: EthcoreError) -> Error { +pub fn transaction(error: EthcoreError) -> Error { if let EthcoreError::Transaction(e) = error { Error { @@ -318,7 +318,7 @@ pub fn from_transaction_error(error: EthcoreError) -> Error { } } -pub fn from_rlp_error(error: DecoderError) -> Error { +pub fn rlp(error: DecoderError) -> Error { Error { code: ErrorCode::InvalidParams, message: "Invalid RLP.".into(), @@ -326,7 +326,7 @@ pub fn from_rlp_error(error: DecoderError) -> Error { } } -pub fn from_call_error(error: CallError) -> Error { +pub fn call(error: CallError) -> Error { match error { CallError::StatePruned => state_pruned(), CallError::StateCorrupt => state_corrupt(), diff --git a/rpc/src/v1/helpers/ipfs.rs b/rpc/src/v1/helpers/ipfs.rs index 53aa4be35..80ad1c207 100644 --- a/rpc/src/v1/helpers/ipfs.rs +++ b/rpc/src/v1/helpers/ipfs.rs @@ -32,7 +32,7 @@ pub fn cid(content: Bytes) -> Result { let mut buf = Vec::with_capacity(len); buf.resize(len, 0); hasher.result(&mut buf); - let mh = multihash::encode(multihash::Hash::SHA2256, &buf).map_err(errors::encoding_error)?; + let mh = multihash::encode(multihash::Hash::SHA2256, &buf).map_err(errors::encoding)?; let cid = Cid::new(Codec::DagProtobuf, Version::V0, &mh); Ok(cid.to_string().into()) } diff --git a/rpc/src/v1/helpers/secretstore.rs b/rpc/src/v1/helpers/secretstore.rs index 43c2c8943..9563302d9 100644 --- a/rpc/src/v1/helpers/secretstore.rs +++ b/rpc/src/v1/helpers/secretstore.rs @@ -86,13 +86,13 @@ fn decrypt_with_shadow_coefficients(mut decrypted_shadow: Public, mut common_sha let mut shadow_coefficients_sum = shadow_coefficients[0].clone(); for shadow_coefficient in shadow_coefficients.iter().skip(1) { shadow_coefficients_sum.add(shadow_coefficient) - .map_err(errors::encryption_error)?; + .map_err(errors::encryption)?; } math::public_mul_secret(&mut common_shadow_point, &shadow_coefficients_sum) - .map_err(errors::encryption_error)?; + .map_err(errors::encryption)?; math::public_add(&mut decrypted_shadow, &common_shadow_point) - .map_err(errors::encryption_error)?; + .map_err(errors::encryption)?; Ok(decrypted_shadow) } diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 499b0a15f..24b41bd6f 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -365,7 +365,7 @@ impl Eth for EthClient where BlockNumber::Pending => { match self.miner.balance(&*self.client, &address) { Some(balance) => Ok(balance.into()), - None => Err(errors::database_error("latest balance missing")) + None => Err(errors::database("latest balance missing")) } } id => { @@ -388,7 +388,7 @@ impl Eth for EthClient where BlockNumber::Pending => { match self.miner.storage_at(&*self.client, &address, &H256::from(position)) { Some(s) => Ok(s.into()), - None => Err(errors::database_error("latest storage missing")) + None => Err(errors::database("latest storage missing")) } } id => { @@ -413,13 +413,13 @@ impl Eth for EthClient where .or_else(|| self.miner.nonce(&*self.client, &address)); match nonce { Some(nonce) => Ok(nonce.into()), - None => Err(errors::database_error("latest nonce missing")) + None => Err(errors::database("latest nonce missing")) } } BlockNumber::Pending => { match self.miner.nonce(&*self.client, &address) { Some(nonce) => Ok(nonce.into()), - None => Err(errors::database_error("latest nonce missing")) + None => Err(errors::database("latest nonce missing")) } } id => { @@ -472,7 +472,7 @@ impl Eth for EthClient where BlockNumber::Pending => { match self.miner.code(&*self.client, &address) { Some(code) => Ok(code.map_or_else(Bytes::default, Bytes::new)), - None => Err(errors::database_error("latest code missing")) + None => Err(errors::database("latest code missing")) } } id => { @@ -618,8 +618,8 @@ impl Eth for EthClient where fn send_raw_transaction(&self, raw: Bytes) -> Result { UntrustedRlp::new(&raw.into_vec()).as_val() - .map_err(errors::from_rlp_error) - .and_then(|tx| SignedTransaction::new(tx).map_err(errors::from_transaction_error)) + .map_err(errors::rlp) + .and_then(|tx| SignedTransaction::new(tx).map_err(errors::transaction)) .and_then(|signed_transaction| { FullDispatcher::new(self.client.clone(), self.miner.clone()) .dispatch_transaction(signed_transaction.into()) @@ -645,7 +645,7 @@ impl Eth for EthClient where future::done(result .map(|b| b.output.into()) - .map_err(errors::from_call_error) + .map_err(errors::call) ).boxed() } @@ -657,7 +657,7 @@ impl Eth for EthClient where }; future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into()) .map(Into::into) - .map_err(errors::from_call_error) + .map_err(errors::call) ).boxed() } diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index f50dd82ab..fd03f1226 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -363,18 +363,18 @@ impl Eth for EthClient { let best_header = self.client.best_block_header().decode(); UntrustedRlp::new(&raw.into_vec()).as_val() - .map_err(errors::from_rlp_error) + .map_err(errors::rlp) .and_then(|tx| { self.client.engine().verify_transaction_basic(&tx, &best_header) - .map_err(errors::from_transaction_error)?; + .map_err(errors::transaction)?; - let signed = SignedTransaction::new(tx).map_err(errors::from_transaction_error)?; + let signed = SignedTransaction::new(tx).map_err(errors::transaction)?; let hash = signed.hash(); self.transaction_queue.write().import(signed.into()) .map(|_| hash) .map_err(Into::into) - .map_err(errors::from_transaction_error) + .map_err(errors::transaction) }) .map(Into::into) } diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 273c958fe..481cdb136 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -241,7 +241,7 @@ impl Parity for ParityClient { fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result { ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0) - .map_err(errors::encryption_error) + .map_err(errors::encryption) .map(Into::into) } diff --git a/rpc/src/v1/impls/light/parity_set.rs b/rpc/src/v1/impls/light/parity_set.rs index cab2fa91c..fdeee693f 100644 --- a/rpc/src/v1/impls/light/parity_set.rs +++ b/rpc/src/v1/impls/light/parity_set.rs @@ -127,9 +127,9 @@ impl ParitySet for ParitySetClient { fn hash_content(&self, url: String) -> BoxFuture { self.fetch.process(self.fetch.fetch(&url).then(move |result| { result - .map_err(errors::from_fetch_error) + .map_err(errors::fetch) .and_then(|response| { - sha3(&mut io::BufReader::new(response)).map_err(errors::from_fetch_error) + sha3(&mut io::BufReader::new(response)).map_err(errors::fetch) }) .map(Into::into) })) diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index c9dbf54a6..2cffdd4e6 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -284,7 +284,7 @@ impl Parity for ParityClient where fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result { ecies::encrypt(&key.into(), &DEFAULT_MAC, &phrase.0) - .map_err(errors::encryption_error) + .map_err(errors::encryption) .map(Into::into) } diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index 4be41f7c1..dc771c4f8 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -101,7 +101,7 @@ impl ParitySet for ParitySetClient where } fn set_engine_signer(&self, address: H160, password: String) -> Result { - self.miner.set_engine_signer(address.into(), password).map_err(Into::into).map_err(errors::from_password_error)?; + self.miner.set_engine_signer(address.into(), password).map_err(Into::into).map_err(errors::password)?; Ok(true) } @@ -168,9 +168,9 @@ impl ParitySet for ParitySetClient where fn hash_content(&self, url: String) -> BoxFuture { self.fetch.process(self.fetch.fetch(&url).then(move |result| { result - .map_err(errors::from_fetch_error) + .map_err(errors::fetch) .and_then(|response| { - sha3(&mut io::BufReader::new(response)).map_err(errors::from_fetch_error) + sha3(&mut io::BufReader::new(response)).map_err(errors::fetch) }) .map(Into::into) })) diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index d0b1b7a3c..79f4f0e38 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -133,7 +133,7 @@ impl SignerClient { fn verify_transaction(bytes: Bytes, request: FilledTransactionRequest, process: F) -> Result where F: FnOnce(PendingTransaction) -> Result, { - let signed_transaction = UntrustedRlp::new(&bytes.0).as_val().map_err(errors::from_rlp_error)?; + let signed_transaction = UntrustedRlp::new(&bytes.0).as_val().map_err(errors::rlp)?; let signed_transaction = SignedTransaction::new(signed_transaction).map_err(|e| errors::invalid_params("Invalid signature.", e))?; let sender = signed_transaction.sender(); diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index 705ad9cab..2c65f4403 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -87,23 +87,23 @@ impl Traces for TracesClient where C: MiningBlockChainClient + 'stat self.client.call(&signed, block.into(), to_call_analytics(flags)) .map(TraceResults::from) - .map_err(errors::from_call_error) + .map_err(errors::call) } fn raw_transaction(&self, raw_transaction: Bytes, flags: Vec, block: Trailing) -> Result { let block = block.unwrap_or_default(); let tx = UntrustedRlp::new(&raw_transaction.into_vec()).as_val().map_err(|e| errors::invalid_params("Transaction is not valid RLP", e))?; - let signed = SignedTransaction::new(tx).map_err(errors::from_transaction_error)?; + let signed = SignedTransaction::new(tx).map_err(errors::transaction)?; self.client.call(&signed, block.into(), to_call_analytics(flags)) .map(TraceResults::from) - .map_err(errors::from_call_error) + .map_err(errors::call) } fn replay_transaction(&self, transaction_hash: H256, flags: Vec) -> Result { self.client.replay(TransactionId::Hash(transaction_hash.into()), to_call_analytics(flags)) .map(TraceResults::from) - .map_err(errors::from_call_error) + .map_err(errors::call) } } From 349316f70ed909d3c8dc4f32997c3864c9ae89dd Mon Sep 17 00:00:00 2001 From: kaikun213 Date: Thu, 6 Jul 2017 09:50:27 +0200 Subject: [PATCH 5/7] PubSub for parity-js (#5830) * PubSub Integration WebSocket * PubSub Provider API * Parity License and fix switch statement * Minor fix: use parameter api * Exclude subscriptionId return * Unsubscribe parameters as array * secureProvider API added * isSecure check * Refractor: Formatting in callback (no Promise) * Tests for parityProvider * Refractor: Formatting in callback (secure API) * Updated transaction documentation * Module instead of API-Names, Options always as array (e.g. empty) 'parity' instead of 'parity_subscribe' calls params with empty array as options. If eth_subscribe includes empty array parity-core will send invalid request (eth api doesn't have options) * Removed isSecure transport check, because APIs are configurable * Refractor Provider API to single Pubsub * Modify transport layer to have single identifier for subscriptions * FIX: Display pubsub errors * Discard Messages after unsubscribing * Fix: display error normal messages correctly * Simplified code, removed unnecessary pubsub methods * trace_call API 2nd argument blockNumber, first whatTrace https://github.com/paritytech/parity/wiki/JSONRPC-trace-module#trace_call * Separate namespaces pubsub. eth, parity, net * Keep error for messages from unsubscribed topics. * Fix: Unsubscribe Promise * Add Test: Unsubscribe promise resolved * Fix: 'error' in params --- js/src/api/api.js | 13 +- js/src/api/pubsub/eth/eth.js | 227 ++++++++++ js/src/api/pubsub/eth/index.js | 16 + js/src/api/pubsub/index.js | 16 + js/src/api/pubsub/net/index.js | 16 + js/src/api/pubsub/net/net.js | 42 ++ js/src/api/pubsub/parity/index.js | 16 + js/src/api/pubsub/parity/parity.js | 355 ++++++++++++++++ js/src/api/pubsub/pubsub.js | 50 +++ js/src/api/pubsub/pubsub.spec.js | 613 +++++++++++++++++++++++++++ js/src/api/pubsub/pubsubBase.js | 37 ++ js/src/api/rpc/parity/parity.spec.js | 2 +- js/src/api/rpc/trace/trace.js | 4 +- js/src/api/transport/ws/ws.js | 113 ++++- js/src/jsonrpc/interfaces/eth.js | 66 +++ js/test/mockRpc.js | 4 + 16 files changed, 1574 insertions(+), 16 deletions(-) create mode 100644 js/src/api/pubsub/eth/eth.js create mode 100644 js/src/api/pubsub/eth/index.js create mode 100644 js/src/api/pubsub/index.js create mode 100644 js/src/api/pubsub/net/index.js create mode 100644 js/src/api/pubsub/net/net.js create mode 100644 js/src/api/pubsub/parity/index.js create mode 100644 js/src/api/pubsub/parity/parity.js create mode 100644 js/src/api/pubsub/pubsub.js create mode 100644 js/src/api/pubsub/pubsub.spec.js create mode 100644 js/src/api/pubsub/pubsubBase.js diff --git a/js/src/api/api.js b/js/src/api/api.js index 9a208ade9..220c3be29 100644 --- a/js/src/api/api.js +++ b/js/src/api/api.js @@ -21,6 +21,7 @@ import Contract from './contract'; import { Db, Eth, Parity, Net, Personal, Shh, Signer, Trace, Web3 } from './rpc'; import Subscriptions from './subscriptions'; +import Pubsub from './pubsub'; import util from './util'; import { isFunction } from './util/types'; @@ -46,10 +47,13 @@ export default class Api extends EventEmitter { this._trace = new Trace(transport); this._web3 = new Web3(transport); + if (isFunction(transport.subscribe)) { + this._pubsub = new Pubsub(transport); + } + if (allowSubscriptions) { this._subscriptions = new Subscriptions(this); } - // Doing a request here in test env would cause an error if (LocalAccountsMiddleware && process.env.NODE_ENV !== 'test') { const middleware = this.parity @@ -67,6 +71,13 @@ export default class Api extends EventEmitter { } } + get pubsub () { + if (!this._pubsub) { + throw Error('Pubsub is only available with a subscribing-supported transport injected!'); + } + return this._pubsub; + } + get db () { return this._db; } diff --git a/js/src/api/pubsub/eth/eth.js b/js/src/api/pubsub/eth/eth.js new file mode 100644 index 000000000..0bbc85bec --- /dev/null +++ b/js/src/api/pubsub/eth/eth.js @@ -0,0 +1,227 @@ +// Copyright 2015-2017 Parity Technologies (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 . +import PubsubBase from '../pubsubBase'; + +import { inAddress, inBlockNumber, inHex, inNumber16, inOptions, inFilter } from '../../format/input'; +import { outAddress, outBlock, outNumber, outTransaction, outSyncing, outReceipt, outLog } from '../../format/output'; + +export default class Eth extends PubsubBase { + constructor (transport) { + super(transport); + this._api = 'parity'; + } + + newHeads (callback) { + return this.addListener('eth', 'newHeads', callback); + } + + logs (callback) { + throw Error('not supported yet'); + } + + // eth API + protocolVersion (callback) { + return this.addListener(this._api, 'eth_protocolVersion', callback); + } + + syncing (callback) { + return this.addListener(this._api, 'eth_syncing', (error, data) => { + error + ? callback(error) + : callback(null, outSyncing(data)); + }); + } + + hashrate (callback) { + return this.addListener(this._api, 'eth_hashrate', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + coinbase (callback) { + return this.addListener(this._api, 'eth_coinbase', (error, data) => { + error + ? callback(error) + : callback(null, outAddress(data)); + }); + } + + mining (callback) { + return this.addListener(this._api, 'eth_mining', callback); + } + + gasPrice (callback) { + return this.addListener(this._api, 'eth_gasPrice', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + accounts (callback) { + return this.addListener(this._api, 'eth_accounts', (error, accounts) => { + error + ? callback(error) + : callback(null, (accounts || []).map(outAddress)); + }); + } + + blockNumber (callback) { + return this.addListener(this._api, 'eth_blockNumber', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + getBalance (callback, address, blockNumber = 'latest') { + return this.addListener(this._api, 'eth_getBalance', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inAddress(address), inBlockNumber(blockNumber)]); + } + + getStorageAt (callback, address, index = 0, blockNumber = 'latest') { + return this.addListener(this._api, 'eth_getStorageAt', callback, [inAddress(address), inNumber16(index), inBlockNumber(blockNumber)]); + } + + getBlockByHash (callback, hash, full = false) { + return this.addListener(this._api, 'eth_getBlockByHash', (error, data) => { + error + ? callback(error) + : callback(null, outBlock(data)); + }, [inHex(hash), full]); + } + + getBlockByNumber (callback, blockNumber = 'latest', full = false) { + return this.addListener(this._api, 'eth_getBlockByNumber', (error, data) => { + error + ? callback(error) + : callback(null, outBlock(data)); + }, [inBlockNumber(blockNumber), full]); + } + + getTransactionCount (callback, address, blockNumber = 'latest') { + return this.addListener(this._api, 'eth_getTransactionCount', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inAddress(address), inBlockNumber(blockNumber)]); + } + + getBlockTransactionCountByHash (callback, hash) { + return this.addListener(this._api, 'eth_getBlockTransactionCountByHash', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inHex(hash)]); + } + + getBlockTransactionCountByNumber (callback, blockNumber = 'latest') { + return this.addListener(this._api, 'eth_getBlockTransactionCountByNumber', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inBlockNumber(blockNumber)]); + } + + getUncleCountByBlockHash (callback, hash) { + return this.addListener(this._api, 'eth_getUncleCountByBlockHash', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inHex(hash)]); + } + + getUncleCountByBlockNumber (callback, blockNumber = 'latest') { + return this.addListener(this._api, 'eth_getUncleCountByBlockNumber', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inBlockNumber(blockNumber)]); + } + + getCode (callback, address, blockNumber = 'latest') { + return this.addListener(this._api, 'eth_getCode', callback, [inAddress(address), inBlockNumber(blockNumber)]); + } + + call (callback, options, blockNumber = 'latest') { + return this.addListener(this._api, 'eth_call', callback, [inOptions(options), inBlockNumber(blockNumber)]); + } + + estimateGas (callback, options) { + return this.addListener(this._api, 'eth_estimateGas', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inOptions(options)]); + } + + getTransactionByHash (callback, hash) { + return this.addListener(this._api, 'eth_getTransactionByHash', (error, data) => { + error + ? callback(error) + : callback(null, outTransaction(data)); + }, [inHex(hash)]); + } + + getTransactionByBlockHashAndIndex (callback, hash, index = 0) { + return this.addListener(this._api, 'eth_getTransactionByBlockHashAndIndex', (error, data) => { + error + ? callback(error) + : callback(null, outTransaction(data)); + }, [inHex(hash), inNumber16(index)]); + } + + getTransactionByBlockNumberAndIndex (callback, blockNumber = 'latest', index = 0) { + return this.addListener(this._api, 'eth_getTransactionByBlockNumberAndIndex', (error, data) => { + error + ? callback(error) + : callback(null, outTransaction(data)); + }, [inBlockNumber(blockNumber), inNumber16(index)]); + } + + getTransactionReceipt (callback, txhash) { + return this.addListener(this._api, 'eth_getTransactionReceipt', (error, data) => { + error + ? callback(error) + : callback(null, outReceipt(data)); + }, [inHex(txhash)]); + } + + getUncleByBlockHashAndIndex (callback, hash, index = 0) { + return this.addListener(this._api, 'eth_getUncleByBlockHashAndIndex', callback, [inHex(hash), inNumber16(index)]); + } + + getUncleByBlockNumberAndIndex (callback, blockNumber = 'latest', index = 0) { + return this.addListener(this._api, 'eth_getUncleByBlockNumberAndIndex', callback, [inBlockNumber(blockNumber), inNumber16(index)]); + } + + getLogs (callback, options) { + return this.addListener(this._api, 'eth_getLogs', (error, logs) => { + error + ? callback(error) + : callback(null, (logs) => logs.map(outLog)); + }, [inFilter(options)]); + } + + getWork (callback) { + return this.addListener(this._api, 'eth_getWork', callback); + } +} diff --git a/js/src/api/pubsub/eth/index.js b/js/src/api/pubsub/eth/index.js new file mode 100644 index 000000000..3b8d1994c --- /dev/null +++ b/js/src/api/pubsub/eth/index.js @@ -0,0 +1,16 @@ +// Copyright 2015-2017 Parity Technologies (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 . +export default from './eth'; diff --git a/js/src/api/pubsub/index.js b/js/src/api/pubsub/index.js new file mode 100644 index 000000000..bf342e1de --- /dev/null +++ b/js/src/api/pubsub/index.js @@ -0,0 +1,16 @@ +// Copyright 2015-2017 Parity Technologies (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 . +export default from './pubsub'; diff --git a/js/src/api/pubsub/net/index.js b/js/src/api/pubsub/net/index.js new file mode 100644 index 000000000..6d13847c5 --- /dev/null +++ b/js/src/api/pubsub/net/index.js @@ -0,0 +1,16 @@ +// Copyright 2015-2017 Parity Technologies (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 . +export default from './net'; diff --git a/js/src/api/pubsub/net/net.js b/js/src/api/pubsub/net/net.js new file mode 100644 index 000000000..e1dc3c4e1 --- /dev/null +++ b/js/src/api/pubsub/net/net.js @@ -0,0 +1,42 @@ +// Copyright 2015-2017 Parity Technologies (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 . +import PubsubBase from '../pubsubBase'; + +import { outNumber } from '../../format/output'; + +export default class Net extends PubsubBase { + constructor (transport) { + super(transport); + this._api = 'parity'; + } + + // net API + version (callback) { + return this.addListener(this._api, 'net_version', callback); + } + + peerCount (callback) { + return this.addListener(this._api, 'net_peerCount', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + listening (callback) { + return this.addListener(this._api, 'net_listening', callback); + } +} diff --git a/js/src/api/pubsub/parity/index.js b/js/src/api/pubsub/parity/index.js new file mode 100644 index 000000000..33ce7aa7f --- /dev/null +++ b/js/src/api/pubsub/parity/index.js @@ -0,0 +1,16 @@ +// Copyright 2015-2017 Parity Technologies (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 . +export default from './parity'; diff --git a/js/src/api/pubsub/parity/parity.js b/js/src/api/pubsub/parity/parity.js new file mode 100644 index 000000000..bf18effa1 --- /dev/null +++ b/js/src/api/pubsub/parity/parity.js @@ -0,0 +1,355 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +import PubsubBase from '../pubsubBase'; +import { inAddress, inBlockNumber, inData, inHex, inDeriveHash, inDeriveIndex } from '../../format/input'; +import { outAccountInfo, outAddress, outBlock, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outTransaction, outAddresses, outRecentDapps, outVaultMeta } from '../../format/output'; + +export default class Parity extends PubsubBase { + constructor (transport) { + super(transport); + this._api = 'parity'; + } + + // parity API + accountsInfo (callback) { + return this.addListener(this._api, 'parity_accountsInfo', (error, data) => { + error + ? callback(error) + : callback(null, outAccountInfo(data)); + }); + } + + hardwareAccountsInfo (callback) { + return this.addListener(this._api, 'parity_hardwareAccountsInfo', (error, data) => { + error + ? callback(error) + : callback(null, outHwAccountInfo(data)); + }); + } + + defaultAccount (callback) { + return this.addListener(this._api, 'parity_defaultAccount', (error, data) => { + error + ? callback(error) + : callback(null, outAddress(data)); + }); + } + + transactionsLimit (callback) { + return this.addListener(this._api, 'parity_transactionsLimit', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + extraData (callback) { + return this.addListener(this._api, 'parity_extraData', callback); + } + + gasFloorTarget (callback) { + return this.addListener(this._api, 'parity_gasFloorTarget', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + gasCeilTarget (callback) { + return this.addListener(this._api, 'parity_gasCeilTarget', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + minGasPrice (callback) { + return this.addListener(this._api, 'parity_minGasPrice', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + devLogs (callback) { + return this.addListener(this._api, 'parity_devLogs', callback); + } + + devLogsLevels (callback) { + return this.addListener(this._api, 'parity_devLogsLevels', callback); + } + + netChain (callback) { + return this.addListener(this._api, 'parity_netChain', callback); + } + + netPeers (callback) { + return this.addListener(this._api, 'parity_netPeers', (error, data) => { + error + ? callback(error) + : callback(null, outPeers(data)); + }); + } + + netPort (callback) { + return this.addListener(this._api, 'parity_netPort', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + rpcSettings (callback) { + return this.addListener(this._api, 'parity_rpcSettings', callback); + } + + nodeName (callback) { + return this.addListener(this._api, 'parity_nodeName', callback); + } + + defaultExtraData (callback) { + return this.addListener(this._api, 'parity_defaultExtraData', callback); + } + + gasPriceHistogram (callback) { + return this.addListener(this._api, 'parity_gasPriceHistogram', (error, data) => { + error + ? callback(error) + : callback(null, outHistogram(data)); + }); + } + + unsignedTransactionsCount (callback) { + return this.addListener(this._api, 'parity_unsignedTransactionsCount', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }); + } + + registryAddress (callback) { + return this.addListener(this._api, 'parity_registryAddress', (error, data) => { + error + ? callback(error) + : callback(null, outAddress(data)); + }); + } + + listAccounts (callback, count, offset = null, blockNumber = 'latest') { + return this.addListener(this._api, 'parity_listAccounts', (error, data) => { + error + ? callback(error) + : callback(null, (data) => (data || []).map(outAddress)); + }, [count, inAddress(offset), inBlockNumber(blockNumber)]); + } + + listStorageKeys (callback, address, count, hash = null, blockNumber = 'latest') { + return this.addListener(this._api, 'parity_listStorageKeys', callback, [inAddress(address), count, inHex(hash), inBlockNumber(blockNumber)]); + } + + pendingTransactions (callback) { + return this.addListener(this._api, 'parity_pendingTransactions', (error, data) => { + error + ? callback(error) + : callback(null, outTransaction(data)); + }); + } + + futureTransactions (callback) { + return this.addListener(this._api, 'parity_futureTransactions', (error, data) => { + error + ? callback(error) + : callback(null, outTransaction(data)); + }); + } + + pendingTransactionsStats (callback) { + return this.addListener(this._api, 'parity_pendingTransactionsStats', callback); + } + + localTransactions (callback) { + return this.addListener(this._api, 'parity_localTransactions', (error, transactions) => { + error + ? callback(error) + : callback(null, transactions => { + Object.values(transactions) + .filter(tx => tx.transaction) + .map(tx => { + tx.transaction = outTransaction(tx.transaction); + }); + return transactions; + }); + }); + } + + dappsUrl (callback) { + return this.addListener(this._api, 'parity_dappsUrl', callback); + } + + wsUrl (callback) { + return this.addListener(this._api, 'parity_wsUrl', callback); + } + + nextNonce (callback, account) { + return this.addListener(this._api, 'parity_nextNonce', (error, data) => { + error + ? callback(error) + : callback(null, outNumber(data)); + }, [inAddress(account)]); + } + + mode (callback) { + return this.addListener(this._api, 'parity_mode', callback); + } + + chain (callback) { + return this.addListener(this._api, 'parity_chain', callback); + } + + enode (callback) { + return this.addListener(this._api, 'parity_enode', callback); + } + + consensusCapability (callback) { + return this.addListener(this._api, 'parity_consensusCapability', callback); + } + + versionInfo (callback) { + return this.addListener(this._api, 'parity_versionInfo', callback); + } + + releasesInfo (callback) { + return this.addListener(this._api, 'parity_releasesInfo', callback); + } + + chainStatus (callback) { + return this.addListener(this._api, 'parity_chainStatus', (error, data) => { + error + ? callback(error) + : callback(null, outChainStatus(data)); + }); + } + + nodeKind (callback) { + return this.addListener(this._api, 'parity_nodeKind', (error, data) => { + error + ? callback(error) + : callback(null, outNodeKind(data)); + }); + } + + getBlockHeaderByNumber (callback, blockNumber = 'latest') { + return this.addListener(this._api, 'parity_getBlockHeaderByNumber', (error, data) => { + error + ? callback(error) + : callback(null, outBlock(data)); + }, [inBlockNumber(blockNumber)]); + } + + cidV0 (callback, data) { + return this.addListener(this._api, 'parity_cidV0', callback, [inData(data)]); + } + + // parity accounts API (only secure API or configured to be exposed) + allAccountsInfo (callback) { + return this._addListener(this._api, 'parity_allAccountsInfo', (error, data) => { + error + ? callback(error) + : callback(null, outAccountInfo(data)); + }); + } + + getDappAddresses (callback, dappId) { + return this._addListener(this._api, 'parity_getDappAddresses', (error, data) => { + error + ? callback(error) + : callback(null, outAddresses(data)); + }, [dappId]); + } + + getDappDefaultAddress (callback, dappId) { + return this._addListener(this._api, 'parity_getDappDefaultAddress', (error, data) => { + error + ? callback(error) + : callback(null, outAddress(data)); + }, [dappId]); + } + + getNewDappsAddresses (callback) { + return this._addListener(this._api, 'parity_getDappDefaultAddress', (error, addresses) => { + error + ? callback(error) + : callback(null, addresses ? addresses.map(outAddress) : null); + }); + } + + getNewDappsDefaultAddress (callback) { + return this._addListener(this._api, 'parity_getNewDappsDefaultAddress', (error, data) => { + error + ? callback(error) + : callback(null, outAddress(data)); + }); + } + + listRecentDapps (callback) { + return this._addListener(this._api, 'parity_listRecentDapps', (error, data) => { + error + ? callback(error) + : callback(null, outRecentDapps(data)); + }); + } + + listGethAccounts (callback) { + return this._addListener(this._api, 'parity_listGethAccounts', (error, data) => { + error + ? callback(error) + : callback(null, outAddresses(data)); + }); + } + + listVaults (callback) { + return this._addListener(this._api, 'parity_listVaults', callback); + } + + listOpenedVaults (callback) { + return this._addListener(this._api, 'parity_listOpenedVaults', callback); + } + + getVaultMeta (callback, vaultName) { + return this._addListener(this._api, 'parity_getVaultMeta', (error, data) => { + error + ? callback(error) + : callback(null, outVaultMeta(data)); + }, [vaultName]); + } + + deriveAddressHash (callback, address, password, hash, shouldSave) { + return this._addListener(this._api, 'parity_deriveAddressHash', (error, data) => { + error + ? callback(error) + : callback(null, outAddress(data)); + }, [inAddress(address), password, inDeriveHash(hash), !!shouldSave]); + } + + deriveAddressIndex (callback, address, password, index, shouldSave) { + return this._addListener(this._api, 'parity_deriveAddressIndex', (error, data) => { + error + ? callback(error) + : callback(null, outAddress(data)); + }, [inAddress(address), password, inDeriveIndex(index), !!shouldSave]); + } +} diff --git a/js/src/api/pubsub/pubsub.js b/js/src/api/pubsub/pubsub.js new file mode 100644 index 000000000..edbc201ae --- /dev/null +++ b/js/src/api/pubsub/pubsub.js @@ -0,0 +1,50 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +import Eth from './eth'; +import Parity from './parity'; +import Net from './net'; + +import { isFunction } from '../util/types'; + +export default class Pubsub { + constructor (transport) { + if (!transport || !isFunction(transport.subscribe)) { + throw new Error('Pubsub API needs transport with subscribe() function defined. (WebSocket)'); + } + + this._eth = new Eth(transport); + this._net = new Net(transport); + this._parity = new Parity(transport); + } + + get net () { + return this._net; + } + + get eth () { + return this._eth; + } + + get parity () { + return this._parity; + } + + unsubscribe (subscriptionIds) { + // subscriptions are namespace independent. Thus we can simply removeListener from any. + return this._parity.removeListener(subscriptionIds); + } +} diff --git a/js/src/api/pubsub/pubsub.spec.js b/js/src/api/pubsub/pubsub.spec.js new file mode 100644 index 000000000..10fcd2edb --- /dev/null +++ b/js/src/api/pubsub/pubsub.spec.js @@ -0,0 +1,613 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +import BigNumber from 'bignumber.js'; +import { TEST_WS_URL, mockWs } from '../../../test/mockRpc'; +import { isBigNumber } from '../../../test/types'; + +import Ws from '../transport/ws'; +import Pubsub from './pubsub'; + +describe('api/pubsub/Pubsub', () => { + let scope; + let instance; + const address = '0x63Cf90D3f0410092FC0fca41846f596223979195'; + + describe('accountsInfo', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: { + '0x63cf90d3f0410092fc0fca41846f596223979195': { + name: 'name', uuid: 'uuid', meta: '{"data":"data"}' + } + }, + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('retrieves the available account info', (done) => { + instance.parity.accountsInfo((error, result) => { + expect(error).to.be.null; + expect(result).to.deep.equal({ + '0x63Cf90D3f0410092FC0fca41846f596223979195': { + name: 'name', uuid: 'uuid', meta: { + data: 'data' + } + } + }); + done(); + }); + }); + }); + + describe('Unsubscribe', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2 }, + { method: 'parity_unsubscribe', reply: true }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('Promise gets resolved on success.', (done) => { + instance.parity.accountsInfo().then(s => { + instance.parity.unsubscribe(s).then(b => { + expect(b).to.be.true; + }); + }); + done(); + }); + }); + + describe('chainStatus', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: { + 'blockGap': [0x123, 0x456] + }, + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('retrieves the chain status', (done) => { + instance.parity.chainStatus((error, result) => { + expect(error).to.be.null; + expect(result).to.deep.equal({ + 'blockGap': [new BigNumber(0x123), new BigNumber(0x456)] + }); + done(); + }); + }); + }); + + describe('gasFloorTarget', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: '0x123456', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the gasfloor, formatted', (done) => { + instance.parity.gasFloorTarget((error, result) => { + expect(error).to.be.null; + expect(isBigNumber(result)).to.be.true; + expect(result.eq(0x123456)).to.be.true; + done(); + }); + }); + }); + + describe('transactionsLimit', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: 1024, + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the tx limit, formatted', (done) => { + instance.parity.transactionsLimit((error, result) => { + expect(error).to.be.null; + expect(isBigNumber(result)).to.be.true; + expect(result.eq(1024)).to.be.true; + done(); + }); + }); + }); + + describe('minGasPrice', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: '0x123456', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the min gasprice, formatted', (done) => { + instance.parity.minGasPrice((error, result) => { + expect(error).to.be.null; + expect(isBigNumber(result)).to.be.true; + expect(result.eq(0x123456)).to.be.true; + done(); + }); + }); + }); + + describe('netPeers', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: { active: 123, connected: 456, max: 789, peers: [] }, + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the peer structure, formatted', (done) => { + instance.parity.netPeers((error, peers) => { + expect(error).to.be.null; + expect(peers.active.eq(123)).to.be.true; + expect(peers.connected.eq(456)).to.be.true; + expect(peers.max.eq(789)).to.be.true; + done(); + }); + }); + }); + + describe('netPort', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: 33030, + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the connected port, formatted', (done) => { + instance.parity.netPort((error, count) => { + expect(error).to.be.null; + expect(isBigNumber(count)).to.be.true; + expect(count.eq(33030)).to.be.true; + done(); + }); + }); + }); + +// Eth API + describe('accounts', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: [address.toLowerCase()], + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns a list of accounts, formatted', (done) => { + instance.eth.accounts((error, accounts) => { + expect(error).to.be.null; + expect(accounts).to.deep.equal([address]); + done(); + }); + }); + }); + + describe('newHeads', () => { + beforeEach(() => { + scope = mockWs([{ method: 'eth_subscribe', reply: 2, subscription: { + method: 'eth_subscription', + params: { + result: '0x123456', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns newHeads for eth_subscribe', (done) => { + instance.eth.newHeads((error, blockNumber) => { + expect(error).to.be.null; + expect(blockNumber).to.equal('0x123456'); + done(); + }); + }); + }); + + describe('blockNumber', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: '0x123456', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the current blockNumber, formatted', (done) => { + instance.eth.blockNumber((error, blockNumber) => { + expect(error).to.be.null; + expect(isBigNumber(blockNumber)).to.be.true; + expect(blockNumber.toString(16)).to.equal('123456'); + done(); + }); + }); + }); + + describe('call', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: [], + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('formats the input options & blockNumber', (done) => { + instance.eth.call((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_call', [{ data: '0x12345678' }, 'earliest']]); + done(); + }, { data: '12345678' }, 'earliest'); + }); + + it('provides a latest blockNumber when not specified', (done) => { + instance.eth.call((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_call', [{ data: '0x12345678' }, 'latest']]); + done(); + }, { data: '12345678' }); + }); + }); + + describe('coinbase', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: address.toLowerCase(), + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the coinbase, formatted', (done) => { + instance.eth.coinbase((error, account) => { + expect(error).to.be.null; + expect(account).to.deep.equal(address); + done(); + }); + }); + }); + + describe('estimateGas', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: '0x123', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('converts the options correctly', (done) => { + instance.eth.estimateGas((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_estimateGas', [{ gas: '0x5208' }]]); + done(); + }, { gas: 21000 }); + }); + + it('returns the gas used, formatted', (done) => { + instance.eth.estimateGas((error, gas) => { + expect(error).to.be.null; + expect(isBigNumber(gas)).to.be.true; + expect(gas.toString(16)).to.deep.equal('123'); + done(); + }); + }); + }); + + describe('gasPrice', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: '0x123', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('returns the gas price, formatted', (done) => { + instance.eth.gasPrice((error, price) => { + expect(error).to.be.null; + expect(isBigNumber(price)).to.be.true; + expect(price.toString(16)).to.deep.equal('123'); + done(); + }); + }); + }); + + describe('getBalance', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: '0x123', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('passes in the address (default blockNumber)', (done) => { + instance.eth.getBalance((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getBalance', [address.toLowerCase(), 'latest']]); + done(); + }, address); + }); + + it('passes in the address & blockNumber', (done) => { + instance.eth.getBalance((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getBalance', [address.toLowerCase(), '0x456']]); + done(); + }, address, 0x456); + }); + + it('returns the balance', (done) => { + instance.eth.getBalance((error, balance) => { + expect(error).to.be.null; + expect(isBigNumber(balance)).to.be.true; + expect(balance.toString(16)).to.deep.equal('123'); + done(); + }, address); + }); + }); + + describe('getBlockByHash', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: { miner: address.toLowerCase() }, + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('formats the input hash as a hash, default full', (done) => { + instance.eth.getBlockByHash((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getBlockByHash', ['0x1234', false]]); + done(); + }, '1234'); + }); + + it('formats the input hash as a hash, full true', (done) => { + instance.eth.getBlockByHash((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getBlockByHash', ['0x1234', true]]); + done(); + }, '1234', true); + }); + + it('formats the output into block', (done) => { + instance.eth.getBlockByHash((error, block) => { + expect(error).to.be.null; + expect(block.miner).to.equal(address); + done(); + }, '1234'); + }); + }); + + describe('getBlockByNumber', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: { miner: address.toLowerCase() }, + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('assumes blockNumber latest & full false', (done) => { + instance.eth.getBlockByNumber((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getBlockByNumber', ['latest', false]]); + done(); + }); + }); + + it('uses input blockNumber & full false', (done) => { + instance.eth.getBlockByNumber((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getBlockByNumber', ['0x1234', false]]); + done(); + }, '0x1234'); + }); + + it('formats the input blockNumber, full true', (done) => { + instance.eth.getBlockByNumber((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getBlockByNumber', ['0x1234', true]]); + done(); + }, 0x1234, true); + }); + + it('formats the output into block', (done) => { + instance.eth.getBlockByNumber((error, block) => { + expect(error).to.be.null; + expect(block.miner).to.equal(address); + done(); + }, 0x1234); + }); + }); + + describe('getTransactionCount', () => { + beforeEach(() => { + scope = mockWs([{ method: 'parity_subscribe', reply: 2, subscription: { + method: 'parity_subscription', + params: { + result: '0x123', + subscription: 2 + } + } }]); + instance = new Pubsub(new Ws(TEST_WS_URL)); + }); + + afterEach(() => { + scope.stop(); + }); + + it('passes in the address (default blockNumber)', (done) => { + instance.eth.getTransactionCount((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getTransactionCount', [address.toLowerCase(), 'latest']]); + done(); + }, address); + }); + + it('passes in the address & blockNumber', (done) => { + instance.eth.getTransactionCount((error) => { + expect(error).to.be.null; + expect(scope.body.parity_subscribe.params).to.deep.equal(['eth_getTransactionCount', [address.toLowerCase(), '0x456']]); + done(); + }, address, 0x456); + }); + + it('returns the count, formatted', (done) => { + instance.eth.getTransactionCount((error, count) => { + expect(error).to.be.null; + expect(isBigNumber(count)).to.be.true; + expect(count.toString(16)).to.equal('123'); + done(); + }, address, 0x456); + }); + }); +}); diff --git a/js/src/api/pubsub/pubsubBase.js b/js/src/api/pubsub/pubsubBase.js new file mode 100644 index 000000000..fcc7525d5 --- /dev/null +++ b/js/src/api/pubsub/pubsubBase.js @@ -0,0 +1,37 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +export default class PubsubBase { + // Provider for websocket pubsub transport + constructor (transport) { + this._transport = transport; + } + + addListener (module, eventName, callback, eventParams) { + return eventParams + ? this._transport.subscribe(module, callback, eventName, eventParams) + : this._transport.subscribe(module, callback, eventName, []); + // this._transport.subscribe(module, callback, eventName); After Patch from tomac is merged to master! => eth_subscribe does not support empty array as params + } + + removeListener (subscriptionIds) { + return this._transport.unsubscribe(subscriptionIds); + } + + unsubscribe (subscriptionIds) { + return this.removeListener(subscriptionIds); + } +} diff --git a/js/src/api/rpc/parity/parity.spec.js b/js/src/api/rpc/parity/parity.spec.js index d7eb41047..6ba7a1c83 100644 --- a/js/src/api/rpc/parity/parity.spec.js +++ b/js/src/api/rpc/parity/parity.spec.js @@ -110,7 +110,7 @@ describe('api/rpc/parity', () => { }); }); - describe('newPeers', () => { + describe('netPeers', () => { it('returns the peer structure, formatted', () => { mockHttp([{ method: 'parity_netPeers', reply: { result: { active: 123, connected: 456, max: 789, peers: [] } } }]); diff --git a/js/src/api/rpc/trace/trace.js b/js/src/api/rpc/trace/trace.js index 29494a9ae..26b19b378 100644 --- a/js/src/api/rpc/trace/trace.js +++ b/js/src/api/rpc/trace/trace.js @@ -28,9 +28,9 @@ export default class Trace { .then(outTraces); } - call (options, blockNumber = 'latest', whatTrace = ['trace']) { + call (options, whatTrace = ['trace'], blockNumber = 'latest') { return this._transport - .execute('trace_call', inOptions(options), inBlockNumber(blockNumber), inTraceType(whatTrace)) + .execute('trace_call', inOptions(options), inTraceType(whatTrace), inBlockNumber(blockNumber)) .then(outTraceReplay); } diff --git a/js/src/api/transport/ws/ws.js b/js/src/api/transport/ws/ws.js index 63cfcc5ec..3c642d5f8 100644 --- a/js/src/api/transport/ws/ws.js +++ b/js/src/api/transport/ws/ws.js @@ -22,12 +22,14 @@ import TransportError from '../error'; /* global WebSocket */ export default class Ws extends JsonRpcBase { - constructor (url, token, autoconnect = true) { + // token is optional (secure API) + constructor (url, token = null, autoconnect = true) { super(); this._url = url; this._token = token; this._messages = {}; + this._subscriptions = { 'eth_subscription': [], 'parity_subscription': [] }; this._sessionHash = null; this._connecting = false; @@ -68,10 +70,6 @@ export default class Ws extends JsonRpcBase { this._reconnectTimeoutId = null; } - const time = parseInt(new Date().getTime() / 1000, 10); - const sha3 = keccak_256(`${this._token}:${time}`); - const hash = `${sha3}_${time}`; - if (this._ws) { this._ws.onerror = null; this._ws.onopen = null; @@ -81,13 +79,23 @@ export default class Ws extends JsonRpcBase { this._ws = null; this._sessionHash = null; } - this._connecting = true; this._connected = false; this._lastError = null; - this._sessionHash = sha3; - this._ws = new WebSocket(this._url, hash); + // rpc secure API + if (this._token) { + const time = parseInt(new Date().getTime() / 1000, 10); + const sha3 = keccak_256(`${this._token}:${time}`); + const hash = `${sha3}_${time}`; + + this._sessionHash = sha3; + this._ws = new WebSocket(this._url, hash); + // non-secure API + } else { + this._ws = new WebSocket(this._url); + } + this._ws.onerror = this._onError; this._ws.onopen = this._onOpen; this._ws.onclose = this._onClose; @@ -194,13 +202,48 @@ export default class Ws extends JsonRpcBase { }, 50); } + _extract = (result) => { + const { result: res, id, method, params } = result; + const msg = this._messages[id]; + + // initial pubsub ACK + if (id && msg.subscription) { + // save subscription to map subId -> messageId + this._subscriptions[msg.subscription][res] = id; + // resolve promise with messageId because subId's can collide (eth/parity) + msg.resolve(id); + // save subId for unsubscribing later + msg.subId = res; + return msg; + } + + // normal message + if (id) { + return msg; + } + + // pubsub format + if (method.includes('subscription')) { + const messageId = this._messages[this._subscriptions[method][params.subscription]]; + + if (messageId) { + return messageId; + } else { + throw Error(`Received Subscription which is already unsubscribed ${JSON.stringify(result)}`); + } + } + + throw Error(`Unknown message format: No ID or subscription ${JSON.stringify(result)}`); + } + _onMessage = (event) => { try { const result = JSON.parse(event.data); - const { method, params, json, resolve, reject } = this._messages[result.id]; + const { method, params, json, resolve, reject, callback, subscription } = this._extract(result); Logging.send(method, params, { json, result }); + result.error = (result.params && result.params.error) || result.error; if (result.error) { this.error(event.data); @@ -211,14 +254,23 @@ export default class Ws extends JsonRpcBase { const error = new TransportError(method, result.error.code, result.error.message); - reject(error); + if (result.id) { + reject(error); + } else { + callback(error); + } delete this._messages[result.id]; return; } - resolve(result.result); - delete this._messages[result.id]; + // if not initial subscription message resolve & delete + if (result.id && !subscription) { + resolve(result.result); + delete this._messages[result.id]; + } else if (result.params) { + callback(null, result.params.result); + } } catch (e) { console.error('ws::_onMessage', event.data, e); } @@ -249,6 +301,43 @@ export default class Ws extends JsonRpcBase { }); } + _methodsFromApi (api) { + const method = `${api}_subscribe`; + const uMethod = `${api}_unsubscribe`; + const subscription = `${api}_subscription`; + + return { method, uMethod, subscription }; + } + + subscribe (api, callback, ...params) { + return new Promise((resolve, reject) => { + const id = this.id; + const { method, uMethod, subscription } = this._methodsFromApi(api); + const json = this.encode(method, params); + + this._messages[id] = { id, method, uMethod, params, json, resolve, reject, callback, subscription }; + + this._send(id); + }); + } + + unsubscribe (messageId) { + return new Promise((resolve, reject) => { + const id = this.id; + const { subId, uMethod, subscription } = this._messages[messageId]; + const params = [subId]; + const json = this.encode(uMethod, params); + const uResolve = (v) => { + delete this._messages[messageId]; + delete this._subscriptions[subscription][subId]; + resolve(v); + }; + + this._messages[id] = { id, method: uMethod, params, json, resolve: uResolve, reject }; + this._send(id); + }); + } + set url (url) { this._url = url; } diff --git a/js/src/jsonrpc/interfaces/eth.js b/js/src/jsonrpc/interfaces/eth.js index c52b9bc7a..d54c57325 100644 --- a/js/src/jsonrpc/interfaces/eth.js +++ b/js/src/jsonrpc/interfaces/eth.js @@ -545,6 +545,39 @@ The following options are possible for the \`defaultBlock\` parameter: input: { type: Data, desc: 'the data send along with the transaction.' + }, + v: { + type: Quantity, + desc: 'the standardised V field of the signature.' + }, + standard_v: { + type: Quantity, + desc: 'the standardised V field of the signature (0 or 1).' + }, + r: { + type: Quantity, + desc: 'the R field of the signature.' + }, + raw: { + type: Data, + desc: 'raw transaction data' + }, + publicKey: { + type: Hash, + desc: 'public key of the signer.' + }, + networkId: { + type: Quantity, + desc: 'the network id of the transaction, if any.' + }, + creates: { + type: Hash, + desc: 'creates contract hash' + }, + condition: { + type: Object, + optional: true, + desc: 'conditional submission, Block number in `block` or timestamp in `time` or `null`. (parity-feature)' } }, example: { @@ -1057,6 +1090,39 @@ The following options are possible for the \`defaultBlock\` parameter: input: { type: Data, desc: 'the data send along with the transaction.' + }, + v: { + type: Quantity, + desc: 'the standardised V field of the signature.' + }, + standard_v: { + type: Quantity, + desc: 'the standardised V field of the signature (0 or 1).' + }, + r: { + type: Quantity, + desc: 'the R field of the signature.' + }, + raw: { + type: Data, + desc: 'raw transaction data' + }, + publicKey: { + type: Hash, + desc: 'public key of the signer.' + }, + networkId: { + type: Quantity, + desc: 'the network id of the transaction, if any.' + }, + creates: { + type: Hash, + desc: 'creates contract hash' + }, + condition: { + type: Object, + optional: true, + desc: 'conditional submission, Block number in `block` or timestamp in `time` or `null`. (parity-feature)' } } } diff --git a/js/test/mockRpc.js b/js/test/mockRpc.js index eb15e98ed..b3c6abc3e 100644 --- a/js/test/mockRpc.js +++ b/js/test/mockRpc.js @@ -70,6 +70,10 @@ export function mockWs (requests) { scope.requests++; mockServer.send(JSON.stringify(response)); + + if (request.method.match('subscribe') && request.subscription) { + mockServer.send(JSON.stringify(request.subscription)); + } }); return scope; From 33f1d2af1e5be828a2d93fd04a5c71a1b4e1e375 Mon Sep 17 00:00:00 2001 From: GitLab Build Bot Date: Thu, 6 Jul 2017 08:21:42 +0000 Subject: [PATCH 6/7] [ci skip] js-precompiled 20170706-081457 --- Cargo.lock | 2 +- js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63597b890..e7002d093 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1834,7 +1834,7 @@ dependencies = [ [[package]] name = "parity-ui-precompiled" version = "1.4.0" -source = "git+https://github.com/paritytech/js-precompiled.git#7dc30d69a4e15b1fc22d3d25939a177f0979df07" +source = "git+https://github.com/paritytech/js-precompiled.git#d046d5b5393e90617f4d9a51a5af90fbe516793d" dependencies = [ "parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/js/package.json b/js/package.json index 36fc6754e..0c22c0c3a 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "parity.js", - "version": "1.7.96", + "version": "1.7.97", "main": "release/index.js", "jsnext:main": "src/index.js", "author": "Parity Team ", From 46183b1cdd3b0c2a2a858027b02a56e73ad6181f Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 6 Jul 2017 11:26:14 +0200 Subject: [PATCH 7/7] bigint upgraded to version 3.0 (#5986) * bigint upgraded to version 3.0 * fixed missing FromHex import in ethcore tests * fixed missing FromHex import in rpc tests --- Cargo.lock | 46 +++++--- dapps/Cargo.toml | 2 +- dapps/src/apps/fetcher/mod.rs | 2 +- dapps/src/lib.rs | 2 +- dapps/src/tests/fetch.rs | 2 +- dapps/src/tests/helpers/registrar.rs | 2 +- ethcore/Cargo.toml | 1 + ethcore/src/blockchain/blockchain.rs | 2 +- ethcore/src/builtin.rs | 8 +- ethcore/src/client/test_client.rs | 1 + ethcore/src/engines/tendermint/mod.rs | 1 + ethcore/src/engines/validator_set/contract.rs | 1 + .../engines/validator_set/safe_contract.rs | 1 + ethcore/src/env_info.rs | 2 - ethcore/src/evm/interpreter/shared_cache.rs | 2 +- ethcore/src/evm/tests.rs | 3 +- ethcore/src/executive.rs | 3 +- ethcore/src/header.rs | 2 +- ethcore/src/lib.rs | 1 + ethcore/src/miner/banning_queue.rs | 3 +- ethcore/src/miner/miner.rs | 3 +- ethcore/src/miner/transaction_queue.rs | 6 +- ethcore/src/spec/spec.rs | 1 + ethcore/src/state/mod.rs | 2 +- ethcore/src/types/receipt.rs | 4 +- ethcore/src/types/transaction.rs | 4 +- ethcore/src/views/block.rs | 2 +- ethcore/src/views/body.rs | 2 +- ethcore/src/views/header.rs | 2 +- ethcore/src/views/transaction.rs | 2 +- ethkey/Cargo.toml | 2 +- ethkey/cli/Cargo.toml | 2 +- ethkey/cli/src/main.rs | 4 +- ethkey/src/keypair.rs | 2 +- ethkey/src/lib.rs | 2 +- ethkey/src/signature.rs | 2 +- ethstore/Cargo.toml | 2 +- ethstore/cli/Cargo.toml | 2 +- ethstore/cli/src/main.rs | 2 +- ethstore/src/json/bytes.rs | 2 +- ethstore/src/json/hash.rs | 2 +- ethstore/src/json/id.rs | 2 +- ethstore/src/lib.rs | 2 +- evmbin/Cargo.toml | 1 + evmbin/benches/mod.rs | 4 +- evmbin/src/display/json.rs | 2 +- evmbin/src/main.rs | 4 +- hash-fetch/Cargo.toml | 2 +- hash-fetch/src/lib.rs | 2 +- hash-fetch/src/urlhint.rs | 4 +- hw/Cargo.toml | 2 +- hw/src/ledger.rs | 2 +- hw/src/lib.rs | 2 +- json/Cargo.toml | 2 +- json/src/bytes.rs | 2 +- json/src/hash.rs | 2 +- json/src/lib.rs | 2 +- rpc/Cargo.toml | 2 +- rpc/src/lib.rs | 2 +- rpc/src/v1/helpers/secretstore.rs | 2 +- rpc/src/v1/tests/mocked/eth.rs | 4 +- rpc/src/v1/tests/mocked/parity_set.rs | 2 +- rpc/src/v1/types/bytes.rs | 5 +- rpc/src/v1/types/call_request.rs | 2 +- rpc/src/v1/types/hash.rs | 2 +- rpc/src/v1/types/transaction_request.rs | 2 +- rpc_cli/Cargo.toml | 2 +- secret_store/Cargo.toml | 2 +- secret_store/src/lib.rs | 2 +- secret_store/src/serialization.rs | 2 +- util/Cargo.toml | 4 +- util/benches/bigint.rs | 111 ------------------ util/bigint/Cargo.toml | 7 +- util/bigint/src/hash.rs | 12 +- util/bigint/src/lib.rs | 7 +- util/network/Cargo.toml | 1 + util/network/src/discovery.rs | 2 +- util/network/src/handshake.rs | 2 +- util/network/src/lib.rs | 1 + util/rlp/Cargo.toml | 2 +- util/rlp/src/lib.rs | 2 +- util/rlp/src/rlpin.rs | 2 +- util/rlp/src/untrusted_rlp.rs | 4 +- util/src/error.rs | 2 +- util/src/lib.rs | 2 +- util/src/standard.rs | 6 +- 86 files changed, 139 insertions(+), 235 deletions(-) delete mode 100644 util/benches/bigint.rs diff --git a/Cargo.lock b/Cargo.lock index abb2fd705..3150bf81f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,13 +69,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bigint" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -406,6 +405,7 @@ dependencies = [ "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "stats 0.1.0", @@ -417,11 +417,11 @@ dependencies = [ name = "ethcore-bigint" version = "0.1.3" dependencies = [ - "bigint 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bigint 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -570,6 +570,7 @@ dependencies = [ "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", @@ -597,7 +598,7 @@ dependencies = [ "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "native-contracts 0.1.0", "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -653,7 +654,7 @@ dependencies = [ "rlp 0.2.0", "rocksdb 0.4.5 (git+https://github.com/paritytech/rust-rocksdb)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "sha3 0.1.0", "table 0.1.0", @@ -682,7 +683,7 @@ version = "0.1.0" dependencies = [ "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-util 1.7.0", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -698,7 +699,7 @@ dependencies = [ "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -708,7 +709,7 @@ version = "0.1.0" dependencies = [ "docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.2.0", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -725,7 +726,7 @@ dependencies = [ "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -741,7 +742,7 @@ version = "0.1.0" dependencies = [ "docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethstore 0.1.0", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -777,6 +778,7 @@ dependencies = [ "docopt 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.7.0", "ethcore-util 1.7.0", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -896,7 +898,7 @@ dependencies = [ "libusb 0.3.0 (git+https://github.com/paritytech/libusb-rs)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1655,7 +1657,7 @@ dependencies = [ "parity-reactor 0.1.0", "parity-ui 1.7.0", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1693,7 +1695,7 @@ dependencies = [ "native-contracts 0.1.0", "parity-reactor 0.1.0", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1769,7 +1771,7 @@ dependencies = [ "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2122,7 +2124,7 @@ dependencies = [ "elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-bigint 0.1.3", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2182,7 +2184,7 @@ dependencies = [ name = "rpc-cli" version = "1.4.0" dependencies = [ - "bigint 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bigint 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-util 1.7.0", "futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc 1.7.0", @@ -2202,6 +2204,11 @@ dependencies = [ "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-hex" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rustc-serialize" version = "0.3.19" @@ -2908,7 +2915,7 @@ dependencies = [ "checksum aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfdf7355d9db158df68f976ed030ab0f6578af811f5a7bb6dcf221ec24e0e0" "checksum base-x 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f59103b47307f76e03bef1633aec7fa9e29bfb5aa6daf5a334f94233c71f6c1" "checksum base32 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1b9605ba46d61df0410d8ac686b0007add8172eba90e8e909c347856fe794d8c" -"checksum bigint 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d493e6869ed11b135750f4a4f44d574a52bf8f67e656cdc15b4085316c2098b6" +"checksum bigint 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0673c930652d3d4d6dcd5c45b5db4fa5f8f33994d7323618c43c083b223e8c" "checksum bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e103c8b299b28a9c6990458b7013dc4a8356a9b854c51b9883241f5866fac36e" "checksum bit-set 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e6e1e6fb1c9e3d6fcdec57216a74eaa03e41f52a22f13a16438251d8e88b89da" "checksum bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9bf6104718e80d7b26a68fdbacff3481cfc05df670821affc7e9cbc1884400c" @@ -3065,6 +3072,7 @@ dependencies = [ "checksum rpassword 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5d3a99497c5c544e629cc8b359ae5ede321eba5fa8e5a8078f3ced727a976c3f" "checksum rpassword 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab6e42be826e215f30ff830904f8f4a0933c6e2ae890e1af8b408f5bae60081e" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" +"checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" "checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum rustc_version 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1e114e275f7c9b5d50bb52b28f9aac1921209f02aa6077c8b255e21eefaf8ffa" diff --git a/dapps/Cargo.toml b/dapps/Cargo.toml index 429ed01f5..ba6cf67ce 100644 --- a/dapps/Cargo.toml +++ b/dapps/Cargo.toml @@ -17,7 +17,7 @@ parity-dapps-glue = "1.7" mime = "0.2" mime_guess = "1.6.1" rand = "0.3" -rustc-serialize = "0.3" +rustc-hex = "1.0" serde = "0.9" serde_derive = "0.9" serde_json = "0.9" diff --git a/dapps/src/apps/fetcher/mod.rs b/dapps/src/apps/fetcher/mod.rs index d621042c4..ff14def7b 100644 --- a/dapps/src/apps/fetcher/mod.rs +++ b/dapps/src/apps/fetcher/mod.rs @@ -23,7 +23,7 @@ mod installers; use std::{fs, env}; use std::path::PathBuf; use std::sync::Arc; -use rustc_serialize::hex::FromHex; +use rustc_hex::FromHex; use fetch::{Client as FetchClient, Fetch}; use hash_fetch::urlhint::{URLHintContract, URLHint, URLHintResult}; use parity_reactor::Remote; diff --git a/dapps/src/lib.rs b/dapps/src/lib.rs index 1cbc446a7..0b93f4e39 100644 --- a/dapps/src/lib.rs +++ b/dapps/src/lib.rs @@ -24,7 +24,7 @@ extern crate futures; extern crate linked_hash_map; extern crate mime_guess; extern crate rand; -extern crate rustc_serialize; +extern crate rustc_hex; extern crate serde; extern crate serde_json; extern crate time; diff --git a/dapps/src/tests/fetch.rs b/dapps/src/tests/fetch.rs index 51650a963..8abc86196 100644 --- a/dapps/src/tests/fetch.rs +++ b/dapps/src/tests/fetch.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use devtools::http_client; -use rustc_serialize::hex::FromHex; +use rustc_hex::FromHex; use tests::helpers::{ serve_with_registrar, serve_with_registrar_and_sync, serve_with_fetch, serve_with_registrar_and_fetch, serve_with_registrar_and_fetch_and_threads, diff --git a/dapps/src/tests/helpers/registrar.rs b/dapps/src/tests/helpers/registrar.rs index 58aad9886..d7890675b 100644 --- a/dapps/src/tests/helpers/registrar.rs +++ b/dapps/src/tests/helpers/registrar.rs @@ -17,7 +17,7 @@ use std::str; use std::sync::Arc; use std::collections::HashMap; -use rustc_serialize::hex::FromHex; +use rustc_hex::FromHex; use hash_fetch::urlhint::ContractClient; use util::{Bytes, Address, Mutex, H256, ToPretty}; diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 168cf803c..99986d6da 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -46,6 +46,7 @@ num_cpus = "1.2" rand = "0.3" rlp = { path = "../util/rlp" } rust-crypto = "0.2.34" +rustc-hex = "1.0" rustc-serialize = "0.3" semver = "0.6" stats = { path = "../util/stats" } diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 8f66c270d..4412df567 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -1460,7 +1460,7 @@ impl BlockChain { mod tests { #![cfg_attr(feature="dev", allow(similar_names))] use std::sync::Arc; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use util::kvdb::KeyValueDB; use util::hash::*; use util::sha3::Hashable; diff --git a/ethcore/src/builtin.rs b/ethcore/src/builtin.rs index 90190ac8e..084be4666 100644 --- a/ethcore/src/builtin.rs +++ b/ethcore/src/builtin.rs @@ -500,7 +500,7 @@ mod tests { use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp}; use ethjson; use util::{U256, BytesRef}; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; #[test] fn identity() { @@ -524,7 +524,6 @@ mod tests { #[test] fn sha256() { - use rustc_serialize::hex::FromHex; let f = ethereum_builtin("sha256"); let i = [0u8; 0]; @@ -548,7 +547,6 @@ mod tests { #[test] fn ripemd160() { - use rustc_serialize::hex::FromHex; let f = ethereum_builtin("ripemd160"); let i = [0u8; 0]; @@ -568,7 +566,6 @@ mod tests { #[test] fn ecrecover() { - use rustc_serialize::hex::FromHex; /*let k = KeyPair::from_secret(b"test".sha3()).unwrap(); let a: Address = From::from(k.public().sha3()); println!("Address: {}", a); @@ -627,7 +624,6 @@ mod tests { #[test] fn modexp() { - use rustc_serialize::hex::FromHex; let f = Builtin { pricer: Box::new(Modexp { divisor: 20 }), @@ -714,7 +710,6 @@ mod tests { #[test] fn bn128_add() { - use rustc_serialize::hex::FromHex; let f = Builtin { pricer: Box::new(Linear { base: 0, word: 0 }), @@ -776,7 +771,6 @@ mod tests { #[test] fn bn128_mul() { - use rustc_serialize::hex::FromHex; let f = Builtin { pricer: Box::new(Linear { base: 0, word: 0 }), diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 19fdd74c8..e656e6c42 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -17,6 +17,7 @@ //! Test client. use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder}; +use rustc_hex::FromHex; use util::*; use rlp::*; use ethkey::{Generator, Random}; diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index 70d4e0ced..e7d0dab86 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -651,6 +651,7 @@ impl Engine for Tendermint { #[cfg(test)] mod tests { + use rustc_hex::FromHex; use util::*; use block::*; use error::{Error, BlockError}; diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index c2d3fd064..46f5c8512 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -126,6 +126,7 @@ impl ValidatorSet for ValidatorContract { #[cfg(test)] mod tests { + use rustc_hex::FromHex; use util::*; use rlp::encode; use spec::Spec; diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index de8d16ddc..e999439ee 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -420,6 +420,7 @@ impl ValidatorSet for ValidatorSafeContract { #[cfg(test)] mod tests { + use rustc_hex::FromHex; use util::*; use types::ids::BlockId; use spec::Spec; diff --git a/ethcore/src/env_info.rs b/ethcore/src/env_info.rs index cc42008d5..4f6a330b0 100644 --- a/ethcore/src/env_info.rs +++ b/ethcore/src/env_info.rs @@ -76,8 +76,6 @@ impl From for EnvInfo { #[cfg(test)] mod tests { - extern crate rustc_serialize; - use std::str::FromStr; use super::*; use util::{U256, Address}; diff --git a/ethcore/src/evm/interpreter/shared_cache.rs b/ethcore/src/evm/interpreter/shared_cache.rs index ed3b59340..a93afa79a 100644 --- a/ethcore/src/evm/interpreter/shared_cache.rs +++ b/ethcore/src/evm/interpreter/shared_cache.rs @@ -92,7 +92,7 @@ impl Default for SharedCache { #[test] fn test_find_jump_destinations() { - use util::FromHex; + use rustc_hex::FromHex; // given let code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5b01600055".from_hex().unwrap(); diff --git a/ethcore/src/evm/tests.rs b/ethcore/src/evm/tests.rs index 7f3cf0e1c..f7d82daa4 100644 --- a/ethcore/src/evm/tests.rs +++ b/ethcore/src/evm/tests.rs @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::fmt::Debug; +use rustc_hex::FromHex; use util::*; use action_params::{ActionParams, ActionValue}; use env_info::EnvInfo; use types::executed::CallType; use evm::{self, Ext, Schedule, Factory, GasLeft, VMType, ContractCreateResult, MessageCallResult, CreateContractAddress, ReturnData}; -use std::fmt::Debug; use tests::helpers::*; use types::transaction::SYSTEM_ADDRESS; use executive::Executive; diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index b486aa8d4..4038fe30d 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -578,9 +578,10 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { #[allow(dead_code)] mod tests { use std::sync::Arc; + use rustc_hex::FromHex; use ethkey::{Generator, Random}; use super::*; - use util::{H256, U256, U512, Address, FromHex, FromStr}; + use util::{H256, U256, U512, Address, FromStr}; use util::bytes::BytesRef; use action_params::{ActionParams, ActionValue}; use env_info::EnvInfo; diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs index aa114c01e..f5bf1dcfd 100644 --- a/ethcore/src/header.rs +++ b/ethcore/src/header.rs @@ -305,7 +305,7 @@ impl HeapSizeOf for Header { #[cfg(test)] mod tests { - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use rlp; use super::Header; diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 7dc49fff8..746a737bf 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -99,6 +99,7 @@ extern crate num_cpus; extern crate num; extern crate rand; extern crate rlp; +extern crate rustc_hex; extern crate rustc_serialize; extern crate semver; extern crate stats; diff --git a/ethcore/src/miner/banning_queue.rs b/ethcore/src/miner/banning_queue.rs index 20b46d760..46d7e7cf8 100644 --- a/ethcore/src/miner/banning_queue.rs +++ b/ethcore/src/miner/banning_queue.rs @@ -209,13 +209,14 @@ impl DerefMut for BanningTransactionQueue { #[cfg(test)] mod tests { use std::time::Duration; + use rustc_hex::FromHex; use super::{BanningTransactionQueue, Threshold}; use ethkey::{Random, Generator}; use transaction::{Transaction, SignedTransaction, Action}; use error::{Error, TransactionError}; use client::TransactionImportResult; use miner::{TransactionQueue, TransactionOrigin}; - use util::{U256, Address, FromHex, Hashable}; + use util::{U256, Address, Hashable}; use miner::transaction_queue::test::DummyTransactionDetailsProvider; fn queue() -> BanningTransactionQueue { diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index c772490ba..208c778bc 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -1261,10 +1261,11 @@ mod tests { use std::sync::Arc; use std::time::Duration; + use rustc_hex::FromHex; use super::super::{MinerService, PrioritizationStrategy}; use super::*; use block::IsBlock; - use util::{U256, FromHex}; + use util::U256; use ethkey::{Generator, Random}; use client::{BlockChainClient, TestBlockChainClient, EachBlockWith, TransactionImportResult}; use header::BlockNumber; diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index d833f8f6a..8da9f7150 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -27,13 +27,13 @@ //! extern crate ethcore_util as util; //! extern crate ethcore; //! extern crate ethkey; -//! extern crate rustc_serialize; +//! extern crate rustc_hex; //! //! use util::{U256, Address}; //! use ethkey::{Random, Generator}; //! use ethcore::miner::{TransactionQueue, RemovalReason, TransactionQueueDetailsProvider, AccountDetails, TransactionOrigin}; //! use ethcore::transaction::*; -//! use rustc_serialize::hex::FromHex; +//! use rustc_hex::FromHex; //! //! #[derive(Default)] //! struct DummyTransactionDetailsProvider; @@ -1422,7 +1422,7 @@ fn check_if_removed(sender: &Address, nonce: &U256, dropped: Option for PendingTransaction { #[test] fn sender_test() { - let t: UnverifiedTransaction = decode(&::rustc_serialize::hex::FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap()); + let t: UnverifiedTransaction = decode(&::rustc_hex::FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap()); assert_eq!(t.data, b""); assert_eq!(t.gas, U256::from(0x5208u64)); assert_eq!(t.gas_price, U256::from(0x01u64)); @@ -612,7 +612,7 @@ fn should_recover_from_network_specific_signing() { #[test] fn should_agree_with_vitalik() { - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; let test_vector = |tx_data: &str, address: &'static str| { let signed = decode(&FromHex::from_hex(tx_data).unwrap()); diff --git a/ethcore/src/views/block.rs b/ethcore/src/views/block.rs index 463eb7240..f00ca548f 100644 --- a/ethcore/src/views/block.rs +++ b/ethcore/src/views/block.rs @@ -163,7 +163,7 @@ impl<'a> Hashable for BlockView<'a> { #[cfg(test)] mod tests { use std::str::FromStr; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use util::H256; use super::BlockView; diff --git a/ethcore/src/views/body.rs b/ethcore/src/views/body.rs index c32796628..038e152b0 100644 --- a/ethcore/src/views/body.rs +++ b/ethcore/src/views/body.rs @@ -130,7 +130,7 @@ impl<'a> BodyView<'a> { #[cfg(test)] mod tests { - use util::*; + use rustc_hex::FromHex; use super::BodyView; use blockchain::BlockChain; diff --git a/ethcore/src/views/header.rs b/ethcore/src/views/header.rs index 618728525..4506d98ec 100644 --- a/ethcore/src/views/header.rs +++ b/ethcore/src/views/header.rs @@ -104,7 +104,7 @@ impl<'a> Hashable for HeaderView<'a> { #[cfg(test)] mod tests { use std::str::FromStr; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use util::{H256, Address, H2048, U256}; use super::HeaderView; diff --git a/ethcore/src/views/transaction.rs b/ethcore/src/views/transaction.rs index 0b5b2e1ff..11c7fc2f1 100644 --- a/ethcore/src/views/transaction.rs +++ b/ethcore/src/views/transaction.rs @@ -77,7 +77,7 @@ impl<'a> Hashable for TransactionView<'a> { #[cfg(test)] mod tests { use std::str::FromStr; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use util::U256; use super::TransactionView; diff --git a/ethkey/Cargo.toml b/ethkey/Cargo.toml index 7d038a7f7..342410adc 100644 --- a/ethkey/Cargo.toml +++ b/ethkey/Cargo.toml @@ -8,7 +8,7 @@ rand = "0.3.14" lazy_static = "0.2" tiny-keccak = "1.2" eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" } -rustc-serialize = "0.3" +rustc-hex = "1.0" ethcore-bigint = { path = "../util/bigint" } rust-crypto = "0.2" byteorder = "1.0" diff --git a/ethkey/cli/Cargo.toml b/ethkey/cli/Cargo.toml index 01cc9849f..b8da13908 100644 --- a/ethkey/cli/Cargo.toml +++ b/ethkey/cli/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] [dependencies] ethkey = { path = "../" } -rustc-serialize = "0.3" +rustc-hex = "1.0" docopt = "0.7" [[bin]] diff --git a/ethkey/cli/src/main.rs b/ethkey/cli/src/main.rs index 757c8198f..53a6adb4d 100644 --- a/ethkey/cli/src/main.rs +++ b/ethkey/cli/src/main.rs @@ -15,13 +15,13 @@ // along with Parity. If not, see . extern crate docopt; -extern crate rustc_serialize; +extern crate rustc_hex; extern crate ethkey; use std::{env, fmt, process}; use std::num::ParseIntError; use docopt::Docopt; -use rustc_serialize::hex::{FromHex, FromHexError}; +use rustc_hex::{FromHex, FromHexError}; use ethkey::{KeyPair, Random, Brain, Prefix, Error as EthkeyError, Generator, sign, verify_public, verify_address}; pub const USAGE: &'static str = r#" diff --git a/ethkey/src/keypair.rs b/ethkey/src/keypair.rs index 8975063d5..5a13d476b 100644 --- a/ethkey/src/keypair.rs +++ b/ethkey/src/keypair.rs @@ -16,7 +16,7 @@ use std::fmt; use secp256k1::key; -use rustc_serialize::hex::ToHex; +use rustc_hex::ToHex; use keccak::Keccak256; use super::{Secret, Public, Address, SECP256K1, Error}; diff --git a/ethkey/src/lib.rs b/ethkey/src/lib.rs index 60039b671..e87e198df 100644 --- a/ethkey/src/lib.rs +++ b/ethkey/src/lib.rs @@ -19,7 +19,7 @@ extern crate rand; extern crate lazy_static; extern crate tiny_keccak; extern crate secp256k1; -extern crate rustc_serialize; +extern crate rustc_hex; extern crate ethcore_bigint as bigint; extern crate crypto as rcrypto; extern crate byteorder; diff --git a/ethkey/src/signature.rs b/ethkey/src/signature.rs index 91fe3e2a3..67115c98b 100644 --- a/ethkey/src/signature.rs +++ b/ethkey/src/signature.rs @@ -21,7 +21,7 @@ use std::str::FromStr; use std::hash::{Hash, Hasher}; use secp256k1::{Message as SecpMessage, RecoverableSignature, RecoveryId, Error as SecpError}; use secp256k1::key::{SecretKey, PublicKey}; -use rustc_serialize::hex::{ToHex, FromHex}; +use rustc_hex::{ToHex, FromHex}; use bigint::hash::{H520, H256}; use {Secret, Public, SECP256K1, Error, Message, public_to_address, Address}; diff --git a/ethstore/Cargo.toml b/ethstore/Cargo.toml index a2efaf286..62263d801 100755 --- a/ethstore/Cargo.toml +++ b/ethstore/Cargo.toml @@ -11,7 +11,7 @@ ethkey = { path = "../ethkey" } serde = "0.9" serde_json = "0.9" serde_derive = "0.9" -rustc-serialize = "0.3" +rustc-hex = "1.0" rust-crypto = "0.2.36" tiny-keccak = "1.0" time = "0.1.34" diff --git a/ethstore/cli/Cargo.toml b/ethstore/cli/Cargo.toml index 28e210cec..09ec9d13f 100644 --- a/ethstore/cli/Cargo.toml +++ b/ethstore/cli/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -rustc-serialize = "0.3" +rustc-hex = "1.0" docopt = "0.7" ethstore = { path = "../" } diff --git a/ethstore/cli/src/main.rs b/ethstore/cli/src/main.rs index 3e8df3a35..b73f06711 100644 --- a/ethstore/cli/src/main.rs +++ b/ethstore/cli/src/main.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -extern crate rustc_serialize; +extern crate rustc_hex; extern crate docopt; extern crate ethstore; diff --git a/ethstore/src/json/bytes.rs b/ethstore/src/json/bytes.rs index c7ecfec4c..3a48fa2a1 100644 --- a/ethstore/src/json/bytes.rs +++ b/ethstore/src/json/bytes.rs @@ -17,7 +17,7 @@ use std::{ops, str}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::de::Error; -use rustc_serialize::hex::{ToHex, FromHex, FromHexError}; +use rustc_hex::{ToHex, FromHex, FromHexError}; #[derive(Debug, PartialEq)] pub struct Bytes(Vec); diff --git a/ethstore/src/json/hash.rs b/ethstore/src/json/hash.rs index 328f155c2..43920c3a0 100644 --- a/ethstore/src/json/hash.rs +++ b/ethstore/src/json/hash.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use std::{ops, fmt, str}; -use rustc_serialize::hex::{FromHex, ToHex}; +use rustc_hex::{FromHex, ToHex}; use serde::{Serialize, Serializer, Deserialize, Deserializer}; use serde::de::{Visitor, Error as SerdeError}; use super::Error; diff --git a/ethstore/src/json/id.rs b/ethstore/src/json/id.rs index 8dfcc3028..a1db0ccc5 100644 --- a/ethstore/src/json/id.rs +++ b/ethstore/src/json/id.rs @@ -16,7 +16,7 @@ //! Universaly unique identifier. use std::{fmt, str}; -use rustc_serialize::hex::{ToHex, FromHex}; +use rustc_hex::{ToHex, FromHex}; use serde::{Deserialize, Serialize, Deserializer, Serializer}; use serde::de::{Visitor, Error as SerdeError}; use super::Error; diff --git a/ethstore/src/lib.rs b/ethstore/src/lib.rs index 06a8259de..65935f89c 100755 --- a/ethstore/src/lib.rs +++ b/ethstore/src/lib.rs @@ -23,7 +23,7 @@ extern crate itertools; extern crate libc; extern crate parking_lot; extern crate rand; -extern crate rustc_serialize; +extern crate rustc_hex; extern crate serde; extern crate serde_json; extern crate smallvec; diff --git a/evmbin/Cargo.toml b/evmbin/Cargo.toml index 55defab7b..c43a48042 100644 --- a/evmbin/Cargo.toml +++ b/evmbin/Cargo.toml @@ -9,6 +9,7 @@ name = "parity-evm" path = "./src/main.rs" [dependencies] +rustc-hex = "1.0" rustc-serialize = "0.3" docopt = { version = "0.7" } ethcore = { path = "../ethcore" } diff --git a/evmbin/benches/mod.rs b/evmbin/benches/mod.rs index 7ddc50681..a3017c37e 100644 --- a/evmbin/benches/mod.rs +++ b/evmbin/benches/mod.rs @@ -26,14 +26,14 @@ extern crate test; extern crate ethcore; extern crate evm; extern crate ethcore_util; -extern crate rustc_serialize; +extern crate rustc_hex; use self::test::{Bencher, black_box}; use evm::run_vm; use ethcore::action_params::ActionParams; use ethcore_util::U256; -use rustc_serialize::hex::FromHex; +use rustc_hex::FromHex; #[bench] fn simple_loop_usize(b: &mut Bencher) { diff --git a/evmbin/src/display/json.rs b/evmbin/src/display/json.rs index 38265c14c..1791640d6 100644 --- a/evmbin/src/display/json.rs +++ b/evmbin/src/display/json.rs @@ -122,7 +122,7 @@ impl trace::VMTracer for Informant { fn prepare_subtrace(&self, code: &[u8]) -> Self where Self: Sized { let mut vm = Informant::default(); vm.depth = self.depth + 1; - vm.code = code.into_vec(); + vm.code = code.to_vec(); vm.gas_used = self.gas_used; vm } diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index a7d90b90b..ab4ddc4c1 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -19,6 +19,7 @@ #![warn(missing_docs)] #![allow(dead_code)] extern crate ethcore; +extern crate rustc_hex; extern crate rustc_serialize; extern crate docopt; extern crate ethcore_util as util; @@ -26,7 +27,8 @@ extern crate ethcore_util as util; use std::sync::Arc; use std::{fmt, fs}; use docopt::Docopt; -use util::{U256, FromHex, Bytes, Address}; +use rustc_hex::FromHex; +use util::{U256, Bytes, Address}; use ethcore::spec; use ethcore::action_params::ActionParams; diff --git a/hash-fetch/Cargo.toml b/hash-fetch/Cargo.toml index 600402559..b02a74f64 100644 --- a/hash-fetch/Cargo.toml +++ b/hash-fetch/Cargo.toml @@ -13,7 +13,7 @@ log = "0.3" mime = "0.2" mime_guess = "1.6.1" rand = "0.3" -rustc-serialize = "0.3" +rustc-hex = "1.0" fetch = { path = "../util/fetch" } ethcore-util = { path = "../util" } parity-reactor = { path = "../util/reactor" } diff --git a/hash-fetch/src/lib.rs b/hash-fetch/src/lib.rs index 9019f744d..4952ecea2 100644 --- a/hash-fetch/src/lib.rs +++ b/hash-fetch/src/lib.rs @@ -30,7 +30,7 @@ extern crate mime_guess; extern crate native_contracts; extern crate parity_reactor; extern crate rand; -extern crate rustc_serialize; +extern crate rustc_hex; pub extern crate fetch; diff --git a/hash-fetch/src/urlhint.rs b/hash-fetch/src/urlhint.rs index cd7d2a2c5..bc4b63cf2 100644 --- a/hash-fetch/src/urlhint.rs +++ b/hash-fetch/src/urlhint.rs @@ -17,7 +17,7 @@ //! URLHint Contract use std::sync::Arc; -use rustc_serialize::hex::ToHex; +use rustc_hex::ToHex; use mime::Mime; use mime_guess; @@ -209,7 +209,7 @@ fn guess_mime_type(url: &str) -> Option { pub mod tests { use std::sync::Arc; use std::str::FromStr; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use futures::{BoxFuture, Future, IntoFuture}; diff --git a/hw/Cargo.toml b/hw/Cargo.toml index ca236d130..261721470 100644 --- a/hw/Cargo.toml +++ b/hw/Cargo.toml @@ -15,4 +15,4 @@ ethkey = { path = "../ethkey" } ethcore-bigint = { path = "../util/bigint" } [dev-dependencies] -rustc-serialize = "0.3" +rustc-hex = "1.0" diff --git a/hw/src/ledger.rs b/hw/src/ledger.rs index 2f209afa5..0d787588d 100644 --- a/hw/src/ledger.rs +++ b/hw/src/ledger.rs @@ -340,7 +340,7 @@ impl Manager { #[test] fn smoke() { - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; let mut manager = Manager::new().unwrap(); manager.update_devices().unwrap(); for d in &manager.devices { diff --git a/hw/src/lib.rs b/hw/src/lib.rs index a35607305..cda6c2241 100644 --- a/hw/src/lib.rs +++ b/hw/src/lib.rs @@ -22,7 +22,7 @@ extern crate libusb; extern crate ethkey; extern crate ethcore_bigint as bigint; #[macro_use] extern crate log; -#[cfg(test)] extern crate rustc_serialize; +#[cfg(test)] extern crate rustc_hex; mod ledger; diff --git a/json/Cargo.toml b/json/Cargo.toml index 577d0d9e8..d0fec9933 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] [dependencies] ethcore-util = { path = "../util" } -rustc-serialize = "0.3" +rustc-hex = "1.0" serde = "0.9" serde_json = "0.9" serde_derive = "0.9" diff --git a/json/src/bytes.rs b/json/src/bytes.rs index 0900ec999..5b474ba7d 100644 --- a/json/src/bytes.rs +++ b/json/src/bytes.rs @@ -19,7 +19,7 @@ use std::fmt; use std::str::FromStr; use std::ops::Deref; -use rustc_serialize::hex::FromHex; +use rustc_hex::FromHex; use serde::{Deserialize, Deserializer}; use serde::de::{Error, Visitor}; diff --git a/json/src/hash.rs b/json/src/hash.rs index 78fa77bd9..6a2df6515 100644 --- a/json/src/hash.rs +++ b/json/src/hash.rs @@ -20,7 +20,7 @@ use std::str::FromStr; use std::fmt; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::de::{Error, Visitor}; -use rustc_serialize::hex::ToHex; +use rustc_hex::ToHex; use util::hash::{H64 as Hash64, H160 as Hash160, H256 as Hash256, H520 as Hash520, H2048 as Hash2048}; diff --git a/json/src/lib.rs b/json/src/lib.rs index b65b18cab..c03b9f439 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -extern crate rustc_serialize; +extern crate rustc_hex; extern crate serde; extern crate serde_json; extern crate ethcore_util as util; diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index c2fe7fb8a..7b083a3ac 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -15,7 +15,7 @@ multihash ="0.6" order-stat = "0.1" rand = "0.3" rust-crypto = "0.2" -rustc-serialize = "0.3" +rustc-hex = "1.0" semver = "0.6" serde = "0.9" serde_derive = "0.9" diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 7b8e207b8..38dafc0a4 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -26,7 +26,7 @@ extern crate futures; extern crate multihash; extern crate order_stat; extern crate rand; -extern crate rustc_serialize; +extern crate rustc_hex; extern crate semver; extern crate serde; extern crate serde_json; diff --git a/rpc/src/v1/helpers/secretstore.rs b/rpc/src/v1/helpers/secretstore.rs index 9563302d9..246d0fa3f 100644 --- a/rpc/src/v1/helpers/secretstore.rs +++ b/rpc/src/v1/helpers/secretstore.rs @@ -99,7 +99,7 @@ fn decrypt_with_shadow_coefficients(mut decrypted_shadow: Public, mut common_sha #[cfg(test)] mod tests { use util::Bytes; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use super::{encrypt_document, decrypt_document, decrypt_document_with_shadow}; #[test] diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 3f158f1c5..33d46c04f 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -18,7 +18,7 @@ use std::str::FromStr; use std::collections::HashMap; use std::sync::Arc; use std::time::{Instant, Duration}; -use rustc_serialize::hex::{FromHex, ToHex}; +use rustc_hex::{FromHex, ToHex}; use time::get_time; use rlp; @@ -536,7 +536,7 @@ fn rpc_eth_transaction_count_by_number_pending() { #[test] fn rpc_eth_pending_transaction_by_hash() { - use util::{H256, FromHex}; + use util::H256; use rlp; use ethcore::transaction::SignedTransaction; diff --git a/rpc/src/v1/tests/mocked/parity_set.rs b/rpc/src/v1/tests/mocked/parity_set.rs index cff9e710d..443379b4f 100644 --- a/rpc/src/v1/tests/mocked/parity_set.rs +++ b/rpc/src/v1/tests/mocked/parity_set.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use std::str::FromStr; -use rustc_serialize::hex::FromHex; +use rustc_hex::FromHex; use util::{U256, Address}; use ethcore::miner::MinerService; diff --git a/rpc/src/v1/types/bytes.rs b/rpc/src/v1/types/bytes.rs index b290dd5ac..22a74f97d 100644 --- a/rpc/src/v1/types/bytes.rs +++ b/rpc/src/v1/types/bytes.rs @@ -17,10 +17,9 @@ //! Serializable wrapper around vector of bytes use std::fmt; -use rustc_serialize::hex::ToHex; +use rustc_hex::{ToHex, FromHex}; use serde::{Serialize, Serializer, Deserialize, Deserializer}; use serde::de::{Error, Visitor}; -use util::common::FromHex; /// Wrapper structure around vector of bytes. #[derive(Debug, PartialEq, Eq, Default, Hash, Clone)] @@ -98,7 +97,7 @@ impl Visitor for BytesVisitor { mod tests { use super::*; use serde_json; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; #[test] fn test_bytes_serialize() { diff --git a/rpc/src/v1/types/call_request.rs b/rpc/src/v1/types/call_request.rs index 04c9efcaf..71b562e45 100644 --- a/rpc/src/v1/types/call_request.rs +++ b/rpc/src/v1/types/call_request.rs @@ -55,7 +55,7 @@ impl Into for CallRequest { #[cfg(test)] mod tests { use std::str::FromStr; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use serde_json; use v1::types::{U256, H160}; use super::CallRequest; diff --git a/rpc/src/v1/types/hash.rs b/rpc/src/v1/types/hash.rs index 2f230510d..166aebfa3 100644 --- a/rpc/src/v1/types/hash.rs +++ b/rpc/src/v1/types/hash.rs @@ -19,7 +19,7 @@ use std::str::FromStr; use std::cmp::Ordering; use std::hash::{Hash, Hasher}; use serde; -use rustc_serialize::hex::{ToHex, FromHex}; +use rustc_hex::{ToHex, FromHex}; use util::{H64 as Eth64, H160 as Eth160, H256 as Eth256, H520 as Eth520, H512 as Eth512, H2048 as Eth2048}; macro_rules! impl_hash { diff --git a/rpc/src/v1/types/transaction_request.rs b/rpc/src/v1/types/transaction_request.rs index 242c02360..cb74e071b 100644 --- a/rpc/src/v1/types/transaction_request.rs +++ b/rpc/src/v1/types/transaction_request.rs @@ -131,7 +131,7 @@ impl Into for TransactionRequest { #[cfg(test)] mod tests { use std::str::FromStr; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use serde_json; use v1::types::{U256, H160, TransactionCondition}; use super::*; diff --git a/rpc_cli/Cargo.toml b/rpc_cli/Cargo.toml index 2a473a6ab..52fc58fe4 100644 --- a/rpc_cli/Cargo.toml +++ b/rpc_cli/Cargo.toml @@ -9,7 +9,7 @@ version = "1.4.0" [dependencies] futures = "0.1" rpassword = "0.3.0" -bigint = "2.0" +bigint = "3.0" parity-rpc = { path = "../rpc" } parity-rpc-client = { path = "../rpc_client" } ethcore-util = { path = "../util" } diff --git a/secret_store/Cargo.toml b/secret_store/Cargo.toml index d31ebe11d..2d7eccfa4 100644 --- a/secret_store/Cargo.toml +++ b/secret_store/Cargo.toml @@ -19,7 +19,7 @@ serde_json = "0.9" serde_derive = "0.9" futures = "0.1" futures-cpupool = "0.1" -rustc-serialize = "0.3" +rustc-hex = "1.0" tokio-core = "0.1.6" tokio-io = "0.1.0" tokio-service = "0.1" diff --git a/secret_store/src/lib.rs b/secret_store/src/lib.rs index 209a32cc2..4176bd322 100644 --- a/secret_store/src/lib.rs +++ b/secret_store/src/lib.rs @@ -22,7 +22,7 @@ extern crate futures; extern crate futures_cpupool; extern crate hyper; extern crate parking_lot; -extern crate rustc_serialize; +extern crate rustc_hex; extern crate serde; extern crate serde_json; #[macro_use] diff --git a/secret_store/src/serialization.rs b/secret_store/src/serialization.rs index c88e9edf7..4b42311cf 100644 --- a/secret_store/src/serialization.rs +++ b/secret_store/src/serialization.rs @@ -17,7 +17,7 @@ use std::fmt; use std::cmp::{Ord, PartialOrd, Ordering}; use std::ops::Deref; -use rustc_serialize::hex::{ToHex, FromHex}; +use rustc_hex::{ToHex, FromHex}; use serde::{Serialize, Deserialize, Serializer, Deserializer}; use serde::de::{Visitor, Error as SerdeError}; use ethkey::{Public, Secret, Signature}; diff --git a/util/Cargo.toml b/util/Cargo.toml index 0af5635ab..8a0928ff5 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -10,7 +10,7 @@ build = "build.rs" [dependencies] log = "0.3" env_logger = "0.4" -rustc-serialize = "0.3" +rustc-hex = "1.0" rand = "0.3.12" time = "0.1.34" rocksdb = { git = "https://github.com/paritytech/rust-rocksdb" } @@ -26,7 +26,7 @@ ethcore-devtools = { path = "../devtools" } libc = "0.2.7" vergen = "0.1" target_info = "0.1" -ethcore-bigint = { path = "bigint" } +ethcore-bigint = { path = "bigint", features = ["heapsizeof"] } parking_lot = "0.4" using_queue = { path = "using_queue" } table = { path = "table" } diff --git a/util/benches/bigint.rs b/util/benches/bigint.rs deleted file mode 100644 index 59377c511..000000000 --- a/util/benches/bigint.rs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2015-2017 Parity Technologies (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 . - -//! benchmarking for bigint -//! should be started with: -//! ```bash -//! multirust run nightly cargo bench -//! ``` - -#![feature(test)] -#![feature(asm)] - -extern crate test; -extern crate ethcore_util; - -use test::{Bencher, black_box}; -use ethcore_util::{U256, U512, U128}; - -#[bench] -fn u256_add(b: &mut Bencher) { - b.iter(|| { - let n = black_box(10000); - let zero = black_box(U256::zero()); - (0..n).fold(zero, |old, new| { old.overflowing_add(U256::from(black_box(new))).0 }) - }); -} - -#[bench] -fn u256_sub(b: &mut Bencher) { - b.iter(|| { - let n = black_box(10000); - let max = black_box(U256::max_value()); - (0..n).fold(max, |old, new| { old.overflowing_sub(U256::from(black_box(new))).0 }) - }); -} - -#[bench] -fn u512_sub(b: &mut Bencher) { - b.iter(|| { - let n = black_box(10000); - let max = black_box(U512::max_value()); - (0..n).fold( - max, - |old, new| { - let new = black_box(new); - let p = new % 2; - old.overflowing_sub(U512([p, p, p, p, p, p, p, new])).0 - } - ) - }); -} - -#[bench] -fn u512_add(b: &mut Bencher) { - b.iter(|| { - let n = black_box(10000); - let zero = black_box(U512::zero()); - (0..n).fold(zero, - |old, new| { - let new = black_box(new); - old.overflowing_add(U512([new, new, new, new, new, new, new, new])).0 - }) - }); -} - -#[bench] -fn u256_mul(b: &mut Bencher) { - b.iter(|| { - let n = black_box(10000); - let one = black_box(U256::one()); - (0..n).fold(one, |old, new| { old.overflowing_mul(U256::from(black_box(new))).0 }) - }); -} - - -#[bench] -fn u256_full_mul(b: &mut Bencher) { - b.iter(|| { - let n = black_box(10000); - let one = black_box(U256::one()); - (0..n).fold(one, - |old, new| { - let new = black_box(new); - let U512(ref u512words) = old.full_mul(U256([new, new, new, new])); - U256([u512words[0], u512words[2], u512words[2], u512words[3]]) - }) - }); -} - - -#[bench] -fn u128_mul(b: &mut Bencher) { - b.iter(|| { - let n = black_box(10000); - (0..n).fold(U128([12345u64, 0u64]), |old, new| { old.overflowing_mul(U128::from(new)).0 }) - }); -} - diff --git a/util/bigint/Cargo.toml b/util/bigint/Cargo.toml index c1225f72c..477925334 100644 --- a/util/bigint/Cargo.toml +++ b/util/bigint/Cargo.toml @@ -8,12 +8,13 @@ version = "0.1.3" authors = ["Parity Technologies "] [dependencies] -bigint = "2.0" -rustc-serialize = "0.3" -heapsize = "0.4" +bigint = "3.0" +rustc-hex = "1.0" rand = "0.3.12" libc = "0.2" +heapsize = { version = "0.4", optional = true } [features] x64asm_arithmetic=[] rust_arithmetic=[] +heapsizeof = ["heapsize", "bigint/heapsizeof"] diff --git a/util/bigint/src/hash.rs b/util/bigint/src/hash.rs index 942ffc6fb..748236285 100644 --- a/util/bigint/src/hash.rs +++ b/util/bigint/src/hash.rs @@ -8,15 +8,14 @@ //! General hash types, a fixed-size raw-data type used as the output of hash functions. -use std::{ops, fmt, cmp}; +use std::{ops, fmt, cmp, str}; use std::cmp::{min, Ordering}; use std::ops::{Deref, DerefMut, BitXor, BitAnd, BitOr, IndexMut, Index}; use std::hash::{Hash, Hasher, BuildHasherDefault}; use std::collections::{HashMap, HashSet}; -use std::str::FromStr; use rand::Rng; use rand::os::OsRng; -use rustc_serialize::hex::{FromHex, FromHexError}; +use rustc_hex::{FromHex, FromHexError}; use bigint::U256; use libc::{c_void, memcmp}; @@ -141,7 +140,7 @@ macro_rules! impl_hash { } } - impl FromStr for $from { + impl str::FromStr for $from { type Err = FromHexError; fn from_str(s: &str) -> Result<$from, FromHexError> { @@ -349,9 +348,9 @@ macro_rules! impl_hash { fn from(s: &'static str) -> $from { let s = clean_0x(s); if s.len() % 2 == 1 { - $from::from_str(&("0".to_owned() + s)).unwrap() + ("0".to_owned() + s).parse().unwrap() } else { - $from::from_str(s).unwrap() + s.parse().unwrap() } } } @@ -435,6 +434,7 @@ impl_hash!(H520, 65); impl_hash!(H1024, 128); impl_hash!(H2048, 256); +#[cfg(feature="heapsizeof")] known_heap_size!(0, H32, H64, H128, H160, H256, H264, H512, H520, H1024, H2048); // Specialized HashMap and HashSet diff --git a/util/bigint/src/lib.rs b/util/bigint/src/lib.rs index ed22bfcfb..7a85de6a1 100644 --- a/util/bigint/src/lib.rs +++ b/util/bigint/src/lib.rs @@ -11,10 +11,13 @@ #![cfg_attr(asm_available, feature(asm))] extern crate rand; -extern crate rustc_serialize; +extern crate rustc_hex; extern crate bigint; extern crate libc; -#[macro_use] extern crate heapsize; + +#[cfg(feature="heapsizeof")] +#[macro_use] +extern crate heapsize; pub mod hash; diff --git a/util/network/Cargo.toml b/util/network/Cargo.toml index edbbefd17..63b5ad50e 100644 --- a/util/network/Cargo.toml +++ b/util/network/Cargo.toml @@ -20,6 +20,7 @@ igd = "0.6" libc = "0.2.7" parking_lot = "0.4" ansi_term = "0.9" +rustc-hex = "1.0" rustc-serialize = "0.3" ethcore-io = { path = "../io" } ethcore-util = { path = ".." } diff --git a/util/network/src/discovery.rs b/util/network/src/discovery.rs index ad995188d..138ba23ba 100644 --- a/util/network/src/discovery.rs +++ b/util/network/src/discovery.rs @@ -559,7 +559,7 @@ mod tests { use node_table::{Node, NodeId, NodeEndpoint}; use std::str::FromStr; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use ethkey::{Random, Generator}; use AllowIP; diff --git a/util/network/src/handshake.rs b/util/network/src/handshake.rs index 9f6474c39..f5c4e118a 100644 --- a/util/network/src/handshake.rs +++ b/util/network/src/handshake.rs @@ -331,7 +331,7 @@ impl Handshake { #[cfg(test)] mod test { use std::sync::Arc; - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use super::*; use util::hash::H256; use io::*; diff --git a/util/network/src/lib.rs b/util/network/src/lib.rs index 8fae474ff..80654d503 100644 --- a/util/network/src/lib.rs +++ b/util/network/src/lib.rs @@ -66,6 +66,7 @@ extern crate crypto as rcrypto; extern crate rand; extern crate time; extern crate ansi_term; //TODO: remove this +extern crate rustc_hex; extern crate rustc_serialize; extern crate igd; extern crate libc; diff --git a/util/rlp/Cargo.toml b/util/rlp/Cargo.toml index b6ca67984..aa682e469 100644 --- a/util/rlp/Cargo.toml +++ b/util/rlp/Cargo.toml @@ -10,5 +10,5 @@ authors = ["Parity Technologies "] elastic-array = "0.9" ethcore-bigint = { path = "../bigint" } lazy_static = "0.2" -rustc-serialize = "0.3" +rustc-hex = "1.0" byteorder = "1.0" diff --git a/util/rlp/src/lib.rs b/util/rlp/src/lib.rs index e7e20b17d..f7596b2bc 100644 --- a/util/rlp/src/lib.rs +++ b/util/rlp/src/lib.rs @@ -41,7 +41,7 @@ extern crate byteorder; extern crate ethcore_bigint as bigint; extern crate elastic_array; -extern crate rustc_serialize; +extern crate rustc_hex; #[macro_use] extern crate lazy_static; diff --git a/util/rlp/src/rlpin.rs b/util/rlp/src/rlpin.rs index 918db4d0c..f4f3d3d58 100644 --- a/util/rlp/src/rlpin.rs +++ b/util/rlp/src/rlpin.rs @@ -273,7 +273,7 @@ impl<'a, 'view> Iterator for RlpIterator<'a, 'view> { #[test] fn break_it() { - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; use bigint::prelude::U256; let h: Vec = FromHex::from_hex("f84d0589010efbef67941f79b2a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap(); diff --git a/util/rlp/src/untrusted_rlp.rs b/util/rlp/src/untrusted_rlp.rs index bc47dee0f..c027438b0 100644 --- a/util/rlp/src/untrusted_rlp.rs +++ b/util/rlp/src/untrusted_rlp.rs @@ -8,7 +8,7 @@ use std::cell::Cell; use std::fmt; -use rustc_serialize::hex::ToHex; +use rustc_hex::ToHex; use impls::decode_usize; use {Decodable, DecoderError}; @@ -389,7 +389,7 @@ mod tests { #[test] fn test_rlp_display() { - use rustc_serialize::hex::FromHex; + use rustc_hex::FromHex; let data = "f84d0589010efbef67941f79b2a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470".from_hex().unwrap(); let rlp = UntrustedRlp::new(&data); assert_eq!(format!("{}", rlp), "[\"0x05\", \"0x010efbef67941f79b2\", \"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\", \"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470\"]"); diff --git a/util/src/error.rs b/util/src/error.rs index 5fcc6fd8f..4ed2fc9bd 100644 --- a/util/src/error.rs +++ b/util/src/error.rs @@ -16,7 +16,7 @@ //! General error types for use in ethcore. -use rustc_serialize::hex::FromHexError; +use rustc_hex::FromHexError; use rlp::DecoderError; use std::fmt; use hash::H256; diff --git a/util/src/lib.rs b/util/src/lib.rs index 5c988bbbc..c6a50f58b 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -87,7 +87,7 @@ //! cargo build --release //! ``` -extern crate rustc_serialize; +extern crate rustc_hex; extern crate rand; extern crate rocksdb; extern crate env_logger; diff --git a/util/src/standard.rs b/util/src/standard.rs index 6363eecd8..19521a5d5 100644 --- a/util/src/standard.rs +++ b/util/src/standard.rs @@ -39,11 +39,7 @@ pub use std::cmp::*; pub use std::sync::Arc; pub use std::collections::*; -pub use rustc_serialize::json::Json; -pub use rustc_serialize::base64::FromBase64; -pub use rustc_serialize::hex::{FromHex, FromHexError}; - pub use heapsize::HeapSizeOf; pub use itertools::Itertools; -pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; \ No newline at end of file +pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};