Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19535333c9 | ||
|
|
5a1a7f6f45 | ||
|
|
148b20978c | ||
|
|
75b4bea521 | ||
|
|
69f53ffb2b | ||
|
|
eee0e6f295 | ||
|
|
822fa82056 | ||
|
|
83825befea | ||
|
|
4e93537e45 | ||
|
|
c0e32bac0e | ||
|
|
8b459b7bd3 | ||
|
|
51f830e922 | ||
|
|
6d0dfa6dab |
56
Cargo.lock
generated
56
Cargo.lock
generated
@@ -277,7 +277,7 @@ dependencies = [
|
||||
name = "common-types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethjson 0.1.0",
|
||||
"rlp 0.2.0",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -476,7 +476,7 @@ dependencies = [
|
||||
"ethcore-ipc-nano 1.7.0",
|
||||
"ethcore-logger 1.7.0",
|
||||
"ethcore-stratum 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethjson 0.1.0",
|
||||
"ethkey 0.2.0",
|
||||
"ethstore 0.1.0",
|
||||
@@ -545,7 +545,7 @@ name = "ethcore-ipc"
|
||||
version = "1.7.0"
|
||||
dependencies = [
|
||||
"ethcore-devtools 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"nanomsg 0.5.1 (git+https://github.com/paritytech/nanomsg.rs.git?branch=parity-1.7)",
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -594,7 +594,7 @@ dependencies = [
|
||||
"ethcore-ipc 1.7.0",
|
||||
"ethcore-ipc-codegen 1.7.0",
|
||||
"ethcore-ipc-nano 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nanomsg 0.5.1 (git+https://github.com/paritytech/nanomsg.rs.git?branch=parity-1.7)",
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -611,7 +611,7 @@ dependencies = [
|
||||
"ethcore-ipc 1.7.0",
|
||||
"ethcore-ipc-codegen 1.7.0",
|
||||
"ethcore-network 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"evm 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -650,7 +650,7 @@ dependencies = [
|
||||
"ethcore-devtools 1.7.0",
|
||||
"ethcore-io 1.7.0",
|
||||
"ethcore-logger 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethcrypto 0.1.0",
|
||||
"ethkey 0.2.0",
|
||||
"igd 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -681,7 +681,7 @@ dependencies = [
|
||||
"ethcore-ipc-codegen 1.7.0",
|
||||
"ethcore-ipc-nano 1.7.0",
|
||||
"ethcore-logger 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethcrypto 0.1.0",
|
||||
"ethkey 0.2.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -711,7 +711,7 @@ dependencies = [
|
||||
"ethcore-ipc-codegen 1.7.0",
|
||||
"ethcore-ipc-nano 1.7.0",
|
||||
"ethcore-logger 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-macros 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@@ -724,7 +724,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ethcore-util"
|
||||
version = "1.7.4"
|
||||
version = "1.7.6"
|
||||
dependencies = [
|
||||
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -774,7 +774,7 @@ name = "ethjson"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -855,7 +855,7 @@ dependencies = [
|
||||
"ethcore-ipc-nano 1.7.0",
|
||||
"ethcore-light 1.7.0",
|
||||
"ethcore-network 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethkey 0.2.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -874,7 +874,7 @@ dependencies = [
|
||||
"bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"common-types 0.1.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethjson 0.1.0",
|
||||
"evmjit 1.7.0",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -891,7 +891,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethjson 0.1.0",
|
||||
"evm 0.1.0",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1136,7 +1136,7 @@ version = "1.7.0"
|
||||
dependencies = [
|
||||
"ethcore-ipc 1.7.0",
|
||||
"ethcore-ipc-codegen 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -1530,7 +1530,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"native-contract-generator 0.1.0",
|
||||
]
|
||||
@@ -1735,7 +1735,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "parity"
|
||||
version = "1.7.4"
|
||||
version = "1.7.6"
|
||||
dependencies = [
|
||||
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_dirs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1755,7 +1755,7 @@ dependencies = [
|
||||
"ethcore-logger 1.7.0",
|
||||
"ethcore-secretstore 1.0.0",
|
||||
"ethcore-stratum 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethkey 0.2.0",
|
||||
"ethsync 1.7.0",
|
||||
"fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1801,7 +1801,7 @@ dependencies = [
|
||||
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-devtools 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@@ -1845,7 +1845,7 @@ name = "parity-hash-fetch"
|
||||
version = "1.7.0"
|
||||
dependencies = [
|
||||
"ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1863,7 +1863,7 @@ version = "1.7.0"
|
||||
dependencies = [
|
||||
"cid 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"jsonrpc-http-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"multihash 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1876,7 +1876,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore 1.7.0",
|
||||
"ethcore-io 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethkey 0.2.0",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
@@ -1906,7 +1906,7 @@ dependencies = [
|
||||
"ethcore-ipc 1.7.0",
|
||||
"ethcore-light 1.7.0",
|
||||
"ethcore-logger 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethcrypto 0.1.0",
|
||||
"ethjson 0.1.0",
|
||||
"ethkey 0.2.0",
|
||||
@@ -1948,7 +1948,7 @@ dependencies = [
|
||||
name = "parity-rpc-client"
|
||||
version = "1.4.0"
|
||||
dependencies = [
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-ws-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@@ -1984,7 +1984,7 @@ name = "parity-ui"
|
||||
version = "1.7.0"
|
||||
dependencies = [
|
||||
"parity-ui-dev 1.7.0",
|
||||
"parity-ui-precompiled 1.4.0 (git+https://github.com/paritytech/js-precompiled.git?branch=beta)",
|
||||
"parity-ui-precompiled 1.4.0 (git+https://github.com/paritytech/js-precompiled.git?branch=stable)",
|
||||
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -1998,7 +1998,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "parity-ui-precompiled"
|
||||
version = "1.4.0"
|
||||
source = "git+https://github.com/paritytech/js-precompiled.git?branch=beta#b24d0f6572640beb37924e709151fb124453c2e4"
|
||||
source = "git+https://github.com/paritytech/js-precompiled.git?branch=stable#1f3321388c17206628aeb22db00f0988b1510f50"
|
||||
dependencies = [
|
||||
"parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -2011,7 +2011,7 @@ dependencies = [
|
||||
"ethcore 1.7.0",
|
||||
"ethcore-ipc 1.7.0",
|
||||
"ethcore-ipc-codegen 1.7.0",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"ethsync 1.7.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-common-types 1.7.0",
|
||||
@@ -2367,7 +2367,7 @@ name = "rpc-cli"
|
||||
version = "1.4.0"
|
||||
dependencies = [
|
||||
"bigint 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-util 1.7.4",
|
||||
"ethcore-util 1.7.6",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-rpc 1.7.0",
|
||||
"parity-rpc-client 1.4.0",
|
||||
@@ -3250,7 +3250,7 @@ dependencies = [
|
||||
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
|
||||
"checksum parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1d06f6ee0fda786df3784a96ee3f0629f529b91cbfb7d142f6410e6bcd1ce2c"
|
||||
"checksum parity-tokio-ipc 0.1.5 (git+https://github.com/nikvolf/parity-tokio-ipc)" = "<none>"
|
||||
"checksum parity-ui-precompiled 1.4.0 (git+https://github.com/paritytech/js-precompiled.git?branch=beta)" = "<none>"
|
||||
"checksum parity-ui-precompiled 1.4.0 (git+https://github.com/paritytech/js-precompiled.git?branch=stable)" = "<none>"
|
||||
"checksum parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "51104c8b8da5cd0ebe0ab765dfab37bc1927b4a01a3d870b0fe09d9ee65e35ea"
|
||||
"checksum parity-wordlist 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52142d717754f7ff7ef0fc8da1bdce4f302dd576fb9bf8b727d6a5fdef33348d"
|
||||
"checksum parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aebb68eebde2c99f89592d925288600fde220177e46b5c9a91ca218d245aeedf"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
description = "Parity Ethereum client"
|
||||
name = "parity"
|
||||
version = "1.7.4"
|
||||
version = "1.7.6"
|
||||
license = "GPL-3.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
build = "build.rs"
|
||||
|
||||
@@ -12,7 +12,7 @@ rustc_version = "0.1"
|
||||
[dependencies]
|
||||
parity-ui-dev = { path = "../../js", optional = true }
|
||||
# This is managed by the js/scripts/release.sh script on CI - keep it in a single line
|
||||
parity-ui-precompiled = { git = "https://github.com/paritytech/js-precompiled.git", optional = true, branch = "beta" }
|
||||
parity-ui-precompiled = { git = "https://github.com/paritytech/js-precompiled.git", optional = true, branch = "stable" }
|
||||
|
||||
[features]
|
||||
no-precompiled-js = ["parity-ui-dev"]
|
||||
|
||||
@@ -565,7 +565,7 @@ impl<Cost: CostType> Interpreter<Cost> {
|
||||
let source_offset = stack.peek(1);
|
||||
let size = stack.peek(2);
|
||||
let return_data_len = U256::from(self.return_data.len());
|
||||
if source_offset.overflow_add(*size).0 > return_data_len {
|
||||
if source_offset.saturating_add(*size) > return_data_len {
|
||||
return Err(evm::Error::OutOfBounds);
|
||||
}
|
||||
}
|
||||
@@ -931,4 +931,25 @@ mod tests {
|
||||
assert_eq!(ext.calls.len(), 1);
|
||||
assert_eq!(gas_left, 248_212.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_overflow_returndata() {
|
||||
let code = "6001600160000360003e00".from_hex().unwrap();
|
||||
|
||||
let mut params = ActionParams::default();
|
||||
params.address = 5.into();
|
||||
params.gas = 300_000.into();
|
||||
params.gas_price = 1.into();
|
||||
params.code = Some(Arc::new(code));
|
||||
let mut ext = FakeExt::new_byzantium();
|
||||
ext.balances.insert(5.into(), 1_000_000_000.into());
|
||||
ext.tracing = true;
|
||||
|
||||
let err = {
|
||||
let mut vm = Factory::new(VMType::Interpreter, 1).create(params.gas);
|
||||
test_finalize(vm.exec(params, &mut ext)).err().unwrap()
|
||||
};
|
||||
|
||||
assert_eq!(err, ::vm::Error::OutOfBounds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,11 @@ impl Pricer for ModexpPricer {
|
||||
|
||||
let adjusted_exp_len = Self::adjusted_exp_len(exp_len, exp_low);
|
||||
|
||||
(Self::mult_complexity(m) * max(adjusted_exp_len, 1) / self.divisor as u64).into()
|
||||
let (gas, overflow) = Self::mult_complexity(m).overflowing_mul(max(adjusted_exp_len, 1));
|
||||
if overflow {
|
||||
return U256::max_value();
|
||||
}
|
||||
(gas / self.divisor as u64).into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -711,6 +715,14 @@ mod tests {
|
||||
activate_at: 0,
|
||||
};
|
||||
|
||||
// test for potential gas cost multiplication overflow
|
||||
{
|
||||
let input = FromHex::from_hex("0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000003b27bafd00000000000000000000000000000000000000000000000000000000503c8ac3").unwrap();
|
||||
let expected_cost = U256::max_value();
|
||||
assert_eq!(f.cost(&input[..]), expected_cost.into());
|
||||
}
|
||||
|
||||
|
||||
// test for potential exp len overflow
|
||||
{
|
||||
let input = FromHex::from_hex("\
|
||||
|
||||
@@ -970,9 +970,11 @@ impl Client {
|
||||
|
||||
/// Tick the client.
|
||||
// TODO: manage by real events.
|
||||
pub fn tick(&self) {
|
||||
pub fn tick(&self, prevent_sleep: bool) {
|
||||
self.check_garbage();
|
||||
self.check_snooze();
|
||||
if !prevent_sleep {
|
||||
self.check_snooze();
|
||||
}
|
||||
}
|
||||
|
||||
fn check_garbage(&self) {
|
||||
@@ -1079,7 +1081,7 @@ impl Client {
|
||||
if !self.liveness.load(AtomicOrdering::Relaxed) {
|
||||
self.liveness.store(true, AtomicOrdering::Relaxed);
|
||||
self.notify(|n| n.start());
|
||||
trace!(target: "mode", "wake_up: Waking.");
|
||||
info!(target: "mode", "wake_up: Waking.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1089,11 +1091,11 @@ impl Client {
|
||||
if self.queue_info().total_queue_size() <= MAX_QUEUE_SIZE_TO_SLEEP_ON {
|
||||
self.liveness.store(false, AtomicOrdering::Relaxed);
|
||||
self.notify(|n| n.stop());
|
||||
trace!(target: "mode", "sleep: Sleeping.");
|
||||
info!(target: "mode", "sleep: Sleeping.");
|
||||
} else {
|
||||
trace!(target: "mode", "sleep: Cannot sleep - syncing ongoing.");
|
||||
info!(target: "mode", "sleep: Cannot sleep - syncing ongoing.");
|
||||
// TODO: Consider uncommenting.
|
||||
//*self.last_activity.lock() = Some(Instant::now());
|
||||
//(*self.sleep_state.lock()).last_activity = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use error::*;
|
||||
use client::{Client, ClientConfig, ChainNotify};
|
||||
use miner::Miner;
|
||||
|
||||
use snapshot::ManifestData;
|
||||
use snapshot::{ManifestData, RestorationStatus};
|
||||
use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
@@ -175,7 +175,11 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
|
||||
|
||||
fn timeout(&self, _io: &IoContext<ClientIoMessage>, timer: TimerToken) {
|
||||
match timer {
|
||||
CLIENT_TICK_TIMER => self.client.tick(),
|
||||
CLIENT_TICK_TIMER => {
|
||||
use snapshot::SnapshotService;
|
||||
let snapshot_restoration = if let RestorationStatus::Ongoing{..} = self.snapshot.status() { true } else { false };
|
||||
self.client.tick(snapshot_restoration)
|
||||
},
|
||||
SNAPSHOT_TICK_TIMER => self.snapshot.tick(),
|
||||
_ => warn!("IO service triggered unregistered timer '{}'", timer),
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ fn imports_block_sequence() {
|
||||
#[test]
|
||||
fn can_collect_garbage() {
|
||||
let client = generate_dummy_client(100);
|
||||
client.tick();
|
||||
client.tick(true);
|
||||
assert!(client.blockchain_cache_info().blocks < 100 * 1024);
|
||||
}
|
||||
|
||||
|
||||
12
js/package-lock.json
generated
12
js/package-lock.json
generated
@@ -428,7 +428,7 @@
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||
"integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "1.0.0",
|
||||
@@ -810,7 +810,7 @@
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||
"integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "1.0.0",
|
||||
@@ -4414,7 +4414,7 @@
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||
"integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "1.0.0",
|
||||
@@ -11958,7 +11958,7 @@
|
||||
"string-width": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
|
||||
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
|
||||
"integrity": "sha1-q5Pyeo3BPSjKyBXEYhQ6bZASrp4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-fullwidth-code-point": "2.0.0",
|
||||
@@ -12923,7 +12923,7 @@
|
||||
"async": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.5.0.tgz",
|
||||
"integrity": "sha512-e+lJAJeNWuPCNyxZKOBdaJGyLGHugXVQtrAwtuAe2vhxTYxFTKE73p8JuTmdH0qdQZtDvI4dhJwjZc5zsfIsYw==",
|
||||
"integrity": "sha1-hDGQ/WtzV6C54clW7d3V7IRitU0=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"lodash": "4.17.2"
|
||||
@@ -13328,7 +13328,7 @@
|
||||
"commander": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
|
||||
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ=="
|
||||
"integrity": "sha1-FXFS/R56bI2YpbcVzzdt+SgARWM="
|
||||
},
|
||||
"detect-indent": {
|
||||
"version": "5.0.0",
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
// test script 10
|
||||
// test script 11
|
||||
// beta trigger 01
|
||||
|
||||
@@ -29,3 +29,4 @@ export signaturereg from './signaturereg.json';
|
||||
export smsverification from './sms-verification.json';
|
||||
export tokenreg from './tokenreg.json';
|
||||
export foundationWallet from './foundation-multisig-wallet.json';
|
||||
export vouchfor from './vouchfor.json';
|
||||
|
||||
1
js/src/contracts/abi/vouchfor.json
Normal file
1
js/src/contracts/abi/vouchfor.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"constant":true,"inputs":[],"name":"certifier","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_what","type":"bytes32"}],"name":"vouch","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_what","type":"bytes32"},{"name":"_index","type":"uint256"}],"name":"vouched","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_what","type":"bytes32"},{"name":"_index","type":"uint256"}],"name":"unvouch","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"},{"name":"","type":"uint256"}],"name":"vouchers","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_certifier","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"who","type":"address"},{"indexed":false,"name":"what","type":"bytes32"}],"name":"Vouched","type":"event"}]
|
||||
@@ -105,7 +105,7 @@ export default class BadgeReg {
|
||||
]);
|
||||
})
|
||||
.then(([ title, icon ]) => {
|
||||
title = bytesToHex(title);
|
||||
title = bytesToHex(title).replace(/(00)+$/, '');
|
||||
title = title === ZERO32 ? null : hexToAscii(title);
|
||||
|
||||
if (bytesToHex(icon) === ZERO32) {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
left: 0;
|
||||
opacity: 1;
|
||||
padding: 1.5em;
|
||||
cursor: pointer;
|
||||
position: fixed;
|
||||
right: 50%;
|
||||
z-index: 100;
|
||||
|
||||
@@ -43,8 +43,13 @@ export default class Application extends Component {
|
||||
contract: PropTypes.object
|
||||
};
|
||||
|
||||
state = {
|
||||
hideWarning: false
|
||||
};
|
||||
|
||||
render () {
|
||||
const { isLoading, contract } = this.props;
|
||||
const { hideWarning } = this.state;
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -62,9 +67,15 @@ export default class Application extends Component {
|
||||
<Actions />
|
||||
|
||||
<Tokens />
|
||||
<div className={ styles.warning }>
|
||||
WARNING: The token registry is experimental. Please ensure that you understand the steps, risks, benefits & consequences of registering a token before doing so. A non-refundable fee of { api.util.fromWei(contract.fee).toFormat(3) }<small>ETH</small> is required for all registrations.
|
||||
</div>
|
||||
{
|
||||
hideWarning
|
||||
? null
|
||||
: (
|
||||
<div className={ styles.warning } onClick={ this.handleHideWarning }>
|
||||
WARNING: The token registry is experimental. Please ensure that you understand the steps, risks, benefits & consequences of registering a token before doing so. A non-refundable fee of { api.util.fromWei(contract.fee).toFormat(3) }<small>ETH</small> is required for all registrations.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -74,4 +85,8 @@ export default class Application extends Component {
|
||||
muiTheme
|
||||
};
|
||||
}
|
||||
|
||||
handleHideWarning = () => {
|
||||
this.setState({ hideWarning: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
export const fetchCertifiers = () => ({
|
||||
type: 'fetchCertifiers'
|
||||
});
|
||||
|
||||
export const fetchCertifications = (address) => ({
|
||||
type: 'fetchCertifications', address
|
||||
});
|
||||
|
||||
export const addCertification = (address, id, name, title, icon) => ({
|
||||
type: 'addCertification', address, id, name, title, icon
|
||||
});
|
||||
|
||||
343
js/src/redux/providers/certifications/certifiers.monitor.js
Normal file
343
js/src/redux/providers/certifications/certifiers.monitor.js
Normal file
@@ -0,0 +1,343 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { range } from 'lodash';
|
||||
|
||||
import { addCertification, removeCertification } from './actions';
|
||||
|
||||
import { getLogger, LOG_KEYS } from '~/config';
|
||||
import Contract from '~/api/contract';
|
||||
import { bytesToHex, hexToAscii } from '~/api/util/format';
|
||||
import Contracts from '~/contracts';
|
||||
import CertifierABI from '~/contracts/abi/certifier.json';
|
||||
import { querier } from './enhanced-querier';
|
||||
|
||||
const log = getLogger(LOG_KEYS.CertificationsMiddleware);
|
||||
|
||||
let self = null;
|
||||
|
||||
export default class CertifiersMonitor {
|
||||
constructor (api, store) {
|
||||
this._api = api;
|
||||
this._name = 'Certifiers';
|
||||
this._store = store;
|
||||
|
||||
this._contract = new Contract(this.api, CertifierABI);
|
||||
this._contractEvents = [ 'Confirmed', 'Revoked' ]
|
||||
.map((name) => this.contract.events.find((e) => e.name === name));
|
||||
|
||||
this.certifiers = {};
|
||||
this.fetchedAccounts = {};
|
||||
|
||||
this.load();
|
||||
}
|
||||
|
||||
static get () {
|
||||
if (self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
self = new CertifiersMonitor();
|
||||
return self;
|
||||
}
|
||||
|
||||
static init (api, store) {
|
||||
if (!self) {
|
||||
self = new CertifiersMonitor(api, store);
|
||||
}
|
||||
}
|
||||
|
||||
get api () {
|
||||
return this._api;
|
||||
}
|
||||
|
||||
get contract () {
|
||||
return this._contract;
|
||||
}
|
||||
|
||||
get contractEvents () {
|
||||
return this._contractEvents;
|
||||
}
|
||||
|
||||
get name () {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
get store () {
|
||||
return this._store;
|
||||
}
|
||||
|
||||
get registry () {
|
||||
return this._registry;
|
||||
}
|
||||
|
||||
get registryEvents () {
|
||||
return this._registryEvents;
|
||||
}
|
||||
|
||||
checkFilters () {
|
||||
this.checkCertifiersFilter();
|
||||
this.checkRegistryFilter();
|
||||
}
|
||||
|
||||
checkCertifiersFilter () {
|
||||
if (!this.certifiersFilter) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.api.eth.getFilterChanges(this.certifiersFilter)
|
||||
.then((logs) => {
|
||||
if (logs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const parsedLogs = this.contract.parseEventLogs(logs).filter((log) => log.params);
|
||||
|
||||
log.debug('received certifiers logs', parsedLogs);
|
||||
|
||||
const promises = parsedLogs.map((log) => {
|
||||
const account = log.params.who.value;
|
||||
const certifier = Object.values(this.certifiers).find((c) => c.address === log.address);
|
||||
|
||||
if (!certifier) {
|
||||
log.warn('could not find the certifier', { certifiers: this.certifiers, log });
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return this.fetchAccount(account, { ids: [ certifier.id ] });
|
||||
});
|
||||
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
checkRegistryFilter () {
|
||||
if (!this.registryFilter) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.api.eth.getFilterChanges(this.registryFilter)
|
||||
.then((logs) => {
|
||||
if (logs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const parsedLogs = this.contract.parseEventLogs(logs).filter((log) => log.params);
|
||||
const indexes = parsedLogs.map((log) => log.params && log.params.id.value.toNumber());
|
||||
|
||||
log.debug('received registry logs', parsedLogs);
|
||||
return this.fetchElements(indexes);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial load of the Monitor.
|
||||
* Fetch the contract from the Registry, and
|
||||
* load the elements addresses
|
||||
*/
|
||||
load () {
|
||||
const badgeReg = Contracts.get().badgeReg;
|
||||
|
||||
log.debug(`loading the ${this.name} monitor...`);
|
||||
return badgeReg.getContract()
|
||||
.then((registryContract) => {
|
||||
this._registry = registryContract;
|
||||
this._registryEvents = [ 'Registered', 'Unregistered', 'MetaChanged', 'AddressChanged' ]
|
||||
.map((name) => this.registry.events.find((e) => e.name === name));
|
||||
|
||||
return this.registry.instance.badgeCount.call({});
|
||||
})
|
||||
.then((count) => {
|
||||
log.debug(`found ${count.toFormat()} registered contracts for ${this.name}`);
|
||||
return this.fetchElements(range(count.toNumber()));
|
||||
})
|
||||
.then(() => {
|
||||
return this.setRegistryFilter();
|
||||
})
|
||||
.then(() => {
|
||||
// Listen for new blocks
|
||||
return this.api.subscribe('eth_blockNumber', (err) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.checkFilters();
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
log.debug(`loaded the ${this.name} monitor!`, this.certifiers);
|
||||
})
|
||||
.catch((error) => {
|
||||
log.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the given registered element
|
||||
*/
|
||||
fetchElements (indexes) {
|
||||
const badgeReg = Contracts.get().badgeReg;
|
||||
const { instance } = this.registry;
|
||||
|
||||
const sorted = indexes.sort();
|
||||
const from = sorted[0];
|
||||
const last = sorted[sorted.length - 1];
|
||||
const limit = last - from + 1;
|
||||
|
||||
// Fetch the address, name and owner in one batch
|
||||
return querier(this.api, { address: instance.address, from, limit }, instance.badge)
|
||||
.then((results) => {
|
||||
const certifiers = results
|
||||
.map(([ address, name, owner ], index) => ({
|
||||
address, owner,
|
||||
id: index + from,
|
||||
name: hexToAscii(bytesToHex(name).replace(/(00)+$/, ''))
|
||||
}))
|
||||
.reduce((certifiers, certifier) => {
|
||||
const { id } = certifier;
|
||||
|
||||
if (!/^(0x)?0+$/.test(certifier.address)) {
|
||||
certifiers[id] = certifier;
|
||||
} else if (certifiers[id]) {
|
||||
delete certifiers[id];
|
||||
}
|
||||
|
||||
return certifiers;
|
||||
}, {});
|
||||
|
||||
// Fetch the meta-data in serie
|
||||
return Object.values(certifiers).reduce((promise, certifier) => {
|
||||
return promise.then(() => badgeReg.fetchMeta(certifier.id))
|
||||
.then((meta) => {
|
||||
this.certifiers[certifier.id] = { ...certifier, ...meta };
|
||||
});
|
||||
}, Promise.resolve());
|
||||
})
|
||||
.then(() => log.debug('fetched certifiers', { certifiers: this.certifiers }))
|
||||
// Fetch the know accounts in case it's an update of the certifiers
|
||||
.then(() => this.fetchAccounts(Object.keys(this.fetchedAccounts), { ids: indexes, force: true }));
|
||||
}
|
||||
|
||||
fetchAccounts (addresses, { ids = null, force = false } = {}) {
|
||||
const newAddresses = force
|
||||
? addresses
|
||||
: addresses.filter((address) => !this.fetchedAccounts[address]);
|
||||
|
||||
if (newAddresses.length === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
log.debug(`fetching values for "${addresses.join(' ; ')}" in ${this.name}...`);
|
||||
return newAddresses
|
||||
.reduce((promise, address) => {
|
||||
return promise.then(() => this.fetchAccount(address, { ids }));
|
||||
}, Promise.resolve())
|
||||
.then(() => {
|
||||
log.debug(`fetched values for "${addresses.join(' ; ')}" in ${this.name}!`);
|
||||
})
|
||||
.then(() => this.setCertifiersFilter());
|
||||
}
|
||||
|
||||
fetchAccount (address, { ids = null } = {}) {
|
||||
let certifiers = Object.values(this.certifiers);
|
||||
|
||||
// Only fetch values for the givens ids, if any
|
||||
if (ids) {
|
||||
certifiers = certifiers.filter((certifier) => ids.includes(certifier.id));
|
||||
}
|
||||
|
||||
certifiers
|
||||
.reduce((promise, certifier) => {
|
||||
return promise
|
||||
.then(() => {
|
||||
return this.contract.at(certifier.address).instance.certified.call({}, [ address ]);
|
||||
})
|
||||
.then((certified) => {
|
||||
const { id, title, icon, name } = certifier;
|
||||
|
||||
if (!certified) {
|
||||
return this.store.dispatch(removeCertification(address, id));
|
||||
}
|
||||
|
||||
log.debug('seen as certified', { address, id, name, icon });
|
||||
this.store.dispatch(addCertification(address, id, name, title, icon));
|
||||
});
|
||||
}, Promise.resolve())
|
||||
.then(() => {
|
||||
this.fetchedAccounts[address] = true;
|
||||
});
|
||||
}
|
||||
|
||||
setCertifiersFilter () {
|
||||
const accounts = Object.keys(this.fetchedAccounts);
|
||||
const addresses = Object.values(this.certifiers).map((c) => c.address);
|
||||
// The events have as first indexed data the account address
|
||||
const topics = [
|
||||
this.contractEvents.map((event) => '0x' + event.signature),
|
||||
accounts
|
||||
];
|
||||
|
||||
if (accounts.length === 0 || addresses.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const promise = this.certifiersFilter
|
||||
? this.api.eth.uninstallFilter(this.certifiersFilter)
|
||||
: Promise.resolve();
|
||||
|
||||
log.debug('setting up registry filter', { topics, accounts, addresses });
|
||||
|
||||
return promise
|
||||
.then(() => this.api.eth.newFilter({
|
||||
fromBlock: 'latest',
|
||||
toBlock: 'latest',
|
||||
address: addresses,
|
||||
topics
|
||||
}))
|
||||
.then((filterId) => {
|
||||
this.certifiersFilter = filterId;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
setRegistryFilter () {
|
||||
const { address } = this.registry.instance;
|
||||
const topics = [ this.registryEvents.map((event) => '0x' + event.signature) ];
|
||||
|
||||
log.debug('setting up registry filter', { topics, address });
|
||||
|
||||
return this.api.eth
|
||||
.newFilter({
|
||||
fromBlock: 'latest',
|
||||
toBlock: 'latest',
|
||||
address, topics
|
||||
})
|
||||
.then((filterId) => {
|
||||
this.registryFilter = filterId;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
96
js/src/redux/providers/certifications/enhanced-querier.js
Normal file
96
js/src/redux/providers/certifications/enhanced-querier.js
Normal file
@@ -0,0 +1,96 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { padRight, padLeft } from '~/api/util/format';
|
||||
|
||||
/**
|
||||
* Bytecode of this contract:
|
||||
*
|
||||
*
|
||||
pragma solidity ^0.4.10;
|
||||
|
||||
contract Querier {
|
||||
function Querier
|
||||
(address addr, bytes32 sign, uint out_size, uint from, uint limit)
|
||||
public
|
||||
{
|
||||
// The size is 32 bytes for each
|
||||
// value, plus 32 bytes for the count
|
||||
uint m_size = out_size * limit + 32;
|
||||
|
||||
bytes32 p_return;
|
||||
uint p_in;
|
||||
uint p_out;
|
||||
|
||||
assembly {
|
||||
p_return := mload(0x40)
|
||||
mstore(0x40, add(p_return, m_size))
|
||||
|
||||
mstore(p_return, limit)
|
||||
|
||||
p_in := mload(0x40)
|
||||
mstore(0x40, add(p_in, 0x24))
|
||||
|
||||
mstore(p_in, sign)
|
||||
|
||||
p_out := add(p_return, 0x20)
|
||||
}
|
||||
|
||||
for (uint i = from; i < from + limit; i++) {
|
||||
assembly {
|
||||
mstore(add(p_in, 0x4), i)
|
||||
call(gas, addr, 0x0, p_in, 0x24, p_out, out_size)
|
||||
p_out := add(p_out, out_size)
|
||||
pop
|
||||
}
|
||||
}
|
||||
|
||||
assembly {
|
||||
return (p_return, m_size)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
export const bytecode = '0x60606040523415600e57600080fd5b60405160a0806099833981016040528080519190602001805191906020018051919060200180519190602001805191505082810260200160008080806040519350848401604052858452604051602481016040528981529250505060208201855b858701811015609457806004840152878260248560008e5af15090870190600101606f565b8484f300';
|
||||
|
||||
export const querier = (api, { address, from, limit }, method) => {
|
||||
const { outputs, signature } = method;
|
||||
const outLength = 32 * outputs.length;
|
||||
const callargs = [
|
||||
padLeft(address, 32),
|
||||
padRight(signature, 32),
|
||||
padLeft(outLength, 32),
|
||||
padLeft(from, 32),
|
||||
padLeft(limit, 32)
|
||||
].map((v) => v.slice(2)).join('');
|
||||
const calldata = bytecode + callargs;
|
||||
|
||||
return api.eth.call({ data: calldata })
|
||||
.then((result) => {
|
||||
const data = result.slice(2);
|
||||
const results = [];
|
||||
|
||||
for (let i = 0; i < limit; i++) {
|
||||
const datum = data.substr(2 * (32 + i * outLength), 2 * outLength);
|
||||
const decoded = method.decodeOutput('0x' + datum).map((t) => t.value);
|
||||
|
||||
results.push(decoded);
|
||||
}
|
||||
|
||||
return results;
|
||||
});
|
||||
};
|
||||
@@ -14,222 +14,22 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { uniq, range, debounce } from 'lodash';
|
||||
|
||||
import { addCertification, removeCertification } from './actions';
|
||||
|
||||
import { getLogger, LOG_KEYS } from '~/config';
|
||||
import Contract from '~/api/contract';
|
||||
import Contracts from '~/contracts';
|
||||
import CertifierABI from '~/contracts/abi/certifier.json';
|
||||
|
||||
const log = getLogger(LOG_KEYS.CertificationsMiddleware);
|
||||
|
||||
// TODO: move this to a more general place
|
||||
const updatableFilter = (api, onFilter) => {
|
||||
let filter = null;
|
||||
|
||||
const update = (address, topics) => {
|
||||
if (filter) {
|
||||
filter = filter.then((filterId) => {
|
||||
api.eth.uninstallFilter(filterId);
|
||||
});
|
||||
}
|
||||
|
||||
filter = (filter || Promise.resolve())
|
||||
.then(() => api.eth.newFilter({
|
||||
fromBlock: 'latest',
|
||||
toBlock: 'latest',
|
||||
address,
|
||||
topics
|
||||
}))
|
||||
.then((filterId) => {
|
||||
onFilter(filterId);
|
||||
return filterId;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Failed to create certifications filter:', err);
|
||||
});
|
||||
|
||||
return filter;
|
||||
};
|
||||
|
||||
return update;
|
||||
};
|
||||
import Monitor from './certifiers.monitor';
|
||||
|
||||
export default class CertificationsMiddleware {
|
||||
toMiddleware () {
|
||||
const api = Contracts.get()._api;
|
||||
const badgeReg = Contracts.get().badgeReg;
|
||||
|
||||
const contract = new Contract(api, CertifierABI);
|
||||
const Confirmed = contract.events.find((e) => e.name === 'Confirmed');
|
||||
const Revoked = contract.events.find((e) => e.name === 'Revoked');
|
||||
|
||||
return (store) => {
|
||||
let certifiers = [];
|
||||
let addresses = [];
|
||||
let filterChanged = false;
|
||||
let filter = null;
|
||||
let badgeRegFilter = null;
|
||||
let fetchCertifiersPromise = null;
|
||||
|
||||
const updateFilter = updatableFilter(api, (filterId) => {
|
||||
filterChanged = true;
|
||||
filter = filterId;
|
||||
});
|
||||
|
||||
const badgeRegUpdateFilter = updatableFilter(api, (filterId) => {
|
||||
filterChanged = true;
|
||||
badgeRegFilter = filterId;
|
||||
});
|
||||
|
||||
badgeReg
|
||||
.getContract()
|
||||
.then((badgeRegContract) => {
|
||||
return badgeRegUpdateFilter(badgeRegContract.address, [ [
|
||||
badgeRegContract.instance.Registered.signature,
|
||||
badgeRegContract.instance.Unregistered.signature,
|
||||
badgeRegContract.instance.MetaChanged.signature,
|
||||
badgeRegContract.instance.AddressChanged.signature
|
||||
] ]);
|
||||
})
|
||||
.then(() => {
|
||||
shortFetchChanges();
|
||||
|
||||
api.subscribe('eth_blockNumber', (err) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetchChanges();
|
||||
});
|
||||
});
|
||||
|
||||
function onLogs (logs) {
|
||||
logs = contract.parseEventLogs(logs);
|
||||
logs.forEach((log) => {
|
||||
const certifier = certifiers.find((c) => c.address === log.address);
|
||||
|
||||
if (!certifier) {
|
||||
throw new Error(`Could not find certifier at ${log.address}.`);
|
||||
}
|
||||
const { id, name, title, icon } = certifier;
|
||||
|
||||
if (log.event === 'Revoked') {
|
||||
store.dispatch(removeCertification(log.params.who.value, id));
|
||||
} else {
|
||||
store.dispatch(addCertification(log.params.who.value, id, name, title, icon));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onBadgeRegLogs (logs) {
|
||||
return badgeReg.getContract()
|
||||
.then((badgeRegContract) => {
|
||||
logs = badgeRegContract.parseEventLogs(logs);
|
||||
|
||||
const ids = logs.map((log) => log.params && log.params.id.value.toNumber());
|
||||
|
||||
return fetchCertifiers(uniq(ids));
|
||||
});
|
||||
}
|
||||
|
||||
function _fetchChanges () {
|
||||
const method = filterChanged
|
||||
? 'getFilterLogs'
|
||||
: 'getFilterChanges';
|
||||
|
||||
filterChanged = false;
|
||||
|
||||
api.eth[method](badgeRegFilter)
|
||||
.then(onBadgeRegLogs)
|
||||
.catch((err) => {
|
||||
console.error('Failed to fetch badge reg events:', err);
|
||||
})
|
||||
.then(() => api.eth[method](filter))
|
||||
.then(onLogs)
|
||||
.catch((err) => {
|
||||
console.error('Failed to fetch new certifier events:', err);
|
||||
});
|
||||
}
|
||||
|
||||
const shortFetchChanges = debounce(_fetchChanges, 0.5 * 1000, { leading: true });
|
||||
const fetchChanges = debounce(shortFetchChanges, 10 * 1000, { leading: true });
|
||||
|
||||
function fetchConfirmedEvents () {
|
||||
return updateFilter(certifiers.map((c) => c.address), [
|
||||
[ Confirmed.signature, Revoked.signature ],
|
||||
addresses
|
||||
]).then(() => shortFetchChanges());
|
||||
}
|
||||
|
||||
function fetchCertifiers (ids = []) {
|
||||
if (fetchCertifiersPromise) {
|
||||
return fetchCertifiersPromise;
|
||||
}
|
||||
|
||||
let fetchEvents = false;
|
||||
|
||||
const idsPromise = (certifiers.length === 0)
|
||||
? badgeReg.certifierCount().then((count) => {
|
||||
return range(count);
|
||||
})
|
||||
: Promise.resolve(ids);
|
||||
|
||||
fetchCertifiersPromise = idsPromise
|
||||
.then((ids) => {
|
||||
const promises = ids.map((id) => {
|
||||
return badgeReg.fetchCertifier(id)
|
||||
.then((cert) => {
|
||||
if (!certifiers.some((c) => c.id === cert.id)) {
|
||||
certifiers = certifiers.concat(cert);
|
||||
fetchEvents = true;
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if (/does not exist/.test(err.toString())) {
|
||||
return log.info(err.toString());
|
||||
}
|
||||
|
||||
log.warn(`Could not fetch certifier ${id}:`, err);
|
||||
});
|
||||
});
|
||||
|
||||
return Promise
|
||||
.all(promises)
|
||||
.then(() => {
|
||||
fetchCertifiersPromise = null;
|
||||
|
||||
if (fetchEvents) {
|
||||
return fetchConfirmedEvents();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return fetchCertifiersPromise;
|
||||
}
|
||||
Monitor.init(api, store);
|
||||
|
||||
return (next) => (action) => {
|
||||
switch (action.type) {
|
||||
case 'fetchCertifiers':
|
||||
fetchConfirmedEvents();
|
||||
|
||||
break;
|
||||
case 'fetchCertifications':
|
||||
const { address } = action;
|
||||
|
||||
if (!addresses.includes(address)) {
|
||||
addresses = addresses.concat(address);
|
||||
fetchConfirmedEvents();
|
||||
}
|
||||
|
||||
break;
|
||||
case 'setVisibleAccounts':
|
||||
const _addresses = action.addresses || [];
|
||||
const { addresses = [] } = action;
|
||||
|
||||
addresses = uniq(addresses.concat(_addresses));
|
||||
fetchConfirmedEvents();
|
||||
Monitor.get().fetchAccounts(addresses);
|
||||
next(action);
|
||||
|
||||
break;
|
||||
|
||||
@@ -20,24 +20,32 @@ export default (state = initialState, action) => {
|
||||
if (action.type === 'addCertification') {
|
||||
const { address, id, name, icon, title } = action;
|
||||
const certifications = state[address] || [];
|
||||
const certifierIndex = certifications.findIndex((c) => c.id === id);
|
||||
const data = { id, name, icon, title };
|
||||
const nextCertifications = certifications.slice();
|
||||
|
||||
if (certifications.some((c) => c.id === id)) {
|
||||
return state;
|
||||
if (certifierIndex >= 0) {
|
||||
nextCertifications[certifierIndex] = data;
|
||||
} else {
|
||||
nextCertifications.push(data);
|
||||
}
|
||||
|
||||
const newCertifications = certifications.concat({
|
||||
id, name, icon, title
|
||||
});
|
||||
|
||||
return { ...state, [address]: newCertifications };
|
||||
return { ...state, [address]: nextCertifications };
|
||||
}
|
||||
|
||||
if (action.type === 'removeCertification') {
|
||||
const { address, id } = action;
|
||||
const certifications = state[address] || [];
|
||||
const certifierIndex = certifications.findIndex((c) => c.id === id);
|
||||
|
||||
const newCertifications = certifications.filter((c) => c.id !== id);
|
||||
// Don't remove if not there
|
||||
if (certifierIndex < 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const newCertifications = certifications.slice();
|
||||
|
||||
newCertifications.splice(certifierIndex, 1);
|
||||
return { ...state, [address]: newCertifications };
|
||||
}
|
||||
|
||||
|
||||
@@ -54,13 +54,24 @@ export const watchRequest = (request) => (dispatch, getState) => {
|
||||
dispatch(trackRequest(requestId, request));
|
||||
};
|
||||
|
||||
export const trackRequest = (requestId, { transactionHash = null } = {}) => (dispatch, getState) => {
|
||||
export const trackRequest = (requestId, { transactionHash = null, retries = 0 } = {}) => (dispatch, getState) => {
|
||||
const { api } = getState();
|
||||
|
||||
trackRequestUtil(api, { requestId, transactionHash }, (error, _data = {}) => {
|
||||
const data = { ..._data };
|
||||
|
||||
if (error) {
|
||||
// Retry in 500ms if request not found, max 5 times
|
||||
if (error.type === 'REQUEST_NOT_FOUND') {
|
||||
if (retries > 5) {
|
||||
return dispatch(deleteRequest(requestId));
|
||||
}
|
||||
|
||||
return setTimeout(() => {
|
||||
trackRequest(requestId, { transactionHash, retries: retries + 1 })(dispatch, getState);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
console.error(error);
|
||||
return dispatch(setRequest(requestId, { error }));
|
||||
}
|
||||
|
||||
@@ -115,9 +115,11 @@ export function loadTokensBasics (_tokenIndexes, options) {
|
||||
const prevTokensIndexes = Object.values(tokens).map((t) => t.index);
|
||||
|
||||
// Only fetch tokens we don't have yet
|
||||
const tokenIndexes = _tokenIndexes.filter((tokenIndex) => {
|
||||
return !prevTokensIndexes.includes(tokenIndex);
|
||||
});
|
||||
const tokenIndexes = _tokenIndexes
|
||||
.filter((tokenIndex) => {
|
||||
return !prevTokensIndexes.includes(tokenIndex);
|
||||
})
|
||||
.sort();
|
||||
|
||||
const count = tokenIndexes.length;
|
||||
|
||||
@@ -130,10 +132,15 @@ export function loadTokensBasics (_tokenIndexes, options) {
|
||||
return tokenReg.getContract()
|
||||
.then((tokenRegContract) => {
|
||||
let promise = Promise.resolve();
|
||||
const first = tokenIndexes[0];
|
||||
const last = tokenIndexes[tokenIndexes.length - 1];
|
||||
|
||||
for (let from = first; from <= last; from += limit) {
|
||||
// No need to fetch `limit` elements
|
||||
const lowerLimit = Math.min(limit, last - from + 1);
|
||||
|
||||
for (let start = 0; start < count; start += limit) {
|
||||
promise = promise
|
||||
.then(() => fetchTokensBasics(api, tokenRegContract, start, limit))
|
||||
.then(() => fetchTokensBasics(api, tokenRegContract, from, lowerLimit))
|
||||
.then((results) => {
|
||||
results
|
||||
.forEach((token) => {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
transition: transform ease-out 0.1s;
|
||||
transform: scale(1);
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { pick } from 'lodash';
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import TokenImage from '~/ui/TokenImage';
|
||||
import TokenValue from './tokenValue';
|
||||
|
||||
import styles from './balance.css';
|
||||
|
||||
@@ -69,58 +70,19 @@ export class Balance extends Component {
|
||||
const balanceValue = balance[tokenId];
|
||||
|
||||
const isEthToken = token.native;
|
||||
const isFullToken = !showOnlyEth || isEthToken;
|
||||
const hasBalance = (balanceValue instanceof BigNumber) && balanceValue.gt(0);
|
||||
|
||||
if (!hasBalance && !isEthToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const bnf = new BigNumber(token.format || 1);
|
||||
let decimals = 0;
|
||||
|
||||
if (bnf.gte(1000)) {
|
||||
decimals = 3;
|
||||
} else if (bnf.gte(100)) {
|
||||
decimals = 2;
|
||||
} else if (bnf.gte(10)) {
|
||||
decimals = 1;
|
||||
}
|
||||
|
||||
const rawValue = new BigNumber(balanceValue).div(bnf);
|
||||
const value = rawValue.toFormat(decimals);
|
||||
|
||||
const classNames = [styles.balance];
|
||||
let details = null;
|
||||
|
||||
if (isFullToken) {
|
||||
classNames.push(styles.full);
|
||||
details = [
|
||||
<div
|
||||
className={ styles.value }
|
||||
key='value'
|
||||
>
|
||||
<span title={ `${rawValue.toFormat()} ${token.tag}` }>
|
||||
{ value }
|
||||
</span>
|
||||
</div>,
|
||||
<div
|
||||
className={ styles.tag }
|
||||
key='tag'
|
||||
>
|
||||
{ token.tag }
|
||||
</div>
|
||||
];
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={ classNames.join(' ') }
|
||||
<TokenValue
|
||||
key={ tokenId }
|
||||
>
|
||||
<TokenImage token={ token } />
|
||||
{ details }
|
||||
</div>
|
||||
showOnlyEth={ showOnlyEth }
|
||||
token={ token }
|
||||
value={ balanceValue }
|
||||
/>
|
||||
);
|
||||
})
|
||||
.filter((node) => node);
|
||||
@@ -155,11 +117,15 @@ export class Balance extends Component {
|
||||
}
|
||||
|
||||
function mapStateToProps (state, props) {
|
||||
const { balances, tokens } = state;
|
||||
const { balances, tokens: allTokens } = state;
|
||||
const { address } = props;
|
||||
const balance = balances[address] || props.balance || {};
|
||||
|
||||
const tokenIds = Object.keys(balance);
|
||||
const tokens = pick(allTokens, tokenIds);
|
||||
|
||||
return {
|
||||
balance: balances[address] || props.balance || {},
|
||||
balance,
|
||||
tokens
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,13 +84,13 @@ describe('ui/Balance', () => {
|
||||
});
|
||||
|
||||
it('renders all the non-zero balances', () => {
|
||||
expect(component.find('Connect(TokenImage)')).to.have.length(2);
|
||||
expect(component.find('Connect(TokenValue)')).to.have.length(2);
|
||||
});
|
||||
|
||||
describe('render specifiers', () => {
|
||||
it('renders all the tokens with showZeroValues', () => {
|
||||
render({ showZeroValues: true });
|
||||
expect(component.find('Connect(TokenImage)')).to.have.length(2);
|
||||
expect(component.find('Connect(TokenValue)')).to.have.length(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
109
js/src/ui/Balance/tokenValue.js
Normal file
109
js/src/ui/Balance/tokenValue.js
Normal file
@@ -0,0 +1,109 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
|
||||
import { fetchTokens } from '~/redux/providers/tokensActions';
|
||||
import TokenImage from '~/ui/TokenImage';
|
||||
|
||||
import styles from './balance.css';
|
||||
|
||||
class TokenValue extends Component {
|
||||
static propTypes = {
|
||||
token: PropTypes.object.isRequired,
|
||||
value: PropTypes.object.isRequired,
|
||||
|
||||
// Redux injection
|
||||
fetchTokens: PropTypes.func.isRequired,
|
||||
|
||||
showOnlyEth: PropTypes.bool
|
||||
};
|
||||
|
||||
componentWillMount () {
|
||||
const { token } = this.props;
|
||||
|
||||
if (token.native) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!token.fetched) {
|
||||
if (!Number.isFinite(token.index)) {
|
||||
return console.warn('no token index', token);
|
||||
}
|
||||
|
||||
this.props.fetchTokens([ token.index ]);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { token, showOnlyEth, value } = this.props;
|
||||
|
||||
const isEthToken = token.native;
|
||||
const isFullToken = !showOnlyEth || isEthToken;
|
||||
|
||||
const bnf = new BigNumber(token.format || 1);
|
||||
let decimals = 0;
|
||||
|
||||
if (bnf.gte(1000)) {
|
||||
decimals = 3;
|
||||
} else if (bnf.gte(100)) {
|
||||
decimals = 2;
|
||||
} else if (bnf.gte(10)) {
|
||||
decimals = 1;
|
||||
}
|
||||
|
||||
const rawValue = new BigNumber(value).div(bnf);
|
||||
const classNames = [styles.balance];
|
||||
|
||||
if (isFullToken) {
|
||||
classNames.push(styles.full);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={ classNames.join(' ') }>
|
||||
<TokenImage token={ token } />
|
||||
{
|
||||
isFullToken
|
||||
? [
|
||||
<div className={ styles.value } key='value'>
|
||||
<span title={ `${rawValue.toFormat()} ${token.tag}` }>
|
||||
{ rawValue.toFormat(decimals) }
|
||||
</span>
|
||||
</div>,
|
||||
<div className={ styles.tag } key='tag'>
|
||||
{ token.tag }
|
||||
</div>
|
||||
]
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps (dispatch) {
|
||||
return bindActionCreators({
|
||||
fetchTokens
|
||||
}, dispatch);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
null,
|
||||
mapDispatchToProps
|
||||
)(TokenValue);
|
||||
@@ -19,6 +19,7 @@ import React, { Component, PropTypes } from 'react';
|
||||
import Container, { Title as ContainerTitle } from '~/ui/Container';
|
||||
import DappIcon from '~/ui/DappIcon';
|
||||
import Tags from '~/ui/Tags';
|
||||
import DappVouchFor from '../DappVouchFor';
|
||||
|
||||
import styles from './dappCard.css';
|
||||
|
||||
@@ -61,6 +62,7 @@ export default class DappCard extends Component {
|
||||
app={ app }
|
||||
className={ styles.image }
|
||||
/>
|
||||
<DappVouchFor app={ app } />
|
||||
<Tags
|
||||
className={ styles.tags }
|
||||
tags={
|
||||
|
||||
43
js/src/ui/DappVouchFor/dappVouchFor.css
Normal file
43
js/src/ui/DappVouchFor/dappVouchFor.css
Normal file
@@ -0,0 +1,43 @@
|
||||
/* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
.tag {
|
||||
color: inherit;
|
||||
position: absolute;
|
||||
top: 1em;
|
||||
right: 1em;
|
||||
|
||||
.image {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
.bubble {
|
||||
background: red;
|
||||
border-radius: 0.25em;
|
||||
color: white;
|
||||
font-size: 0.75em;
|
||||
padding: 0.1em 0.5em;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
}
|
||||
57
js/src/ui/DappVouchFor/dappVouchFor.js
Normal file
57
js/src/ui/DappVouchFor/dappVouchFor.js
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { observer } from 'mobx-react';
|
||||
|
||||
import IdentityIcon from '../IdentityIcon';
|
||||
|
||||
import Store from './store';
|
||||
import styles from './dappVouchFor.css';
|
||||
|
||||
@observer
|
||||
export default class DappVouchFor extends Component {
|
||||
static contextTypes = {
|
||||
api: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
static propTypes = {
|
||||
app: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
store = new Store(this.context.api, this.props.app);
|
||||
|
||||
render () {
|
||||
const count = this.store.vouchers.length;
|
||||
|
||||
if (!count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={ styles.tag }>
|
||||
<IdentityIcon
|
||||
address={ this.store.vouchers[0] }
|
||||
className={ styles.image }
|
||||
alt={ `${count} identities vouch for this dapp` }
|
||||
/>
|
||||
<div className={ styles.bubble }>
|
||||
{ count }
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
17
js/src/ui/DappVouchFor/index.js
Normal file
17
js/src/ui/DappVouchFor/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
export default from './dappVouchFor';
|
||||
87
js/src/ui/DappVouchFor/store.js
Normal file
87
js/src/ui/DappVouchFor/store.js
Normal file
@@ -0,0 +1,87 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { action, observable } from 'mobx';
|
||||
import { uniq } from 'lodash';
|
||||
|
||||
import Contracts from '~/contracts';
|
||||
import { vouchfor as vouchForAbi } from '~/contracts/abi';
|
||||
|
||||
let contractPromise = null;
|
||||
|
||||
export default class Store {
|
||||
@observable vouchers = [];
|
||||
|
||||
constructor (api, app) {
|
||||
this._api = api;
|
||||
|
||||
this.findVouchers(app);
|
||||
}
|
||||
|
||||
async attachContract () {
|
||||
const address = await Contracts.get().registry.lookupAddress('vouchfor');
|
||||
|
||||
if (!address || /^0x0*$/.test(address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const contract = await this._api.newContract(vouchForAbi, address);
|
||||
|
||||
return contract;
|
||||
}
|
||||
|
||||
async findVouchers ({ contentHash, id }) {
|
||||
if (!contentHash) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!contractPromise) {
|
||||
contractPromise = this.attachContract();
|
||||
}
|
||||
|
||||
const contract = await contractPromise;
|
||||
|
||||
if (!contract) {
|
||||
return;
|
||||
}
|
||||
|
||||
const vouchHash = await this.lookupHash(contract, `0x${contentHash}`);
|
||||
const vouchId = await this.lookupHash(contract, id);
|
||||
|
||||
this.addVouchers(vouchHash, vouchId);
|
||||
}
|
||||
|
||||
async lookupHash (contract, hash) {
|
||||
const vouchers = [];
|
||||
let lastItem = false;
|
||||
|
||||
for (let index = 0; !lastItem; index++) {
|
||||
const voucher = await contract.instance.vouched.call({}, [hash, index]);
|
||||
|
||||
if (/^0x0*$/.test(voucher)) {
|
||||
lastItem = true;
|
||||
} else {
|
||||
vouchers.push(voucher);
|
||||
}
|
||||
}
|
||||
|
||||
return vouchers;
|
||||
}
|
||||
|
||||
@action addVouchers = (vouchHash, vouchId) => {
|
||||
this.vouchers = uniq([].concat(this.vouchers.peek(), vouchHash, vouchId));
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ class IdentityIcon extends Component {
|
||||
|
||||
static propTypes = {
|
||||
address: PropTypes.string,
|
||||
alt: PropTypes.string,
|
||||
button: PropTypes.bool,
|
||||
center: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
@@ -84,7 +85,7 @@ class IdentityIcon extends Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
const { address, button, className, center, disabled, inline, padded, tiny } = this.props;
|
||||
const { address, alt, button, className, center, disabled, inline, padded, tiny } = this.props;
|
||||
const { iconsrc } = this.state;
|
||||
const classes = [
|
||||
styles.icon,
|
||||
@@ -135,6 +136,7 @@ class IdentityIcon extends Component {
|
||||
|
||||
return (
|
||||
<img
|
||||
alt={ alt || address }
|
||||
className={ classes }
|
||||
data-address-img
|
||||
height={ size }
|
||||
|
||||
@@ -23,6 +23,7 @@ import { connect } from 'react-redux';
|
||||
|
||||
import { TypedInput, InputAddress } from '../Form';
|
||||
import MethodDecodingStore from './methodDecodingStore';
|
||||
import TokenValue from './tokenValue';
|
||||
|
||||
import styles from './methodDecoding.css';
|
||||
|
||||
@@ -602,9 +603,10 @@ class MethodDecoding extends Component {
|
||||
const { token } = this.props;
|
||||
|
||||
return (
|
||||
<span className={ styles.tokenValue }>
|
||||
{ value.div(token.format).toFormat(5) }<small> { token.tag }</small>
|
||||
</span>
|
||||
<TokenValue
|
||||
id={ token.id }
|
||||
value={ value }
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
102
js/src/ui/MethodDecoding/tokenValue.js
Normal file
102
js/src/ui/MethodDecoding/tokenValue.js
Normal file
@@ -0,0 +1,102 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
|
||||
import { fetchTokens } from '~/redux/providers/tokensActions';
|
||||
import styles from './methodDecoding.css';
|
||||
|
||||
class TokenValue extends Component {
|
||||
static propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
value: PropTypes.object.isRequired,
|
||||
|
||||
fetchTokens: PropTypes.func,
|
||||
token: PropTypes.object
|
||||
};
|
||||
|
||||
componentWillMount () {
|
||||
const { token } = this.props;
|
||||
|
||||
if (!token.fetched) {
|
||||
this.props.fetchTokens([ token.index ]);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { token, value } = this.props;
|
||||
|
||||
if (!token.format) {
|
||||
console.warn('token with no format', token);
|
||||
}
|
||||
|
||||
const format = token.format
|
||||
? token.format
|
||||
: 1;
|
||||
|
||||
const precision = token.format
|
||||
? 5
|
||||
: 0;
|
||||
|
||||
const tag = token.format
|
||||
? token.tag
|
||||
: 'TOKENS';
|
||||
|
||||
return (
|
||||
<span className={ styles.tokenValue }>
|
||||
{ value.div(format).toFormat(precision) }<small> { tag }</small>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function mapStateToProps (initState, initProps) {
|
||||
const { id } = initProps;
|
||||
let token = Object.assign({}, initState.tokens[id]);
|
||||
|
||||
if (token.fetched) {
|
||||
return () => ({ token });
|
||||
}
|
||||
|
||||
let update = true;
|
||||
|
||||
return (state) => {
|
||||
if (update) {
|
||||
const { tokens } = state;
|
||||
const nextToken = tokens[id];
|
||||
|
||||
if (nextToken.fetched) {
|
||||
token = Object.assign({}, nextToken);
|
||||
update = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { token };
|
||||
};
|
||||
}
|
||||
|
||||
function mapDispatchToProps (dispatch) {
|
||||
return bindActionCreators({
|
||||
fetchTokens
|
||||
}, dispatch);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(TokenValue);
|
||||
@@ -81,12 +81,11 @@ export function getTxOptions (api, func, _options, values = []) {
|
||||
options.to = options.to || func.contract.address;
|
||||
}
|
||||
|
||||
if (!address) {
|
||||
return Promise.resolve({ func, options, values });
|
||||
}
|
||||
const promise = (!address)
|
||||
? Promise.resolve(false)
|
||||
: WalletsUtils.isWallet(api, address);
|
||||
|
||||
return WalletsUtils
|
||||
.isWallet(api, address)
|
||||
return promise
|
||||
.then((isWallet) => {
|
||||
if (!isWallet) {
|
||||
return { func, options, values };
|
||||
|
||||
@@ -26,7 +26,6 @@ import HardwareStore from '~/mobx/hardwareStore';
|
||||
import ExportStore from '~/modals/ExportAccount/exportStore';
|
||||
import { DeleteAccount, EditMeta, Faucet, PasswordManager, Shapeshift, Transfer, Verification } from '~/modals';
|
||||
import { setVisibleAccounts } from '~/redux/providers/personalActions';
|
||||
import { fetchCertifiers, fetchCertifications } from '~/redux/providers/certifications/actions';
|
||||
import { Actionbar, Button, ConfirmDialog, Input, Page, Portal } from '~/ui';
|
||||
import { DeleteIcon, DialIcon, EditIcon, LockedIcon, SendIcon, VerifyIcon, FileDownloadIcon } from '~/ui/Icons';
|
||||
|
||||
@@ -45,8 +44,6 @@ class Account extends Component {
|
||||
|
||||
static propTypes = {
|
||||
accounts: PropTypes.object.isRequired,
|
||||
fetchCertifiers: PropTypes.func.isRequired,
|
||||
fetchCertifications: PropTypes.func.isRequired,
|
||||
setVisibleAccounts: PropTypes.func.isRequired,
|
||||
|
||||
account: PropTypes.object,
|
||||
@@ -67,7 +64,6 @@ class Account extends Component {
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.props.fetchCertifiers();
|
||||
this.setVisibleAccounts();
|
||||
}
|
||||
|
||||
@@ -90,11 +86,10 @@ class Account extends Component {
|
||||
}
|
||||
|
||||
setVisibleAccounts (props = this.props) {
|
||||
const { params, setVisibleAccounts, fetchCertifications } = props;
|
||||
const { params, setVisibleAccounts } = props;
|
||||
const addresses = [params.address];
|
||||
|
||||
setVisibleAccounts(addresses);
|
||||
fetchCertifications(params.address);
|
||||
}
|
||||
|
||||
render () {
|
||||
@@ -524,8 +519,6 @@ function mapStateToProps (state, props) {
|
||||
|
||||
function mapDispatchToProps (dispatch) {
|
||||
return bindActionCreators({
|
||||
fetchCertifiers,
|
||||
fetchCertifications,
|
||||
newError,
|
||||
setVisibleAccounts
|
||||
}, dispatch);
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
import { pick } from 'lodash';
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
|
||||
import { Container, SectionList } from '~/ui';
|
||||
import { fetchCertifiers, fetchCertifications } from '~/redux/providers/certifications/actions';
|
||||
import { ETH_TOKEN } from '~/util/tokens';
|
||||
|
||||
import Summary from '../Summary';
|
||||
@@ -38,20 +36,9 @@ class List extends Component {
|
||||
orderFallback: PropTypes.string,
|
||||
search: PropTypes.array,
|
||||
|
||||
fetchCertifiers: PropTypes.func.isRequired,
|
||||
fetchCertifications: PropTypes.func.isRequired,
|
||||
handleAddSearchToken: PropTypes.func
|
||||
};
|
||||
|
||||
componentWillMount () {
|
||||
const { accounts, fetchCertifiers, fetchCertifications } = this.props;
|
||||
|
||||
fetchCertifiers();
|
||||
for (let address in accounts) {
|
||||
fetchCertifications(address);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { accounts, disabled, empty } = this.props;
|
||||
|
||||
@@ -264,14 +251,7 @@ function mapStateToProps (state, props) {
|
||||
return { balances, certifications };
|
||||
}
|
||||
|
||||
function mapDispatchToProps (dispatch) {
|
||||
return bindActionCreators({
|
||||
fetchCertifiers,
|
||||
fetchCertifications
|
||||
}, dispatch);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
null
|
||||
)(List);
|
||||
|
||||
@@ -99,7 +99,7 @@ describe('views/Signer/components/SignRequest', () => {
|
||||
expect(isMarkdown(encodedMd)).to.be.true;
|
||||
});
|
||||
|
||||
it('returns false for randow data', () => {
|
||||
it('returns false for random data', () => {
|
||||
expect(isMarkdown('0x1234')).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -462,7 +462,7 @@
|
||||
<key>OVERWRITE_PERMISSIONS</key>
|
||||
<false/>
|
||||
<key>VERSION</key>
|
||||
<string>1.7.4</string>
|
||||
<string>1.7.6</string>
|
||||
</dict>
|
||||
<key>UUID</key>
|
||||
<string>2DCD5B81-7BAF-4DA1-9251-6274B089FD36</string>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
!define DESCRIPTION "Fast, light, robust Ethereum implementation"
|
||||
!define VERSIONMAJOR 1
|
||||
!define VERSIONMINOR 7
|
||||
!define VERSIONBUILD 4
|
||||
!define VERSIONBUILD 6
|
||||
!define ARGS "--warp"
|
||||
!define FIRST_START_ARGS "ui --warp --mode=passive"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ description = "Ethcore utility library"
|
||||
homepage = "http://parity.io"
|
||||
license = "GPL-3.0"
|
||||
name = "ethcore-util"
|
||||
version = "1.7.4"
|
||||
version = "1.7.6"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
build = "build.rs"
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/version.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/rustc_version.rs"));
|
||||
|
||||
#[cfg(feature = "final")]
|
||||
const THIS_TRACK: &'static str = "beta";
|
||||
const THIS_TRACK: &'static str = "stable";
|
||||
// ^^^ should be reset to "stable" or "beta" according to the release branch.
|
||||
|
||||
#[cfg(not(feature = "final"))]
|
||||
|
||||
Reference in New Issue
Block a user