diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4a7ba9d44..6662caee6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,6 @@ variables: RUST_BACKTRACE: "1" RUSTFLAGS: "" CARGOFLAGS: "" - NIGHTLY: "nigtly" cache: key: "$CI_BUILD_STAGE/$CI_BUILD_REF_NAME" untracked: true @@ -232,9 +231,9 @@ linux-armv6: stage: build image: ethcore/rust-armv6:latest only: - - beta - - tags - - stable +# - beta +# - tags +# - stable - triggers script: - export CC=arm-linux-gnueabi-gcc @@ -305,41 +304,6 @@ linux-aarch64: - target/aarch64-unknown-linux-gnu/release/parity name: "aarch64-unknown-linux-gnu_parity" allow_failure: true -#linux-alpine: -# stage: build -# image: ethcore/rust-alpine:latest -# only: -# - beta -# - tags -# - stable -# - triggers -# script: -# - export HOST_CC=gcc -# - export HOST_CXX=g++ -# - cargo build --release $CARGOFLAGS -# - strip target/release/parity -# - md5sum target/release/parity > parity.md5 -# - sh scripts/deb-build.sh arm64 -# - cp target/aarch64-unknown-linux-gnu/release/parity deb/usr/bin/parity -# - export VER=$(grep -m 1 version Cargo.toml | awk '{print $3}' | tr -d '"' | tr -d "\n") -# - dpkg-deb -b deb "parity_"$VER"_arm64.deb" -# - md5sum "parity_"$VER"_arm64.deb" > "parity_"$VER"_arm64.deb.md5" -# - aws configure set aws_access_key_id $s3_key -# - aws configure set aws_secret_access_key $s3_secret -# - if [[ $CI_BUILD_REF_NAME =~ ^(master|beta|stable)$ ]]; then export S3_BUCKET=builds-parity-published; else export S3_BUCKET=builds-parity; fi -# - aws s3 rm --recursive s3://$S3_BUCKET/$CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu -# - aws s3api put-object --bucket $S3_BUCKET --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/parity --body target/aarch64-unknown-linux-gnu/release/parity -# - aws s3api put-object --bucket $S3_BUCKET --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/parity.md5 --body parity.md5 -# - aws s3api put-object --bucket $S3_BUCKET --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/"parity_"$VER"_arm64.deb" --body "parity_"$VER"_arm64.deb" -# - aws s3api put-object --bucket $S3_BUCKET --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/"parity_"$VER"_arm64.deb.md5" --body "parity_"$VER"_arm64.deb.md5" -# tags: -# - rust -# - rust-alpine -# artifacts: -# paths: -# - target/aarch64-unknown-linux-gnu/release/parity -# name: "aarch64-unknown-linux-gnu_parity" -# allow_failure: true darwin: stage: build only: diff --git a/Cargo.lock b/Cargo.lock index 62ef5ea11..caeb7a986 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,7 +3,7 @@ name = "parity" version = "1.5.0" dependencies = [ "ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "ctrlc 1.1.1 (git+https://github.com/ethcore/rust-ctrlc.git)", "daemonize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.6.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -146,15 +146,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clippy" -version = "0.0.96" +version = "0.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "clippy_lints 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy_lints 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "clippy_lints" -version = "0.0.96" +version = "0.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -224,7 +224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "elastic-array" version = "0.6.0" -source = "git+https://github.com/ethcore/elastic-array#70e4012e691b732c7c4cb04e9232799e6aa268bc" +source = "git+https://github.com/ethcore/elastic-array#346f1ba5982576dab9d0b8fa178b50e1db0a21cd" dependencies = [ "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -280,7 +280,7 @@ dependencies = [ "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "bloomchain 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.4.0", @@ -333,7 +333,7 @@ dependencies = [ name = "ethcore-dapps" version = "1.5.0" dependencies = [ - "clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-devtools 1.4.0", "ethcore-hash-fetch 1.5.0", @@ -490,7 +490,7 @@ dependencies = [ name = "ethcore-rpc" version = "1.5.0" dependencies = [ - "clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.4.0", "ethcore 1.5.0", "ethcore-devtools 1.4.0", @@ -520,7 +520,7 @@ dependencies = [ name = "ethcore-signer" version = "1.5.0" dependencies = [ - "clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-devtools 1.4.0", "ethcore-io 1.5.0", @@ -559,7 +559,7 @@ version = "1.5.0" dependencies = [ "ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.6.0 (git+https://github.com/ethcore/elastic-array)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)", @@ -649,7 +649,7 @@ dependencies = [ name = "ethsync" version = "1.5.0" dependencies = [ - "clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.5.0", "ethcore-io 1.5.0", @@ -1263,7 +1263,7 @@ dependencies = [ [[package]] name = "parity-ui-precompiled" version = "1.4.0" -source = "git+https://github.com/ethcore/js-precompiled.git#7cb42b0c636f76eb478c9270a1e507ac3c3ba434" +source = "git+https://github.com/ethcore/js-precompiled.git#da35604af4259da3abd7a12a4c4925906c78f746" dependencies = [ "parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2005,8 +2005,8 @@ dependencies = [ "checksum bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c129aff112dcc562970abb69e2508b40850dd24c274761bb50fb8a0067ba6c27" "checksum bytes 0.4.0-dev (git+https://github.com/carllerche/bytes)" = "" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" -"checksum clippy 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)" = "6eacf01b0aad84a0817703498f72d252df7c0faf6a5b86d0be4265f1829e459f" -"checksum clippy_lints 0.0.96 (registry+https://github.com/rust-lang/crates.io-index)" = "a49960c9aab544ce86b004dcb61620e8b898fea5fc0f697a028f460f48221ed6" +"checksum clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "5b4fabf979ddf6419a313c1c0ada4a5b95cfd2049c56e8418d622d27b4b6ff32" +"checksum clippy_lints 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "ce96ec05bfe018a0d5d43da115e54850ea2217981ff0f2e462780ab9d594651a" "checksum cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90266f45846f14a1e986c77d1e9c2626b8c342ed806fe60241ec38cc8697b245" "checksum crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "fb974f835e90390c5f9dfac00f05b06dc117299f5ea4e85fbc7bb443af4911cc" "checksum ctrlc 1.1.1 (git+https://github.com/ethcore/rust-ctrlc.git)" = "" diff --git a/Cargo.toml b/Cargo.toml index a8d7ba794..3808cce95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ ethcore-hash-fetch = { path = "ethcore/hash-fetch" } rlp = { path = "util/rlp" } ethcore-stratum = { path = "stratum" } ethcore-dapps = { path = "dapps", optional = true } -clippy = { version = "0.0.96", optional = true} +clippy = { version = "0.0.103", optional = true} [target.'cfg(windows)'.dependencies] winapi = "0.2" diff --git a/dapps/Cargo.toml b/dapps/Cargo.toml index 15e537820..6be30884a 100644 --- a/dapps/Cargo.toml +++ b/dapps/Cargo.toml @@ -34,7 +34,7 @@ ethcore-hash-fetch = { path = "../ethcore/hash-fetch" } fetch = { path = "../util/fetch" } parity-ui = { path = "./ui" } -clippy = { version = "0.0.96", optional = true} +clippy = { version = "0.0.103", optional = true} [build-dependencies] serde_codegen = { version = "0.8", optional = true } diff --git a/dapps/src/api/types.rs.in b/dapps/src/api/types.rs.in index 8bbefaa83..a95a0d446 100644 --- a/dapps/src/api/types.rs.in +++ b/dapps/src/api/types.rs.in @@ -17,6 +17,7 @@ use endpoint::EndpointInfo; #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct App { pub id: String, pub name: String, @@ -54,6 +55,7 @@ impl Into for App { } #[derive(Debug, PartialEq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct ApiError { pub code: String, pub title: String, diff --git a/db/Cargo.toml b/db/Cargo.toml index 27eadef4a..2b4a19892 100644 --- a/db/Cargo.toml +++ b/db/Cargo.toml @@ -11,7 +11,7 @@ build = "build.rs" ethcore-ipc-codegen = { path = "../ipc/codegen" } [dependencies] -clippy = { version = "0.0.96", optional = true} +clippy = { version = "0.0.103", optional = true} ethcore-devtools = { path = "../devtools" } ethcore-ipc = { path = "../ipc/rpc" } rocksdb = { git = "https://github.com/ethcore/rust-rocksdb" } diff --git a/docker/ubuntu-stable/Dockerfile b/docker/ubuntu-stable/Dockerfile index 2a8ee3da8..3fe36f32c 100644 --- a/docker/ubuntu-stable/Dockerfile +++ b/docker/ubuntu-stable/Dockerfile @@ -3,6 +3,7 @@ WORKDIR /build # install tools and dependencies RUN apt-get update && \ apt-get install -y \ + build-essential \ g++ \ curl \ git \ diff --git a/docker/ubuntu/Dockerfile b/docker/ubuntu/Dockerfile index 0c8e7d5db..e98c60daa 100644 --- a/docker/ubuntu/Dockerfile +++ b/docker/ubuntu/Dockerfile @@ -4,6 +4,7 @@ WORKDIR /build RUN apt-get update && \ apt-get install -y \ g++ \ + build-essential \ curl \ git \ file \ diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 48fce064a..bd87c422f 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -29,7 +29,7 @@ byteorder = "0.5" transient-hashmap = "0.1" linked-hash-map = "0.3.0" evmjit = { path = "../evmjit", optional = true } -clippy = { version = "0.0.96", optional = true} +clippy = { version = "0.0.103", optional = true} ethash = { path = "../ethash" } ethcore-util = { path = "../util" } ethcore-io = { path = "../util/io" } diff --git a/ethcore/src/account_db.rs b/ethcore/src/account_db.rs index 0761b7fba..63524a442 100644 --- a/ethcore/src/account_db.rs +++ b/ethcore/src/account_db.rs @@ -121,10 +121,6 @@ impl<'db> HashDB for AccountDB<'db>{ fn remove(&mut self, _key: &H256) { unimplemented!() } - - fn get_aux(&self, hash: &[u8]) -> Option { - self.db.get_aux(hash) - } } /// DB backend wrapper for Account trie @@ -197,18 +193,6 @@ impl<'db> HashDB for AccountDBMut<'db>{ let key = combine_key(&self.address_hash, key); self.db.remove(&key) } - - fn insert_aux(&mut self, hash: Vec, value: Vec) { - self.db.insert_aux(hash, value); - } - - fn get_aux(&self, hash: &[u8]) -> Option { - self.db.get_aux(hash) - } - - fn remove_aux(&mut self, hash: &[u8]) { - self.db.remove_aux(hash); - } } struct Wrapping<'db>(&'db HashDB); diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 54c2a7a02..bcbceb9aa 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -594,9 +594,9 @@ mod tests { use factory::Factories; use state_db::StateDB; use views::BlockView; - use util::Address; + use util::{Address, TrieFactory}; use util::hash::FixedHash; - + use util::trie::TrieSpec; use std::sync::Arc; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header @@ -637,7 +637,7 @@ mod tests { let genesis_header = spec.genesis_header(); let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let b = OpenBlock::new(&*spec.engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); @@ -653,7 +653,7 @@ mod tests { let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap() .close_and_lock().seal(engine, vec![]).unwrap(); @@ -662,7 +662,7 @@ mod tests { let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, Default::default()).unwrap(); assert_eq!(e.rlp_bytes(), orig_bytes); @@ -681,7 +681,7 @@ mod tests { let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let mut open_block = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let mut uncle1_header = Header::new(); @@ -697,7 +697,7 @@ mod tests { let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, Default::default()).unwrap(); let bytes = e.rlp_bytes(); diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 5ed51eee8..9a6ac7e7f 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -22,7 +22,7 @@ use std::time::{Instant}; use time::precise_time_ns; // util -use util::{Bytes, PerfTimer, Itertools, Mutex, RwLock}; +use util::{Bytes, PerfTimer, Itertools, Mutex, RwLock, Hashable}; use util::{journaldb, TrieFactory, Trie}; use util::{U256, H256, Address, H2048, Uint, FixedHash}; use util::trie::TrieSpec; @@ -172,9 +172,10 @@ impl Client { false => TrieSpec::Secure, }; + let trie_factory = TrieFactory::new(trie_spec); let journal_db = journaldb::new(db.clone(), config.pruning, ::db::COL_STATE); let mut state_db = StateDB::new(journal_db, config.state_cache_size); - if state_db.journal_db().is_empty() && try!(spec.ensure_db_good(&mut state_db)) { + if state_db.journal_db().is_empty() && try!(spec.ensure_db_good(&mut state_db, &trie_factory)) { let mut batch = DBTransaction::new(&db); try!(state_db.journal_under(&mut batch, 0, &spec.genesis_header().hash())); try!(db.write(batch).map_err(ClientError::Database)); @@ -216,7 +217,7 @@ impl Client { let factories = Factories { vm: EvmFactory::new(config.vm_type.clone(), config.jump_table_size), - trie: TrieFactory::new(trie_spec), + trie: trie_factory, accountdb: Default::default(), }; @@ -888,8 +889,8 @@ impl BlockChainClient for Client { } fn keep_alive(&self) { - let should_wake = match &*self.mode.lock() { - &Mode::Dark(..) | &Mode::Passive(..) => true, + let should_wake = match *self.mode.lock() { + Mode::Dark(..) | Mode::Passive(..) => true, _ => false, }; if should_wake { @@ -971,6 +972,10 @@ impl BlockChainClient for Client { self.state_at(id).map(|s| s.nonce(address)) } + fn storage_root(&self, address: &Address, id: BlockID) -> Option { + self.state_at(id).and_then(|s| s.storage_root(address)) + } + fn block_hash(&self, id: BlockID) -> Option { let chain = self.chain.read(); Self::block_hash(&chain, id) @@ -988,7 +993,7 @@ impl BlockChainClient for Client { self.state_at(id).map(|s| s.storage_at(address, position)) } - fn list_accounts(&self, id: BlockID) -> Option> { + fn list_accounts(&self, id: BlockID, after: Option<&Address>, count: u64) -> Option> { if !self.factories.trie.is_fat() { trace!(target: "fatdb", "list_accounts: Not a fat DB"); return None; @@ -1008,18 +1013,68 @@ impl BlockChainClient for Client { } }; - let iter = match trie.iter() { + let mut iter = match trie.iter() { Ok(iter) => iter, _ => return None, }; + if let Some(after) = after { + if let Err(e) = iter.seek(after) { + trace!(target: "fatdb", "list_accounts: Couldn't seek the DB: {:?}", e); + } + } + let accounts = iter.filter_map(|item| { item.ok().map(|(addr, _)| Address::from_slice(&addr)) - }).collect(); + }).take(count as usize).collect(); Some(accounts) } + fn list_storage(&self, id: BlockID, account: &Address, after: Option<&H256>, count: u64) -> Option> { + if !self.factories.trie.is_fat() { + trace!(target: "fatdb", "list_stroage: Not a fat DB"); + return None; + } + + let state = match self.state_at(id) { + Some(state) => state, + _ => return None, + }; + + let root = match state.storage_root(account) { + Some(root) => root, + _ => return None, + }; + + let (_, db) = state.drop(); + let account_db = self.factories.accountdb.readonly(db.as_hashdb(), account.sha3()); + let trie = match self.factories.trie.readonly(account_db.as_hashdb(), &root) { + Ok(trie) => trie, + _ => { + trace!(target: "fatdb", "list_storage: Couldn't open the DB"); + return None; + } + }; + + let mut iter = match trie.iter() { + Ok(iter) => iter, + _ => return None, + }; + + if let Some(after) = after { + if let Err(e) = iter.seek(after) { + trace!(target: "fatdb", "list_accounts: Couldn't seek the DB: {:?}", e); + } + } + + let keys = iter.filter_map(|item| { + item.ok().map(|(key, _)| H256::from_slice(&key)) + }).take(count as usize).collect(); + + Some(keys) + } + fn transaction(&self, id: TransactionID) -> Option { self.transaction_address(id).and_then(|address| self.chain.read().transaction(&address)) } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 6a9ab4b68..04e1c782d 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -333,7 +333,7 @@ impl MiningBlockChainClient for TestBlockChainClient { let genesis_header = self.spec.genesis_header(); let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - self.spec.ensure_db_good(&mut db).unwrap(); + self.spec.ensure_db_good(&mut db, &TrieFactory::default()).unwrap(); let last_hashes = vec![genesis_header.hash()]; let mut open_block = OpenBlock::new( @@ -385,6 +385,10 @@ impl BlockChainClient for TestBlockChainClient { } } + fn storage_root(&self, _address: &Address, _id: BlockID) -> Option { + None + } + fn latest_nonce(&self, address: &Address) -> U256 { self.nonce(address, BlockID::Latest).unwrap() } @@ -416,10 +420,13 @@ impl BlockChainClient for TestBlockChainClient { } } - fn list_accounts(&self, _id: BlockID) -> Option> { + fn list_accounts(&self, _id: BlockID, _after: Option<&Address>, _count: u64) -> Option> { None } + fn list_storage(&self, _id: BlockID, _account: &Address, _after: Option<&H256>, _count: u64) -> Option> { + None + } fn transaction(&self, _id: TransactionID) -> Option { None // Simple default. } diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 493f623f6..2a5c887ba 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -68,6 +68,10 @@ pub trait BlockChainClient : Sync + Send { /// May not fail on BlockID::Latest. fn nonce(&self, address: &Address, id: BlockID) -> Option; + /// Attempt to get address storage root at given block. + /// May not fail on BlockID::Latest. + fn storage_root(&self, address: &Address, id: BlockID) -> Option; + /// Get address nonce at the latest block's state. fn latest_nonce(&self, address: &Address) -> U256 { self.nonce(address, BlockID::Latest) @@ -114,7 +118,12 @@ pub trait BlockChainClient : Sync + Send { } /// Get a list of all accounts in the block `id`, if fat DB is in operation, otherwise `None`. - fn list_accounts(&self, id: BlockID) -> Option>; + /// If `after` is set the list starts with the following item. + fn list_accounts(&self, id: BlockID, after: Option<&Address>, count: u64) -> Option>; + + /// Get a list of all storage keys in the block `id`, if fat DB is in operation, otherwise `None`. + /// If `after` is set the list starts with the following item. + fn list_storage(&self, id: BlockID, account: &Address, after: Option<&H256>, count: u64) -> Option>; /// Get transaction with given hash. fn transaction(&self, id: TransactionID) -> Option; diff --git a/ethcore/src/engines/authority_round.rs b/ethcore/src/engines/authority_round.rs index 9987ffd10..ade14a28d 100644 --- a/ethcore/src/engines/authority_round.rs +++ b/ethcore/src/engines/authority_round.rs @@ -126,7 +126,7 @@ impl AuthorityRound { } fn step_proposer(&self, step: usize) -> &Address { - let ref p = self.our_params; + let p = &self.our_params; p.authorities.get(step % p.authority_n).expect("There are authority_n authorities; taking number modulo authority_n gives number in authority_n range; qed") } @@ -213,7 +213,7 @@ impl Engine for AuthorityRound { fn on_close_block(&self, _block: &mut ExecutedBlock) {} fn is_sealer(&self, author: &Address) -> Option { - let ref p = self.our_params; + let p = &self.our_params; Some(p.authorities.contains(author)) } @@ -281,7 +281,7 @@ impl Engine for AuthorityRound { let step = try!(header_step(header)); // Check if parent is from a previous step. - if step == try!(header_step(parent)) { + if step == try!(header_step(parent)) { trace!(target: "poa", "Multiple blocks proposed for step {}.", step); try!(Err(EngineError::DoubleVote(header.author().clone()))); } @@ -320,6 +320,7 @@ impl Engine for AuthorityRound { #[cfg(test)] mod tests { use util::*; + use util::trie::TrieSpec; use env_info::EnvInfo; use header::Header; use error::{Error, BlockError}; @@ -390,9 +391,9 @@ mod tests { engine.register_account_provider(Arc::new(tap)); let genesis_header = spec.genesis_header(); let mut db1 = get_temp_state_db().take(); - spec.ensure_db_good(&mut db1).unwrap(); + spec.ensure_db_good(&mut db1, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let mut db2 = get_temp_state_db().take(); - spec.ensure_db_good(&mut db2).unwrap(); + spec.ensure_db_good(&mut db2, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let b1 = OpenBlock::new(engine, Default::default(), false, db1, &genesis_header, last_hashes.clone(), addr1, (3141562.into(), 31415620.into()), vec![]).unwrap(); let b1 = b1.close_and_lock(); diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 7e0402dab..0b9040a11 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -190,6 +190,7 @@ impl Engine for BasicAuthority { #[cfg(test)] mod tests { use util::*; + use util::trie::TrieSpec; use block::*; use env_info::EnvInfo; use error::{BlockError, Error}; @@ -263,7 +264,7 @@ mod tests { let genesis_header = spec.genesis_header(); let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 7491d47f3..83335fb03 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -67,6 +67,7 @@ impl Engine for InstantSeal { #[cfg(test)] mod tests { use util::*; + use util::trie::TrieSpec; use tests::helpers::*; use spec::Spec; use header::Header; @@ -79,7 +80,7 @@ mod tests { let genesis_header = spec.genesis_header(); let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::default(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 40b18abbf..ca69ebff0 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -435,6 +435,7 @@ impl Header { #[cfg(test)] mod tests { use util::*; + use util::trie::TrieSpec; use block::*; use tests::helpers::*; use env_info::EnvInfo; @@ -451,7 +452,7 @@ mod tests { let genesis_header = spec.genesis_header(); let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close(); @@ -465,7 +466,7 @@ mod tests { let genesis_header = spec.genesis_header(); let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let last_hashes = Arc::new(vec![genesis_header.hash()]); let mut b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let mut uncle = Header::new(); diff --git a/ethcore/src/ethereum/mod.rs b/ethcore/src/ethereum/mod.rs index e236924ad..3916e5ccc 100644 --- a/ethcore/src/ethereum/mod.rs +++ b/ethcore/src/ethereum/mod.rs @@ -72,6 +72,7 @@ pub fn new_morden() -> Spec { load(include_bytes!("../../res/ethereum/morden.jso #[cfg(test)] mod tests { use util::*; + use util::trie::TrieSpec; use state::*; use super::*; use tests::helpers::*; @@ -84,7 +85,7 @@ mod tests { let genesis_header = spec.genesis_header(); let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - spec.ensure_db_good(&mut db).unwrap(); + spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let s = State::from_existing(db, genesis_header.state_root().clone(), engine.account_start_nonce(), Default::default()).unwrap(); assert_eq!(s.balance(&"0000000000000000000000000000000000000001".into()), 1u64.into()); assert_eq!(s.balance(&"0000000000000000000000000000000000000002".into()), 1u64.into()); diff --git a/ethcore/src/evm/interpreter/gasometer.rs b/ethcore/src/evm/interpreter/gasometer.rs index beaaadac5..886120880 100644 --- a/ethcore/src/evm/interpreter/gasometer.rs +++ b/ethcore/src/evm/interpreter/gasometer.rs @@ -197,19 +197,17 @@ impl Gasometer { let address = u256_to_address(stack.peek(1)); let is_value_transfer = !stack.peek(2).is_zero(); - if instruction == instructions::CALL { - if ( - !schedule.no_empty && !ext.exists(&address) - ) || ( - schedule.no_empty && is_value_transfer && !ext.exists_and_not_null(&address) - ) { - gas = overflowing!(gas.overflow_add(schedule.call_new_account_gas.into())); - } - }; + if instruction == instructions::CALL && ( + (!schedule.no_empty && !ext.exists(&address)) + || + (schedule.no_empty && is_value_transfer && !ext.exists_and_not_null(&address)) + ) { + gas = overflowing!(gas.overflow_add(schedule.call_new_account_gas.into())); + } if is_value_transfer { gas = overflowing!(gas.overflow_add(schedule.call_value_transfer_gas.into())); - }; + } let requested = *stack.peek(0); @@ -347,7 +345,7 @@ fn test_mem_gas_cost() { let result = gasometer.mem_gas_cost(&schedule, current_mem_size, &mem_size); // then - if let Ok(_) = result { + if result.is_ok() { assert!(false, "Should fail with OutOfGas"); } } diff --git a/ethcore/src/evm/tests.rs b/ethcore/src/evm/tests.rs index 7e69c0771..6cfc9a43e 100644 --- a/ethcore/src/evm/tests.rs +++ b/ethcore/src/evm/tests.rs @@ -95,7 +95,7 @@ impl Ext for FakeExt { } fn exists_and_not_null(&self, address: &Address) -> bool { - self.balances.get(address).map_or(false, |b| !b.is_zero()) + self.balances.get(address).map_or(false, |b| !b.is_zero()) } fn origin_balance(&self) -> U256 { @@ -103,7 +103,7 @@ impl Ext for FakeExt { } fn balance(&self, address: &Address) -> U256 { - *self.balances.get(address).unwrap() + self.balances[address] } fn blockhash(&self, number: &U256) -> H256 { diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 5da105e2f..1dfd987c1 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -445,7 +445,7 @@ impl<'a> Executive<'a> { trace!("exec::finalize: Refunding refund_value={}, sender={}\n", refund_value, sender); // Below: NoEmpty is safe since the sender must already be non-null to have sent this transaction - self.state.add_balance(&sender, &refund_value, CleanupMode::NoEmpty); + self.state.add_balance(&sender, &refund_value, CleanupMode::NoEmpty); trace!("exec::finalize: Compensating author: fees_value={}, author={}\n", fees_value, &self.info.author); self.state.add_balance(&self.info.author, &fees_value, substate.to_cleanup_mode(&schedule)); @@ -514,9 +514,11 @@ impl<'a> Executive<'a> { #[cfg(test)] #[allow(dead_code)] mod tests { + use std::sync::Arc; use ethkey::{Generator, Random}; use super::*; - use util::*; + use util::{H256, U256, U512, Address, Uint, FixedHash, FromHex, FromStr}; + use util::bytes::BytesRef; use action_params::{ActionParams, ActionValue}; use env_info::EnvInfo; use evm::{Factory, VMType}; diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index b1984dd43..032e15d31 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -151,7 +151,7 @@ impl GasPriceCalibrator { if Instant::now() >= self.next_calibration { let usd_per_tx = self.options.usd_per_tx; trace!(target: "miner", "Getting price info"); - if let Ok(_) = PriceInfo::get(move |price: PriceInfo| { + let price_info = PriceInfo::get(move |price: PriceInfo| { trace!(target: "miner", "Price info arrived: {:?}", price); let usd_per_eth = price.ethusd; let wei_per_usd: f32 = 1.0e18 / usd_per_eth; @@ -159,7 +159,9 @@ impl GasPriceCalibrator { let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx; info!(target: "miner", "Updated conversion rate to Ξ1 = {} ({} wei/gas)", Colour::White.bold().paint(format!("US${}", usd_per_eth)), Colour::Yellow.bold().paint(format!("{}", wei_per_gas))); set_price(U256::from(wei_per_gas as u64)); - }) { + }); + + if price_info.is_ok() { self.next_calibration = Instant::now() + self.options.recalibration_period; } else { warn!(target: "miner", "Unable to update Ether price."); @@ -1149,15 +1151,16 @@ impl MinerService for Miner { #[cfg(test)] mod tests { + use std::sync::Arc; use std::time::Duration; use super::super::{MinerService, PrioritizationStrategy}; use super::*; - use util::*; + use block::IsBlock; + use util::{U256, Uint, FromHex}; use ethkey::{Generator, Random}; use client::{BlockChainClient, TestBlockChainClient, EachBlockWith, TransactionImportResult}; use header::BlockNumber; use types::transaction::{Transaction, SignedTransaction, Action}; - use block::*; use spec::Spec; use tests::helpers::{generate_dummy_client}; diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index d99533877..41338ed2e 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -990,7 +990,7 @@ impl TransactionQueue { let mut update_last_nonce_to = None; { let by_nonce = self.future.by_address.row_mut(&address); - if let None = by_nonce { + if by_nonce.is_none() { return; } let mut by_nonce = by_nonce.expect("None is tested in early-exit condition above; qed"); @@ -1222,12 +1222,12 @@ mod test { use util::table::*; use util::*; use ethkey::{Random, Generator}; - use transaction::*; use error::{Error, TransactionError}; use super::*; use super::{TransactionSet, TransactionOrder, VerifiedTransaction}; use miner::local_transactions::LocalTransactionsList; use client::TransactionImportResult; + use transaction::{SignedTransaction, Transaction, Action}; fn unwrap_tx_err(err: Result) -> TransactionError { match err.unwrap_err() { diff --git a/ethcore/src/pod_account.rs b/ethcore/src/pod_account.rs index 0882b688c..92a78cebd 100644 --- a/ethcore/src/pod_account.rs +++ b/ethcore/src/pod_account.rs @@ -64,13 +64,13 @@ impl PodAccount { } /// Place additional data into given hash DB. - pub fn insert_additional(&self, db: &mut AccountDBMut) { + pub fn insert_additional(&self, db: &mut AccountDBMut, factory: &TrieFactory) { match self.code { Some(ref c) if !c.is_empty() => { db.insert(c); } _ => {} } let mut r = H256::new(); - let mut t = SecTrieDBMut::new(db, &mut r); + let mut t = factory.create(db, &mut r); for (k, v) in &self.storage { if let Err(e) = t.insert(k, &rlp::encode(&U256::from(&**v))) { warn!("Encountered potential DB corruption: {}", e); diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 3f63ac208..408941309 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -552,11 +552,11 @@ const POW_VERIFY_RATE: f32 = 0.02; pub fn verify_old_block(rng: &mut OsRng, header: &Header, engine: &Engine, chain: &BlockChain, body: Option<&[u8]>, always: bool) -> Result<(), ::error::Error> { if always || rng.gen::() <= POW_VERIFY_RATE { match chain.block_header(header.parent_hash()) { - Some(parent) => engine.verify_block_family(&header, &parent, body), - None => engine.verify_block_seal(&header), + Some(parent) => engine.verify_block_family(header, &parent, body), + None => engine.verify_block_seal(header), } } else { - engine.verify_block_basic(&header, body) + engine.verify_block_basic(header, body) } } diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index b789df222..1595966cb 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -244,13 +244,13 @@ impl Spec { } /// Ensure that the given state DB has the trie nodes in for the genesis state. - pub fn ensure_db_good(&self, db: &mut StateDB) -> Result> { + pub fn ensure_db_good(&self, db: &mut StateDB, factory: &TrieFactory) -> Result> { if !db.as_hashdb().contains(&self.state_root()) { trace!(target: "spec", "ensure_db_good: Fresh database? Cannot find state root {}", self.state_root()); let mut root = H256::new(); { - let mut t = SecTrieDBMut::new(db.as_hashdb_mut(), &mut root); + let mut t = factory.create(db.as_hashdb_mut(), &mut root); for (address, account) in self.genesis_state.get().iter() { try!(t.insert(&**address, &account.rlp())); } @@ -258,7 +258,7 @@ impl Spec { trace!(target: "spec", "ensure_db_good: Populated sec trie; root is {}", root); for (address, account) in self.genesis_state.get().iter() { db.note_non_null_account(address); - account.insert_additional(&mut AccountDBMut::new(db.as_hashdb_mut(), address)); + account.insert_additional(&mut AccountDBMut::new(db.as_hashdb_mut(), address), factory); } assert!(db.as_hashdb().contains(&self.state_root())); Ok(true) diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index 76061f6a0..bdcc92bd0 100644 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -314,11 +314,10 @@ impl Account { self.code_hash == SHA3_EMPTY } - #[cfg(test)] - /// return the storage root associated with this account or None if it has been altered via the overlay. + /// Return the storage root associated with this account or None if it has been altered via the overlay. pub fn storage_root(&self) -> Option<&H256> { if self.storage_is_clean() {Some(&self.storage_root)} else {None} } - /// return the storage overlay. + /// Return the storage overlay. pub fn storage_changes(&self) -> &HashMap { &self.storage_changes } /// Increment the nonce of the account by one. @@ -445,11 +444,10 @@ impl fmt::Debug for Account { #[cfg(test)] mod tests { - + use rlp::{UntrustedRlp, RlpType, View, Compressible}; use util::*; use super::*; use account_db::*; - use rlp::*; #[test] fn account_compress() { diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index 01a7e3b15..db7c318c6 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -369,6 +369,12 @@ impl State { |a| a.as_ref().map_or(self.account_start_nonce, |account| *account.nonce())) } + /// Get the storage root of account `a`. + pub fn storage_root(&self, a: &Address) -> Option { + self.ensure_cached(a, RequireCache::None, true, + |a| a.as_ref().and_then(|account| account.storage_root().cloned())) + } + /// Mutate storage of account `address` so that it is `value` for `key`. pub fn storage_at(&self, address: &Address, key: &H256) -> H256 { // Storage key search and update works like this: @@ -445,6 +451,7 @@ impl State { } /// Add `incr` to the balance of account `a`. + #[cfg_attr(feature="dev", allow(single_match))] pub fn add_balance(&mut self, a: &Address, incr: &U256, cleanup_mode: CleanupMode) { trace!(target: "state", "add_balance({}, {}): {}", a, incr, self.balance(a)); let is_value_transfer = !incr.is_zero(); diff --git a/ethcore/src/state/substate.rs b/ethcore/src/state/substate.rs index 853b0e422..c11f802a1 100644 --- a/ethcore/src/state/substate.rs +++ b/ethcore/src/state/substate.rs @@ -57,6 +57,7 @@ impl Substate { } /// Get the cleanup mode object from this. + #[cfg_attr(feature="dev", allow(wrong_self_convention))] pub fn to_cleanup_mode(&mut self, schedule: &Schedule) -> CleanupMode { match (schedule.no_empty, schedule.kill_empty) { (false, _) => CleanupMode::ForceCreate, diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index 0fe6bfa26..ac3b2c86b 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -397,6 +397,7 @@ impl StateDB { } /// Get cached code based on hash. + #[cfg_attr(feature="dev", allow(map_clone))] pub fn get_cached_code(&self, hash: &H256) -> Option>> { let mut cache = self.code_cache.lock(); diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 99b251d66..427082823 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -62,7 +62,7 @@ fn should_return_registrar() { &db_config ).unwrap(); let params = client.additional_params(); - let address = params.get("registrar").unwrap(); + let address = ¶ms["registrar"]; assert_eq!(address.len(), 40); assert!(U256::from_str(address).is_ok()); @@ -93,7 +93,7 @@ fn imports_good_block() { &db_config ).unwrap(); let good_block = get_good_dummy_block(); - if let Err(_) = client.import_block(good_block) { + if client.import_block(good_block).is_err() { panic!("error importing block being good by definition"); } client.flush_queue(); @@ -203,18 +203,18 @@ fn can_collect_garbage() { #[test] fn can_generate_gas_price_median() { - let client_result = generate_dummy_client_with_data(3, 1, &vec_into![1, 2, 3]); + let client_result = generate_dummy_client_with_data(3, 1, slice_into![1, 2, 3]); let client = client_result.reference(); assert_eq!(Some(U256::from(2)), client.gas_price_median(3)); - let client_result = generate_dummy_client_with_data(4, 1, &vec_into![1, 4, 3, 2]); + let client_result = generate_dummy_client_with_data(4, 1, slice_into![1, 4, 3, 2]); let client = client_result.reference(); assert_eq!(Some(U256::from(3)), client.gas_price_median(4)); } #[test] fn can_generate_gas_price_histogram() { - let client_result = generate_dummy_client_with_data(20, 1, &vec_into![6354,8593,6065,4842,7845,7002,689,4958,4250,6098,5804,4320,643,8895,2296,8589,7145,2000,2512,1408]); + let client_result = generate_dummy_client_with_data(20, 1, slice_into![6354,8593,6065,4842,7845,7002,689,4958,4250,6098,5804,4320,643,8895,2296,8589,7145,2000,2512,1408]); let client = client_result.reference(); let hist = client.gas_price_histogram(20, 5).unwrap(); @@ -224,7 +224,7 @@ fn can_generate_gas_price_histogram() { #[test] fn empty_gas_price_histogram() { - let client_result = generate_dummy_client_with_data(20, 0, &vec_into![]); + let client_result = generate_dummy_client_with_data(20, 0, slice_into![]); let client = client_result.reference(); assert!(client.gas_price_histogram(20, 5).is_none()); diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 212d8a7b3..e952fe27a 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -18,6 +18,7 @@ use ethkey::KeyPair; use io::*; use client::{BlockChainClient, Client, ClientConfig}; use util::*; +use util::trie::TrieSpec; use spec::*; use state_db::StateDB; use block::{OpenBlock, Drain}; @@ -157,7 +158,7 @@ pub fn generate_dummy_client_with_spec_and_data(get_test_spec: F, block_numbe let mut db_result = get_temp_state_db(); let mut db = db_result.take(); - test_spec.ensure_db_good(&mut db).unwrap(); + test_spec.ensure_db_good(&mut db, &TrieFactory::new(TrieSpec::Secure)).unwrap(); let genesis_header = test_spec.genesis_header(); let mut rolling_timestamp = 40; @@ -262,7 +263,7 @@ pub fn get_test_client_with_blocks(blocks: Vec) -> GuardedTempResult for ClientMode { Mode::Active => ClientMode::Active, } } -} \ No newline at end of file +} diff --git a/ethcore/src/types/transaction.rs b/ethcore/src/types/transaction.rs index 8289c5864..7dba4da53 100644 --- a/ethcore/src/types/transaction.rs +++ b/ethcore/src/types/transaction.rs @@ -73,7 +73,7 @@ pub struct Transaction { impl Transaction { /// Append object with a without signature into RLP stream pub fn rlp_append_unsigned_transaction(&self, s: &mut RlpStream, network_id: Option) { - s.begin_list(if let None = network_id { 6 } else { 9 }); + s.begin_list(if network_id.is_none() { 6 } else { 9 }); s.append(&self.nonce); s.append(&self.gas_price); s.append(&self.gas); @@ -210,7 +210,7 @@ pub struct SignedTransaction { /// Plain Transaction. unsigned: Transaction, /// The V field of the signature; the LS bit described which half of the curve our point falls - /// in. The MS bits describe which network this transaction is for. If 27/28, its for all networks. + /// in. The MS bits describe which network this transaction is for. If 27/28, its for all networks. v: u8, /// The R field of the signature; helps describe the point on the curve. r: U256, @@ -304,7 +304,7 @@ impl SignedTransaction { /// 0 if `v` would have been 27 under "Electrum" notation, 1 if 28 or 4 if invalid. pub fn standard_v(&self) -> u8 { match self.v { v if v == 27 || v == 28 || v > 36 => (v - 1) % 2, _ => 4 } } - /// The network ID, or `None` if this is a global transaction. + /// The network ID, or `None` if this is a global transaction. pub fn network_id(&self) -> Option { match self.v { v if v > 36 => Some((v - 35) / 2), @@ -461,7 +461,7 @@ fn should_agree_with_vitalik() { let signed: SignedTransaction = decode(&FromHex::from_hex(tx_data).unwrap()); signed.check_low_s().unwrap(); assert_eq!(signed.sender().unwrap(), address.into()); - flushln!("networkid: {:?}", signed.network_id()); + flushln!("networkid: {:?}", signed.network_id()); }; test_vector("f864808504a817c800825208943535353535353535353535353535353535353535808025a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116da0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", "0xf0f6f18bca1b28cd68e4357452947e021241e9ce") @@ -474,4 +474,4 @@ fn should_agree_with_vitalik() { test_vector("f867078504a817c807830290409435353535353535353535353535353535353535358201578025a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", "0xd37922162ab7cea97c97a87551ed02c9a38b7332") test_vector("f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", "0x9bddad43f934d313c2b79ca28a432dd2b7281029") test_vector("f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", "0x3c24d7329e92f84f08556ceb6df1cdb0104ca49f") -} \ No newline at end of file +} diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 47b2e16de..7e42e8881 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -29,6 +29,7 @@ use header::{BlockNumber, Header}; use rlp::{UntrustedRlp, View}; use transaction::SignedTransaction; use views::BlockView; +use time::get_time; /// Preprocessed block data gathered in `verify_block_unordered` call pub struct PreverifiedBlock { @@ -209,6 +210,10 @@ pub fn verify_header_params(header: &Header, engine: &Engine) -> Result<(), Erro if header.number() != 0 && header.extra_data().len() > maximum_extra_data_size { return Err(From::from(BlockError::ExtraDataOutOfBounds(OutOfBounds { min: None, max: Some(maximum_extra_data_size), found: header.extra_data().len() }))); } + let max_time = get_time().sec as u64 + 30; + if header.timestamp() > max_time { + return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: Some(max_time), min: None, found: header.timestamp() }))) + } Ok(()) } @@ -258,6 +263,7 @@ mod tests { use tests::helpers::*; use types::log_entry::{LogEntry, LocalizedLogEntry}; use rlp::View; + use time::get_time; fn check_ok(result: Result<(), Error>) { result.unwrap_or_else(|e| panic!("Block verification failed: {:?}", e)); @@ -271,6 +277,14 @@ mod tests { } } + fn check_fail_timestamp(result: Result<(), Error>) { + match result { + Err(Error::Block(BlockError::InvalidTimestamp(_))) => (), + Err(other) => panic!("Block verification failed.\nExpected: InvalidTimestamp\nGot: {:?}", other), + Ok(_) => panic!("Block verification failed.\nExpected: InvalidTimestamp\nGot: Ok"), + } + } + struct TestBlockChain { blocks: HashMap, numbers: HashMap, @@ -515,6 +529,14 @@ mod tests { check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc), InvalidTimestamp(OutOfBounds { max: None, min: Some(parent.timestamp() + 1), found: header.timestamp() })); + header = good.clone(); + header.set_timestamp(2450000000); + check_fail_timestamp(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine)); + + header = good.clone(); + header.set_timestamp(get_time().sec as u64 + 40); + check_fail_timestamp(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine)); + header = good.clone(); header.set_number(9); check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc), diff --git a/js/.babelrc b/js/.babelrc index 27c697885..2298d98c0 100644 --- a/js/.babelrc +++ b/js/.babelrc @@ -1,5 +1,8 @@ { - "presets": ["es2017", "es2016", "es2015", "stage-0", "react"], + "presets": [ + "es2017", "es2016", "es2015", + "stage-0", "react" + ], "plugins": [ "transform-runtime", "transform-decorators-legacy", @@ -10,6 +13,9 @@ "env": { "production": { "plugins": ["transform-react-remove-prop-types"] + }, + "development": { + "plugins": ["react-hot-loader/babel"] } } } diff --git a/js/.eslintrc.json b/js/.eslintrc.json index b649a1bea..198750580 100644 --- a/js/.eslintrc.json +++ b/js/.eslintrc.json @@ -15,6 +15,7 @@ "no-debugger": "error", "no-alert": "error", "jsx-quotes": ["error", "prefer-single"], - "react/jsx-curly-spacing": ["error", "always"] + "react/jsx-curly-spacing": ["error", "always"], + "object-property-newline": 0 } } diff --git a/js/.npmrc b/js/.npmrc new file mode 100644 index 000000000..3f7b4cf25 --- /dev/null +++ b/js/.npmrc @@ -0,0 +1 @@ +save-prefix='~' diff --git a/js/package.json b/js/package.json index 12b0cd9c6..408706016 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "parity.js", - "version": "0.2.74", + "version": "0.2.79", "main": "release/index.js", "jsnext:main": "src/index.js", "author": "Parity Team ", @@ -26,16 +26,16 @@ ], "scripts": { "build": "npm run build:lib && npm run build:dll && npm run build:app", - "build:app": "webpack --progress", - "build:lib": "webpack --config webpack.libraries --progress", - "build:dll": "webpack --config webpack.vendor --progress", + "build:app": "webpack --config webpack/app --progress", + "build:lib": "webpack --config webpack/libraries --progress", + "build:dll": "webpack --config webpack/vendor --progress", "ci:build": "npm run ci:build:lib && npm run ci:build:dll && npm run ci:build:app", - "ci:build:app": "NODE_ENV=production webpack", - "ci:build:lib": "NODE_ENV=production webpack --config webpack.libraries", - "ci:build:dll": "NODE_ENV=production webpack --config webpack.vendor", - "ci:build:npm": "NODE_ENV=production webpack --config webpack.npm", + "ci:build:app": "NODE_ENV=production webpack --config webpack/app", + "ci:build:lib": "NODE_ENV=production webpack --config webpack/libraries", + "ci:build:dll": "NODE_ENV=production webpack --config webpack/vendor", + "ci:build:npm": "NODE_ENV=production webpack --config webpack/npm", "start": "npm install && npm run build:lib && npm run build:dll && npm run start:app", - "start:app": "webpack-dev-server -d --history-api-fallback --open --hot --inline --progress --colors --port 3000", + "start:app": "node webpack/dev.server", "clean": "rm -rf ./build ./coverage", "coveralls": "npm run testCoverage && coveralls < coverage/lcov.info", "lint": "eslint --ignore-path .gitignore ./src/", @@ -47,127 +47,132 @@ "prepush": "npm run lint:cached" }, "devDependencies": { - "babel-cli": "^6.10.1", - "babel-core": "^6.10.4", - "babel-eslint": "^7.1.0", - "babel-loader": "^6.2.3", - "babel-plugin-lodash": "^3.2.2", - "babel-plugin-transform-class-properties": "^6.11.5", - "babel-plugin-transform-decorators-legacy": "^1.3.4", - "babel-plugin-transform-react-remove-prop-types": "^0.2.9", - "babel-plugin-transform-runtime": "^6.9.0", - "babel-polyfill": "^6.13.0", - "babel-preset-es2015": "^6.9.0", - "babel-preset-es2015-rollup": "^1.1.1", - "babel-preset-es2016": "^6.11.3", - "babel-preset-es2017": "^6.14.0", - "babel-preset-react": "^6.5.0", - "babel-preset-stage-0": "^6.5.0", - "babel-register": "6.9.0", - "babel-runtime": "^6.9.2", - "chai": "^3.5.0", + "babel-cli": "~6.18.0", + "babel-core": "~6.18.2", + "babel-eslint": "~7.1.0", + "babel-loader": "~6.2.3", + "babel-plugin-lodash": "~3.2.2", + "babel-plugin-transform-class-properties": "~6.19.0", + "babel-plugin-transform-decorators-legacy": "~1.3.4", + "babel-plugin-transform-react-remove-prop-types": "~0.2.9", + "babel-plugin-transform-runtime": "~6.15.0", + "babel-polyfill": "~6.16.0", + "babel-preset-es2015": "~6.18.0", + "babel-preset-es2015-rollup": "~1.2.0", + "babel-preset-es2016": "~6.16.0", + "babel-preset-es2017": "~6.16.0", + "babel-preset-react": "~6.16.0", + "babel-preset-stage-0": "~6.16.0", + "babel-register": "6.18.0", + "babel-runtime": "~6.18.0", + "chai": "~3.5.0", "chai-enzyme": "0.4.2", "cheerio": "0.20.0", - "copy-webpack-plugin": "^4.0.0", - "core-js": "^2.4.1", - "coveralls": "^2.11.11", - "css-loader": "^0.23.1", + "copy-webpack-plugin": "~4.0.0", + "core-js": "~2.4.1", + "coveralls": "~2.11.11", + "css-loader": "~0.26.0", "enzyme": "2.3.0", - "eslint": "^3.1.0", - "eslint-config-semistandard": "^6.0.2", - "eslint-config-standard": "^5.3.5", - "eslint-config-standard-react": "^3.0.0", - "eslint-plugin-promise": "^2.0.0", - "eslint-plugin-react": "^5.1.1", - "eslint-plugin-standard": "^2.0.0", - "extract-loader": "0.0.2", - "extract-text-webpack-plugin": "^1.0.1", - "file-loader": "^0.8.5", - "fs-extra": "^0.30.0", - "happypack": "^2.2.1", - "history": "^2.0.0", - "html-loader": "^0.4.4", - "husky": "^0.11.9", + "eslint": "~3.10.2", + "eslint-config-semistandard": "~7.0.0", + "eslint-config-standard": "~6.2.1", + "eslint-config-standard-react": "~4.2.0", + "eslint-plugin-promise": "~3.4.0", + "eslint-plugin-react": "~6.7.1", + "eslint-plugin-standard": "~2.0.0", + "express": "~4.14.0", + "extract-loader": "0.1.0", + "extract-text-webpack-plugin": "~2.0.0-beta.4", + "file-loader": "~0.9.0", + "fs-extra": "~0.30.0", + "happypack": "~3.0.0", + "history": "~2.0.0", + "html-loader": "~0.4.4", + "html-webpack-plugin": "~2.24.1", + "http-proxy-middleware": "~0.17.2", + "husky": "~0.11.9", "ignore-styles": "2.0.0", - "image-webpack-loader": "^1.8.0", - "istanbul": "^1.0.0-alpha.2", + "image-webpack-loader": "~3.0.0", + "istanbul": "~1.0.0-alpha.2", "jsdom": "9.2.1", - "json-loader": "^0.5.4", - "mocha": "^3.0.0-1", + "json-loader": "~0.5.4", + "mocha": "~3.0.0-1", "mock-local-storage": "1.0.2", - "mock-socket": "^3.0.1", - "nock": "^8.0.0", - "postcss-import": "^8.1.2", - "postcss-loader": "^0.8.1", - "postcss-nested": "^1.0.0", - "postcss-simple-vars": "^3.0.0", - "raw-loader": "^0.5.1", + "mock-socket": "~3.0.1", + "nock": "~8.0.0", + "postcss-import": "8.1.0", + "postcss-loader": "~1.1.1", + "postcss-nested": "~1.0.0", + "postcss-simple-vars": "~3.0.0", + "progress": "~1.1.8", + "raw-loader": "~0.5.1", "react-addons-perf": "~15.3.2", "react-addons-test-utils": "~15.3.2", - "react-copy-to-clipboard": "^4.2.3", "react-dom": "~15.3.2", - "react-hot-loader": "~1.3.0", - "rucksack-css": "^0.8.6", - "sinon": "^1.17.4", - "sinon-as-promised": "^4.0.2", - "sinon-chai": "^2.8.0", - "style-loader": "^0.13.0", - "url-loader": "^0.5.7", - "webpack": "^1.13.2", - "webpack-dev-server": "^1.15.2", + "react-hot-loader": "~3.0.0-beta.6", + "rucksack-css": "~0.8.6", + "sinon": "~1.17.4", + "sinon-as-promised": "~4.0.2", + "sinon-chai": "~2.8.0", + "style-loader": "~0.13.0", + "url-loader": "~0.5.7", + "webpack": "~2.1.0-beta.27", + "webpack-dev-middleware": "~1.8.4", "webpack-error-notification": "0.1.6", "webpack-hot-middleware": "~2.13.2", - "websocket": "^1.0.23" + "websocket": "~1.0.23" }, "dependencies": { - "bignumber.js": "^2.3.0", + "bignumber.js": "~2.3.0", "blockies": "0.0.2", - "brace": "^0.9.0", - "bytes": "^2.4.0", - "chart.js": "^2.3.0", - "es6-error": "^4.0.0", - "es6-promise": "^3.2.1", - "ethereumjs-tx": "^1.1.2", - "file-saver": "^1.3.3", - "format-json": "^1.0.3", - "format-number": "^2.0.1", - "geopattern": "^1.2.3", - "isomorphic-fetch": "^2.2.1", - "js-sha3": "^0.5.2", - "lodash": "^4.11.1", - "marked": "^0.3.6", + "brace": "~0.9.0", + "bytes": "~2.4.0", + "chart.js": "~2.3.0", + "es6-error": "~4.0.0", + "es6-promise": "~3.2.1", + "ethereumjs-tx": "~1.1.2", + "eventemitter3": "~2.0.2", + "file-saver": "~1.3.3", + "format-json": "~1.0.3", + "format-number": "~2.0.1", + "geopattern": "~1.2.3", + "isomorphic-fetch": "~2.2.1", + "js-sha3": "~0.5.2", + "lodash": "~4.11.1", + "marked": "~0.3.6", "material-ui": "0.16.1", - "material-ui-chip-input": "^0.8.0", - "mobx": "^2.6.1", - "mobx-react": "^3.5.8", - "mobx-react-devtools": "^4.2.9", - "moment": "^2.14.1", - "phoneformat.js": "^1.0.3", - "qs": "^6.3.0", + "material-ui-chip-input": "~0.8.0", + "mobx": "~2.6.1", + "mobx-react": "~3.5.8", + "mobx-react-devtools": "~4.2.9", + "moment": "~2.14.1", + "phoneformat.js": "~1.0.3", + "qs": "~6.3.0", "react": "~15.3.2", - "react-ace": "^4.0.0", + "react-ace": "~4.0.0", "react-addons-css-transition-group": "~15.3.2", - "react-chartjs-2": "^1.5.0", + "react-chartjs-2": "~1.5.0", + "react-copy-to-clipboard": "~4.2.3", "react-dom": "~15.3.2", - "react-dropzone": "^3.7.3", - "react-redux": "^4.4.5", - "react-router": "^2.6.1", - "react-router-redux": "^4.0.5", + "react-dropzone": "~3.7.3", + "react-redux": "~4.4.5", + "react-router": "~2.6.1", + "react-router-redux": "~4.0.5", "react-tap-event-plugin": "~1.0.0", - "react-tooltip": "^2.0.3", - "recharts": "^0.15.2", - "redux": "^3.5.2", - "redux-actions": "^0.10.1", - "redux-thunk": "^2.1.0", - "rlp": "^2.0.0", - "scryptsy": "^2.0.0", + "react-tooltip": "~2.0.3", + "recharts": "~0.15.2", + "redux": "~3.5.2", + "redux-actions": "~0.10.1", + "redux-thunk": "~2.1.0", + "rlp": "~2.0.0", + "scryptsy": "~2.0.0", "solc": "ngotchac/solc-js", - "store": "^1.3.20", - "utf8": "^2.1.1", - "valid-url": "^1.0.9", - "validator": "^5.7.0", - "web3": "^0.17.0-beta", - "whatwg-fetch": "^1.0.0", - "worker-loader": "^0.7.1" + "store": "~1.3.20", + "utf8": "~2.1.1", + "valid-url": "~1.0.9", + "validator": "~5.7.0", + "web3": "~0.17.0-beta", + "whatwg-fetch": "~1.0.0", + "worker-loader": "~0.7.1" } } diff --git a/js/src/3rdparty/sms-verification/index.js b/js/src/3rdparty/sms-verification/index.js index 9b113f364..c50b2331a 100644 --- a/js/src/3rdparty/sms-verification/index.js +++ b/js/src/3rdparty/sms-verification/index.js @@ -27,9 +27,10 @@ export const termsOfService = ( ); -export const postToServer = (query) => { +export const postToServer = (query, isTestnet = false) => { + const port = isTestnet ? 8443 : 443; query = stringify(query); - return fetch('https://sms-verification.parity.io/?' + query, { + return fetch(`https://sms-verification.parity.io:${port}/?` + query, { method: 'POST', mode: 'cors', cache: 'no-store' }) .then((res) => { diff --git a/js/src/api/contract/contract.js b/js/src/api/contract/contract.js index 6fe497551..c1ba8498d 100644 --- a/js/src/api/contract/contract.js +++ b/js/src/api/contract/contract.js @@ -15,16 +15,16 @@ // along with Parity. If not, see . import Abi from '../../abi'; -import Api from '../api'; -import { isInstanceOf } from '../util/types'; let nextSubscriptionId = 0; export default class Contract { constructor (api, abi) { - if (!isInstanceOf(api, Api)) { + if (!api) { throw new Error('API instance needs to be provided to Contract'); - } else if (!abi) { + } + + if (!abi) { throw new Error('ABI needs to be provided to Contract instance'); } diff --git a/js/src/api/format/input.js b/js/src/api/format/input.js index 80f3bc0eb..6d261c674 100644 --- a/js/src/api/format/input.js +++ b/js/src/api/format/input.js @@ -17,7 +17,7 @@ import BigNumber from 'bignumber.js'; import { isArray, isHex, isInstanceOf, isString } from '../util/types'; -import { padLeft } from '../util/format'; +import { padLeft, toHex } from '../util/format'; export function inAddress (address) { // TODO: address validation if we have upper-lower addresses @@ -100,15 +100,7 @@ export function inFilter (options) { } export function inHex (str) { - if (str && str.toString) { - str = str.toString(16); - } - - if (str && str.substr(0, 2) === '0x') { - return str.toLowerCase(); - } - - return `0x${(str || '').toLowerCase()}`; + return toHex(str); } export function inNumber10 (number) { diff --git a/js/src/api/util/format.js b/js/src/api/util/format.js index f1909748d..7f60357cd 100644 --- a/js/src/api/util/format.js +++ b/js/src/api/util/format.js @@ -15,7 +15,6 @@ // along with Parity. If not, see . import { range } from 'lodash'; -import { inHex } from '../format/input'; export function bytesToHex (bytes) { return '0x' + bytes.map((b) => ('0' + b.toString(16)).slice(-2)).join(''); @@ -38,11 +37,23 @@ export function asciiToHex (string) { } export function padRight (input, length) { - const value = inHex(input).substr(2, length * 2); + const value = toHex(input).substr(2, length * 2); return '0x' + value + range(length * 2 - value.length).map(() => '0').join(''); } export function padLeft (input, length) { - const value = inHex(input).substr(2, length * 2); + const value = toHex(input).substr(2, length * 2); return '0x' + range(length * 2 - value.length).map(() => '0').join('') + value; } + +export function toHex (str) { + if (str && str.toString) { + str = str.toString(16); + } + + if (str && str.substr(0, 2) === '0x') { + return str.toLowerCase(); + } + + return `0x${(str || '').toLowerCase()}`; +} diff --git a/js/src/contracts/abi/sms-verification.json b/js/src/contracts/abi/sms-verification.json index 400d22b44..d6852b182 100644 --- a/js/src/contracts/abi/sms-verification.json +++ b/js/src/contracts/abi/sms-verification.json @@ -1 +1 @@ -[{"constant":false,"inputs":[{"name":"_new","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"}],"name":"certify","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"request","outputs":[],"payable":true,"type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"},{"name":"_puzzle","type":"bytes32"}],"name":"puzzle","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"getAddress","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_new","type":"uint256"}],"name":"setFee","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"}],"name":"revoke","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_code","type":"bytes32"}],"name":"confirm","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"drain","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"delegate","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"getUint","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_new","type":"address"}],"name":"setDelegate","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"}],"name":"certified","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"fee","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"get","outputs":[{"name":"","type":"bytes32"}],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Requested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"},{"indexed":false,"name":"puzzle","type":"bytes32"}],"name":"Puzzled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Confirmed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Revoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"old","type":"address"},{"indexed":true,"name":"current","type":"address"}],"name":"NewOwner","type":"event"}] +[{"constant":false,"inputs":[{"name":"_new","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"}],"name":"certify","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"request","outputs":[],"payable":true,"type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"},{"name":"_puzzle","type":"bytes32"}],"name":"puzzle","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"getAddress","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_new","type":"uint256"}],"name":"setFee","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_who","type":"address"}],"name":"revoke","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_code","type":"bytes32"}],"name":"confirm","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"drain","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"delegate","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"getUint","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_new","type":"address"}],"name":"setDelegate","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"}],"name":"certified","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"fee","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"get","outputs":[{"name":"","type":"bytes32"}],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Requested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"},{"indexed":false,"name":"puzzle","type":"bytes32"}],"name":"Puzzled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Confirmed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Revoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"old","type":"address"},{"indexed":true,"name":"current","type":"address"}],"name":"NewOwner","type":"event"}] diff --git a/js/src/contracts/contracts.js b/js/src/contracts/contracts.js index 9d745762c..cefece7de 100644 --- a/js/src/contracts/contracts.js +++ b/js/src/contracts/contracts.js @@ -19,7 +19,7 @@ import Registry from './registry'; import SignatureReg from './signaturereg'; import TokenReg from './tokenreg'; import GithubHint from './githubhint'; -import smsVerification from './sms-verification'; +import * as smsVerification from './sms-verification'; let instance = null; diff --git a/js/src/contracts/sms-verification.js b/js/src/contracts/sms-verification.js index 2d32556ea..34a6bad76 100644 --- a/js/src/contracts/sms-verification.js +++ b/js/src/contracts/sms-verification.js @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +import subscribeToEvent from '../util/subscribe-to-event'; + export const checkIfVerified = (contract, account) => { return contract.instance.certified.call({}, [account]); }; @@ -50,3 +52,36 @@ export const checkIfRequested = (contract, account) => { }); }); }; + +const blockNumber = (api) => { + return new Promise((resolve, reject) => { + api.subscribe('eth_blockNumber', (err, block) => { + if (err) { + return reject(err); + } + resolve(block); + }) + .then((subscription) => { + api.unsubscribe(subscription); + }) + .catch(reject); + }); +}; + +export const awaitPuzzle = (api, contract, account) => { + return blockNumber(api) + .then((block) => { + return new Promise((resolve, reject) => { + const subscription = subscribeToEvent(contract, 'Puzzled', { + from: block.toNumber(), + filter: (log) => log.params.who.value === account + }); + subscription.once('error', reject); + subscription.once('log', subscription.unsubscribe); + subscription.once('log', resolve); + subscription.once('timeout', () => { + reject(new Error('Timed out waiting for the puzzle.')); + }); + }); + }); +}; diff --git a/js/src/dapps/basiccoin.html b/js/src/dapps/basiccoin.html deleted file mode 100644 index 52bc8bc57..000000000 --- a/js/src/dapps/basiccoin.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - Basic Token Deployment - - -
- - - - - - diff --git a/js/src/dapps/basiccoin.js b/js/src/dapps/basiccoin.js index e02990d14..a64afa0b9 100644 --- a/js/src/dapps/basiccoin.js +++ b/js/src/dapps/basiccoin.js @@ -32,7 +32,6 @@ const routerHistory = useRouterHistory(createHashHistory)({}); import '../../assets/fonts/Roboto/font.css'; import '../../assets/fonts/RobotoMono/font.css'; import './style.css'; -import './basiccoin.html'; ReactDOM.render( diff --git a/js/src/dapps/dappreg.html b/js/src/dapps/dappreg.html deleted file mode 100644 index 89c95c472..000000000 --- a/js/src/dapps/dappreg.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - Dapp Registry - - -
- - - - - - diff --git a/js/src/dapps/dappreg.js b/js/src/dapps/dappreg.js index 243576a34..9bd96f1a7 100644 --- a/js/src/dapps/dappreg.js +++ b/js/src/dapps/dappreg.js @@ -17,17 +17,14 @@ import React from 'react'; import ReactDOM from 'react-dom'; import injectTapEventPlugin from 'react-tap-event-plugin'; -import { useStrict } from 'mobx'; injectTapEventPlugin(); -useStrict(true); import Application from './dappreg/Application'; import '../../assets/fonts/Roboto/font.css'; import '../../assets/fonts/RobotoMono/font.css'; import './style.css'; -import './dappreg.html'; ReactDOM.render( , diff --git a/js/src/dapps/githubhint.html b/js/src/dapps/githubhint.html deleted file mode 100644 index 746c7f466..000000000 --- a/js/src/dapps/githubhint.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - GitHub Hint - - -
- - - - - diff --git a/js/src/dapps/githubhint.js b/js/src/dapps/githubhint.js index b73702990..ab807a44b 100644 --- a/js/src/dapps/githubhint.js +++ b/js/src/dapps/githubhint.js @@ -25,7 +25,6 @@ import Application from './githubhint/Application'; import '../../assets/fonts/Roboto/font.css'; import '../../assets/fonts/RobotoMono/font.css'; import './style.css'; -import './githubhint.html'; ReactDOM.render( , diff --git a/js/src/dapps/index.ejs b/js/src/dapps/index.ejs new file mode 100644 index 000000000..fa65c78bf --- /dev/null +++ b/js/src/dapps/index.ejs @@ -0,0 +1,37 @@ + + + + + + + <%= htmlWebpackPlugin.options.title %> + + + +
+
Loading
+
+ + <% if (!htmlWebpackPlugin.options.secure) { %> + + <% } %> + + diff --git a/js/src/dapps/index.js b/js/src/dapps/index.js new file mode 100644 index 000000000..9cba69701 --- /dev/null +++ b/js/src/dapps/index.js @@ -0,0 +1,25 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +module.exports = [ + { name: 'basiccoin', entry: 'basiccoin.js', title: 'Basic Token Deployment' }, + { name: 'dappreg', entry: 'dappreg.js', title: 'Dapp Registry' }, + { name: 'githubhint', entry: 'githubhint.js', title: 'GitHub Hint', secure: true }, + { name: 'localtx', entry: 'localtx.js', title: 'Local transactions Viewer', secure: true }, + { name: 'registry', entry: 'registry.js', title: 'Registry' }, + { name: 'signaturereg', entry: 'signaturereg.js', title: 'Method Signature Registry' }, + { name: 'tokenreg', entry: 'tokenreg.js', title: 'Token Registry' } +]; diff --git a/js/src/dapps/localtx.html b/js/src/dapps/localtx.html deleted file mode 100644 index d1e6fed05..000000000 --- a/js/src/dapps/localtx.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - Local transactions Viewer - - -
- - - - - - diff --git a/js/src/dapps/localtx.js b/js/src/dapps/localtx.js index 98561f33f..3e848ede9 100644 --- a/js/src/dapps/localtx.js +++ b/js/src/dapps/localtx.js @@ -25,7 +25,6 @@ import Application from './localtx/Application'; import '../../assets/fonts/Roboto/font.css'; import '../../assets/fonts/RobotoMono/font.css'; import './style.css'; -import './localtx.html'; ReactDOM.render( , diff --git a/js/src/dapps/localtx/Application/application.js b/js/src/dapps/localtx/Application/application.js index 7d220611f..da435b57d 100644 --- a/js/src/dapps/localtx/Application/application.js +++ b/js/src/dapps/localtx/Application/application.js @@ -158,18 +158,18 @@ export default class Application extends Component { { Transaction.renderHeader() } - { - transactions.map((tx, idx) => ( - - )) - } + { + transactions.map((tx, idx) => ( + + )) + } ); diff --git a/js/src/dapps/localtx/Transaction/transaction.js b/js/src/dapps/localtx/Transaction/transaction.js index 90981304b..17a45ecd6 100644 --- a/js/src/dapps/localtx/Transaction/transaction.js +++ b/js/src/dapps/localtx/Transaction/transaction.js @@ -83,7 +83,7 @@ class BaseTransaction extends Component { return ( - { noOfPropagations } ({ noOfPeers } peers) + { noOfPropagations } ({ noOfPeers } peers) ); } @@ -110,7 +110,7 @@ export class Transaction extends BaseTransaction { static renderHeader () { return ( - + Transaction @@ -129,8 +129,7 @@ export class Transaction extends BaseTransaction { # Propagated - - + ); } @@ -201,7 +200,7 @@ export class LocalTransaction extends BaseTransaction { static renderHeader () { return ( - + Transaction diff --git a/js/src/dapps/registry.html b/js/src/dapps/registry.html deleted file mode 100644 index ab399d1e3..000000000 --- a/js/src/dapps/registry.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - Token Registry - - -
- - - - - - diff --git a/js/src/dapps/registry.js b/js/src/dapps/registry.js index ebcff155a..d132da3d8 100644 --- a/js/src/dapps/registry.js +++ b/js/src/dapps/registry.js @@ -27,7 +27,6 @@ import Container from './registry/Container'; import '../../assets/fonts/Roboto/font.css'; import '../../assets/fonts/RobotoMono/font.css'; import './style.css'; -import './registry.html'; ReactDOM.render( diff --git a/js/src/dapps/signaturereg.html b/js/src/dapps/signaturereg.html deleted file mode 100644 index d050fe803..000000000 --- a/js/src/dapps/signaturereg.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - Method Signature Registry - - -
- - - - - - diff --git a/js/src/dapps/signaturereg.js b/js/src/dapps/signaturereg.js index 72ddd0ca7..d0d0cd423 100644 --- a/js/src/dapps/signaturereg.js +++ b/js/src/dapps/signaturereg.js @@ -25,7 +25,6 @@ import Application from './signaturereg/Application'; import '../../assets/fonts/Roboto/font.css'; import '../../assets/fonts/RobotoMono/font.css'; import './style.css'; -import './signaturereg.html'; ReactDOM.render( , diff --git a/js/src/dapps/signaturereg/Import/import.js b/js/src/dapps/signaturereg/Import/import.js index 90edf9415..55f7d9334 100644 --- a/js/src/dapps/signaturereg/Import/import.js +++ b/js/src/dapps/signaturereg/Import/import.js @@ -73,7 +73,7 @@ export default class Import extends Component { Provide the ABI (Contract Interface) in the space provided below. Only non-constant functions (names & types) will be imported, while constant functions and existing signatures will be ignored.
- +