Merge branch 'master' into auth-round
This commit is contained in:
commit
ae5ae765a6
@ -17,7 +17,7 @@ matrix:
|
||||
include:
|
||||
- rust: stable
|
||||
env: RUN_TESTS="true" TEST_OPTIONS="--no-release"
|
||||
- rust: beta
|
||||
- rust: stable
|
||||
env: RUN_COVERAGE="true"
|
||||
- rust: stable
|
||||
env: RUN_DOCS="true"
|
||||
|
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1249,7 +1249,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "parity-ui-precompiled"
|
||||
version = "1.4.0"
|
||||
source = "git+https://github.com/ethcore/js-precompiled.git#bf33dd4aabd2adb2178576db5a4d23b8902d39b8"
|
||||
source = "git+https://github.com/ethcore/js-precompiled.git#610876fb2bb01705b81de14dd7e04d6a3cdf80ab"
|
||||
dependencies = [
|
||||
"parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -1926,7 +1926,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
[[package]]
|
||||
name = "ws"
|
||||
version = "0.5.3"
|
||||
source = "git+https://github.com/ethcore/ws-rs.git?branch=mio-upstream-stable#0cd6c5e3e9d5e61a37d53eb8dcbad523dcc69314"
|
||||
source = "git+https://github.com/ethcore/ws-rs.git?branch=mio-upstream-stable#f5c0b35d660244d1b7500693c8cc28277ce1d418"
|
||||
dependencies = [
|
||||
"bytes 0.4.0-dev (git+https://github.com/carllerche/bytes)",
|
||||
"httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "TestInstantSeal",
|
||||
"name": "DevelopmentChain",
|
||||
"engine": {
|
||||
"InstantSeal": null
|
||||
},
|
||||
@ -28,6 +28,6 @@
|
||||
"0000000000000000000000000000000000000002": { "balance": "1", "nonce": "1048576", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
||||
"0000000000000000000000000000000000000003": { "balance": "1", "nonce": "1048576", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
||||
"0000000000000000000000000000000000000004": { "balance": "1", "nonce": "1048576", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
||||
"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "1048576" }
|
||||
"0x00a329c0648769a73afac7f9381e08fb43dbea72": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "1048576" }
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ impl Engine for InstantSeal {
|
||||
}
|
||||
|
||||
fn schedule(&self, _env_info: &EnvInfo) -> Schedule {
|
||||
Schedule::new_homestead()
|
||||
Schedule::new_post_eip150(false, false, false)
|
||||
}
|
||||
|
||||
fn is_sealer(&self, _author: &Address) -> Option<bool> { Some(true) }
|
||||
@ -79,7 +79,7 @@ mod tests {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("".sha3(), "").unwrap();
|
||||
|
||||
let spec = Spec::new_test_instant();
|
||||
let spec = Spec::new_instant();
|
||||
let engine = &*spec.engine;
|
||||
let genesis_header = spec.genesis_header();
|
||||
let mut db_result = get_temp_state_db();
|
||||
@ -95,7 +95,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn instant_cant_verify() {
|
||||
let engine = Spec::new_test_instant().engine;
|
||||
let engine = Spec::new_instant().engine;
|
||||
let mut header: Header = Header::default();
|
||||
|
||||
assert!(engine.verify_block_basic(&header, None).is_ok());
|
||||
|
@ -1259,7 +1259,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn internal_seals_without_work() {
|
||||
let miner = Miner::with_spec(&Spec::new_test_instant());
|
||||
let miner = Miner::with_spec(&Spec::new_instant());
|
||||
|
||||
let c = generate_dummy_client(2);
|
||||
let client = c.reference().as_ref();
|
||||
|
@ -19,11 +19,11 @@
|
||||
use account_db::{AccountDB, AccountDBMut};
|
||||
use snapshot::Error;
|
||||
|
||||
use util::{U256, FixedHash, H256, Bytes, HashDB, DBValue, SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::{U256, FixedHash, H256, Bytes, HashDB, SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::trie::{TrieDB, Trie};
|
||||
use rlp::{Rlp, RlpStream, Stream, UntrustedRlp, View};
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
|
||||
// An empty account -- these are replaced with RLP null data for a space optimization.
|
||||
const ACC_EMPTY: Account = Account {
|
||||
@ -150,7 +150,6 @@ impl Account {
|
||||
pub fn from_fat_rlp(
|
||||
acct_db: &mut AccountDBMut,
|
||||
rlp: UntrustedRlp,
|
||||
code_map: &HashMap<H256, Bytes>,
|
||||
) -> Result<(Self, Option<Bytes>), Error> {
|
||||
use util::{TrieDBMut, TrieMut};
|
||||
|
||||
@ -177,9 +176,6 @@ impl Account {
|
||||
}
|
||||
CodeState::Hash => {
|
||||
let code_hash = try!(rlp.val_at(3));
|
||||
if let Some(code) = code_map.get(&code_hash) {
|
||||
acct_db.emplace(code_hash.clone(), DBValue::from_slice(code));
|
||||
}
|
||||
|
||||
(code_hash, None)
|
||||
}
|
||||
@ -229,7 +225,7 @@ mod tests {
|
||||
use util::{Address, FixedHash, H256, HashDB, DBValue};
|
||||
use rlp::{UntrustedRlp, View};
|
||||
|
||||
use std::collections::{HashSet, HashMap};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::{ACC_EMPTY, Account};
|
||||
|
||||
@ -250,7 +246,7 @@ mod tests {
|
||||
|
||||
let fat_rlp = account.to_fat_rlp(&AccountDB::new(db.as_hashdb(), &addr), &mut Default::default()).unwrap();
|
||||
let fat_rlp = UntrustedRlp::new(&fat_rlp);
|
||||
assert_eq!(Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp, &Default::default()).unwrap().0, account);
|
||||
assert_eq!(Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp).unwrap().0, account);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -275,7 +271,7 @@ mod tests {
|
||||
|
||||
let fat_rlp = account.to_fat_rlp(&AccountDB::new(db.as_hashdb(), &addr), &mut Default::default()).unwrap();
|
||||
let fat_rlp = UntrustedRlp::new(&fat_rlp);
|
||||
assert_eq!(Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp, &Default::default()).unwrap().0, account);
|
||||
assert_eq!(Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp).unwrap().0, account);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -318,12 +314,11 @@ mod tests {
|
||||
let fat_rlp1 = UntrustedRlp::new(&fat_rlp1);
|
||||
let fat_rlp2 = UntrustedRlp::new(&fat_rlp2);
|
||||
|
||||
let code_map = HashMap::new();
|
||||
let (acc, maybe_code) = Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr2), fat_rlp2, &code_map).unwrap();
|
||||
let (acc, maybe_code) = Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr2), fat_rlp2).unwrap();
|
||||
assert!(maybe_code.is_none());
|
||||
assert_eq!(acc, account2);
|
||||
|
||||
let (acc, maybe_code) = Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr1), fat_rlp1, &code_map).unwrap();
|
||||
let (acc, maybe_code) = Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr1), fat_rlp1).unwrap();
|
||||
assert_eq!(maybe_code, Some(b"this is definitely code".to_vec()));
|
||||
assert_eq!(acc, account1);
|
||||
}
|
||||
@ -332,9 +327,8 @@ mod tests {
|
||||
fn encoding_empty_acc() {
|
||||
let mut db = get_temp_state_db();
|
||||
let mut used_code = HashSet::new();
|
||||
let code_map = HashMap::new();
|
||||
|
||||
assert_eq!(ACC_EMPTY.to_fat_rlp(&AccountDB::new(db.as_hashdb(), &Address::default()), &mut used_code).unwrap(), ::rlp::NULL_RLP.to_vec());
|
||||
assert_eq!(Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &Address::default()), UntrustedRlp::new(&::rlp::NULL_RLP), &code_map).unwrap(), (ACC_EMPTY, None));
|
||||
assert_eq!(Account::from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &Address::default()), UntrustedRlp::new(&::rlp::NULL_RLP)).unwrap(), (ACC_EMPTY, None));
|
||||
}
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ pub fn chunk_state<'a>(db: &HashDB, root: &H256, writer: &Mutex<SnapshotWriter +
|
||||
pub struct StateRebuilder {
|
||||
db: Box<JournalDB>,
|
||||
state_root: H256,
|
||||
code_map: HashMap<H256, Bytes>, // maps code hashes to code itself.
|
||||
known_code: HashMap<H256, H256>, // code hashes mapped to first account with this code.
|
||||
missing_code: HashMap<H256, Vec<H256>>, // maps code hashes to lists of accounts missing that code.
|
||||
bloom: Bloom,
|
||||
}
|
||||
@ -400,7 +400,7 @@ impl StateRebuilder {
|
||||
StateRebuilder {
|
||||
db: journaldb::new(db.clone(), pruning, ::db::COL_STATE),
|
||||
state_root: SHA3_NULL_RLP,
|
||||
code_map: HashMap::new(),
|
||||
known_code: HashMap::new(),
|
||||
missing_code: HashMap::new(),
|
||||
bloom: StateDB::load_bloom(&*db),
|
||||
}
|
||||
@ -419,7 +419,7 @@ impl StateRebuilder {
|
||||
self.db.as_hashdb_mut(),
|
||||
rlp,
|
||||
&mut pairs,
|
||||
&self.code_map,
|
||||
&self.known_code,
|
||||
flag
|
||||
));
|
||||
|
||||
@ -428,13 +428,13 @@ impl StateRebuilder {
|
||||
}
|
||||
|
||||
// patch up all missing code. must be done after collecting all new missing code entries.
|
||||
for (code_hash, code) in status.new_code {
|
||||
for (code_hash, code, first_with) in status.new_code {
|
||||
for addr_hash in self.missing_code.remove(&code_hash).unwrap_or_else(Vec::new) {
|
||||
let mut db = AccountDBMut::from_hash(self.db.as_hashdb_mut(), addr_hash);
|
||||
db.emplace(code_hash, DBValue::from_slice(&code));
|
||||
}
|
||||
|
||||
self.code_map.insert(code_hash, code);
|
||||
self.known_code.insert(code_hash, first_with);
|
||||
}
|
||||
|
||||
let backing = self.db.backing().clone();
|
||||
@ -482,7 +482,8 @@ impl StateRebuilder {
|
||||
|
||||
#[derive(Default)]
|
||||
struct RebuiltStatus {
|
||||
new_code: Vec<(H256, Bytes)>, // new code that's become available.
|
||||
// new code that's become available. (code_hash, code, addr_hash)
|
||||
new_code: Vec<(H256, Bytes, H256)>,
|
||||
missing_code: Vec<(H256, H256)>, // accounts that are missing code.
|
||||
}
|
||||
|
||||
@ -492,10 +493,9 @@ fn rebuild_accounts(
|
||||
db: &mut HashDB,
|
||||
account_fat_rlps: UntrustedRlp,
|
||||
out_chunk: &mut [(H256, Bytes)],
|
||||
code_map: &HashMap<H256, Bytes>,
|
||||
abort_flag: &AtomicBool
|
||||
) -> Result<RebuiltStatus, ::error::Error>
|
||||
{
|
||||
known_code: &HashMap<H256, H256>,
|
||||
abort_flag: &AtomicBool,
|
||||
) -> Result<RebuiltStatus, ::error::Error> {
|
||||
let mut status = RebuiltStatus::default();
|
||||
for (account_rlp, out) in account_fat_rlps.into_iter().zip(out_chunk) {
|
||||
if !abort_flag.load(Ordering::SeqCst) { return Err(Error::RestorationAborted.into()) }
|
||||
@ -504,17 +504,33 @@ fn rebuild_accounts(
|
||||
let fat_rlp = try!(account_rlp.at(1));
|
||||
|
||||
let thin_rlp = {
|
||||
let mut acct_db = AccountDBMut::from_hash(db, hash);
|
||||
|
||||
// fill out the storage trie and code while decoding.
|
||||
let (acc, maybe_code) = try!(Account::from_fat_rlp(&mut acct_db, fat_rlp, code_map));
|
||||
let (acc, maybe_code) = {
|
||||
let mut acct_db = AccountDBMut::from_hash(db, hash);
|
||||
try!(Account::from_fat_rlp(&mut acct_db, fat_rlp))
|
||||
};
|
||||
|
||||
let code_hash = acc.code_hash().clone();
|
||||
match maybe_code {
|
||||
Some(code) => status.new_code.push((code_hash, code)),
|
||||
// new inline code
|
||||
Some(code) => status.new_code.push((code_hash, code, hash)),
|
||||
None => {
|
||||
if code_hash != ::util::SHA3_EMPTY && !code_map.contains_key(&code_hash) {
|
||||
status.missing_code.push((hash, code_hash));
|
||||
if code_hash != ::util::SHA3_EMPTY {
|
||||
// see if this code has already been included inline
|
||||
match known_code.get(&code_hash) {
|
||||
Some(&first_with) => {
|
||||
// if so, load it from the database.
|
||||
let code = try!(AccountDB::from_hash(db, first_with)
|
||||
.get(&code_hash)
|
||||
.ok_or_else(|| Error::MissingCode(vec![first_with])));
|
||||
|
||||
// and write it again under a different mangled key
|
||||
AccountDBMut::from_hash(db, hash).emplace(code_hash, code);
|
||||
}
|
||||
// if not, queue it up to be filled later
|
||||
None => status.missing_code.push((hash, code_hash)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
//! State snapshotting tests.
|
||||
|
||||
use snapshot::{chunk_state, Error as SnapshotError, Progress, StateRebuilder};
|
||||
use snapshot::account::Account;
|
||||
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter};
|
||||
use super::helpers::{compare_dbs, StateProducer};
|
||||
|
||||
@ -30,6 +31,8 @@ use util::memorydb::MemoryDB;
|
||||
use util::Mutex;
|
||||
use devtools::RandomTempPath;
|
||||
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
@ -88,6 +91,58 @@ fn snap_and_restore() {
|
||||
compare_dbs(&old_db, new_db.as_hashdb());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_code_from_prev_chunk() {
|
||||
use std::collections::HashSet;
|
||||
use rlp::{RlpStream, Stream};
|
||||
use util::{HashDB, H256, FixedHash, U256, Hashable};
|
||||
|
||||
use account_db::{AccountDBMut, AccountDB};
|
||||
|
||||
let code = b"this is definitely code";
|
||||
let mut used_code = HashSet::new();
|
||||
let mut acc_stream = RlpStream::new_list(4);
|
||||
acc_stream.append(&U256::default())
|
||||
.append(&U256::default())
|
||||
.append(&SHA3_NULL_RLP)
|
||||
.append(&code.sha3());
|
||||
|
||||
let (h1, h2) = (H256::random(), H256::random());
|
||||
|
||||
// two accounts with the same code, one per chunk.
|
||||
// first one will have code inlined,
|
||||
// second will just have its hash.
|
||||
let thin_rlp = acc_stream.out();
|
||||
let acc1 = Account::from_thin_rlp(&thin_rlp);
|
||||
let acc2 = Account::from_thin_rlp(&thin_rlp);
|
||||
|
||||
let mut make_chunk = |acc: Account, hash| {
|
||||
let mut db = MemoryDB::new();
|
||||
AccountDBMut::from_hash(&mut db, hash).insert(&code[..]);
|
||||
|
||||
let fat_rlp = acc.to_fat_rlp(&AccountDB::from_hash(&db, hash), &mut used_code).unwrap();
|
||||
|
||||
let mut stream = RlpStream::new_list(1);
|
||||
stream.begin_list(2).append(&hash).append_raw(&fat_rlp, 1);
|
||||
stream.out()
|
||||
};
|
||||
|
||||
let chunk1 = make_chunk(acc1, h1);
|
||||
let chunk2 = make_chunk(acc2, h2);
|
||||
|
||||
let db_path = RandomTempPath::create_dir();
|
||||
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
||||
let new_db = Arc::new(Database::open(&db_cfg, &db_path.to_string_lossy()).unwrap());
|
||||
|
||||
let mut rebuilder = StateRebuilder::new(new_db, Algorithm::Archive);
|
||||
let flag = AtomicBool::new(true);
|
||||
|
||||
rebuilder.feed(&chunk1, &flag).unwrap();
|
||||
rebuilder.feed(&chunk2, &flag).unwrap();
|
||||
|
||||
rebuilder.check_missing().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checks_flag() {
|
||||
let mut producer = StateProducer::new();
|
||||
|
@ -135,6 +135,12 @@ impl From<ethjson::spec::Spec> for Spec {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! load_bundled {
|
||||
($e:expr) => {
|
||||
Spec::load(include_bytes!(concat!("../../res/", $e, ".json")) as &[u8]).expect(concat!("Chain spec ", $e, " is invalid."))
|
||||
};
|
||||
}
|
||||
|
||||
impl Spec {
|
||||
/// Convert engine spec into a arc'd Engine of the right underlying type.
|
||||
/// TODO avoid this hard-coded nastiness - use dynamic-linked plugin framework instead.
|
||||
@ -268,25 +274,17 @@ impl Spec {
|
||||
}
|
||||
|
||||
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus.
|
||||
pub fn new_test() -> Self {
|
||||
Spec::load(include_bytes!("../../res/null_morden.json") as &[u8]).expect("null_morden.json is invalid")
|
||||
}
|
||||
pub fn new_test() -> Spec { load_bundled!("null_morden") }
|
||||
|
||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is sha3('').
|
||||
pub fn new_null() -> Self {
|
||||
Spec::load(include_bytes!("../../res/null.json") as &[u8]).expect("null.json is invalid")
|
||||
}
|
||||
pub fn new_null() -> Spec { load_bundled!("null") }
|
||||
|
||||
/// Create a new Spec with InstantSeal consensus which does internal sealing (not requiring work).
|
||||
pub fn new_test_instant() -> Self {
|
||||
Spec::load(include_bytes!("../../res/instant_seal.json") as &[u8]).expect("instant_seal.json is invalid")
|
||||
}
|
||||
pub fn new_instant() -> Spec { load_bundled!("instant_seal") }
|
||||
|
||||
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not requiring work).
|
||||
/// Accounts with secrets "1".sha3() and "2".sha3() are the authorities.
|
||||
pub fn new_test_round() -> Self {
|
||||
Spec::load(include_bytes!("../../res/authority_round.json") as &[u8]).expect("authority_round.json is invalid")
|
||||
}
|
||||
pub fn new_test_round() -> Self { load_bundled!("authority_round") }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "parity.js",
|
||||
"version": "0.2.37",
|
||||
"version": "0.2.41",
|
||||
"main": "release/index.js",
|
||||
"jsnext:main": "src/index.js",
|
||||
"author": "Parity Team <admin@parity.io>",
|
||||
|
@ -21,3 +21,7 @@
|
||||
.iconMenu option {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
.menu {
|
||||
display: none;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import { Dialog, FlatButton } from 'material-ui';
|
||||
import AccountSelector from '../../Accounts/AccountSelector';
|
||||
import InputText from '../../Inputs/Text';
|
||||
|
||||
import { TOKEN_ADDRESS_TYPE, TLA_TYPE, UINT_TYPE, STRING_TYPE } from '../../Inputs/validation';
|
||||
import { TOKEN_ADDRESS_TYPE, TLA_TYPE, DECIMAL_TYPE, STRING_TYPE } from '../../Inputs/validation';
|
||||
|
||||
import styles from '../actions.css';
|
||||
|
||||
@ -41,11 +41,11 @@ const initState = {
|
||||
floatingLabelText: 'Token TLA',
|
||||
hintText: 'The token short name (3 characters)'
|
||||
},
|
||||
base: {
|
||||
decimals: {
|
||||
...defaultField,
|
||||
type: UINT_TYPE,
|
||||
floatingLabelText: 'Token Base',
|
||||
hintText: 'The token precision'
|
||||
type: DECIMAL_TYPE,
|
||||
floatingLabelText: 'Token Decimals',
|
||||
hintText: 'The number of decimals (0-18)'
|
||||
},
|
||||
name: {
|
||||
...defaultField,
|
||||
|
@ -47,7 +47,8 @@ export const registerToken = (tokenData) => (dispatch, getState) => {
|
||||
const contractInstance = state.status.contract.instance;
|
||||
const fee = state.status.contract.fee;
|
||||
|
||||
const { address, base, name, tla } = tokenData;
|
||||
const { address, decimals, name, tla } = tokenData;
|
||||
const base = Math.pow(10, decimals);
|
||||
|
||||
dispatch(setRegisterSending(true));
|
||||
|
||||
|
@ -32,6 +32,7 @@ export const SIMPLE_TOKEN_ADDRESS_TYPE = 'SIMPLE_TOKEN_ADDRESS_TYPE';
|
||||
export const TLA_TYPE = 'TLA_TYPE';
|
||||
export const SIMPLE_TLA_TYPE = 'SIMPLE_TLA_TYPE';
|
||||
export const UINT_TYPE = 'UINT_TYPE';
|
||||
export const DECIMAL_TYPE = 'DECIMAL_TYPE';
|
||||
export const STRING_TYPE = 'STRING_TYPE';
|
||||
export const HEX_TYPE = 'HEX_TYPE';
|
||||
export const URL_TYPE = 'URL_TYPE';
|
||||
@ -39,6 +40,7 @@ export const URL_TYPE = 'URL_TYPE';
|
||||
export const ERRORS = {
|
||||
invalidTLA: 'The TLA should be 3 characters long',
|
||||
invalidUint: 'Please enter a non-negative integer',
|
||||
invalidDecimal: 'Please enter a value between 0 and 18',
|
||||
invalidString: 'Please enter at least a character',
|
||||
invalidAccount: 'Please select an account to transact with',
|
||||
invalidRecipient: 'Please select an account to send to',
|
||||
@ -152,6 +154,21 @@ const validateUint = (uint) => {
|
||||
};
|
||||
};
|
||||
|
||||
const validateDecimal = (decimal) => {
|
||||
if (!/^\d+$/.test(decimal) || parseInt(decimal) < 0 || parseInt(decimal) > 18) {
|
||||
return {
|
||||
error: ERRORS.invalidDecimal,
|
||||
valid: false
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
value: parseInt(decimal),
|
||||
error: null,
|
||||
valid: true
|
||||
};
|
||||
};
|
||||
|
||||
const validateString = (string) => {
|
||||
if (string.toString().length === 0) {
|
||||
return {
|
||||
@ -204,6 +221,7 @@ export const validate = (value, type, contract) => {
|
||||
if (type === TLA_TYPE) return validateTLA(value, contract);
|
||||
if (type === SIMPLE_TLA_TYPE) return validateTLA(value, contract, true);
|
||||
if (type === UINT_TYPE) return validateUint(value);
|
||||
if (type === DECIMAL_TYPE) return validateDecimal(value);
|
||||
if (type === STRING_TYPE) return validateString(value);
|
||||
if (type === HEX_TYPE) return validateHex(value);
|
||||
if (type === URL_TYPE) return validateURL(value);
|
||||
|
@ -152,8 +152,8 @@ export default class Token extends Component {
|
||||
if (!base || base < 0) return null;
|
||||
return (
|
||||
<Chip
|
||||
value={ base.toString() }
|
||||
label='Base' />
|
||||
value={ Math.log10(base).toString() }
|
||||
label='Decimals' />
|
||||
);
|
||||
}
|
||||
|
||||
|
24
js/src/ui/CopyToClipboard/copyToClipboard.css
Normal file
24
js/src/ui/CopyToClipboard/copyToClipboard.css
Normal file
@ -0,0 +1,24 @@
|
||||
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
/* This file is part of Parity.
|
||||
/*
|
||||
/* Parity is free software: you can redistribute it and/or modify
|
||||
/* it under the terms of the GNU General Public License as published by
|
||||
/* the Free Software Foundation, either version 3 of the License, or
|
||||
/* (at your option) any later version.
|
||||
/*
|
||||
/* Parity is distributed in the hope that it will be useful,
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
/* GNU General Public License for more details.
|
||||
/*
|
||||
/* You should have received a copy of the GNU General Public License
|
||||
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
.wrapper {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.data {
|
||||
font-family: monospace;
|
||||
}
|
@ -16,15 +16,18 @@
|
||||
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { IconButton } from 'material-ui';
|
||||
import Snackbar from 'material-ui/Snackbar';
|
||||
import Clipboard from 'react-copy-to-clipboard';
|
||||
import CopyIcon from 'material-ui/svg-icons/content/content-copy';
|
||||
import Theme from '../Theme';
|
||||
import { darkBlack } from 'material-ui/styles/colors';
|
||||
const { textColor, disabledTextColor } = Theme.flatButton;
|
||||
|
||||
import styles from './copyToClipboard.css';
|
||||
|
||||
export default class CopyToClipboard extends Component {
|
||||
static propTypes = {
|
||||
data: PropTypes.string.isRequired,
|
||||
label: PropTypes.string,
|
||||
onCopy: PropTypes.func,
|
||||
size: PropTypes.number, // in px
|
||||
cooldown: PropTypes.number // in ms
|
||||
@ -32,32 +35,46 @@ export default class CopyToClipboard extends Component {
|
||||
|
||||
static defaultProps = {
|
||||
className: '',
|
||||
label: 'copy to clipboard',
|
||||
onCopy: () => {},
|
||||
size: 16,
|
||||
cooldown: 1000
|
||||
};
|
||||
|
||||
state = {
|
||||
copied: false
|
||||
copied: false,
|
||||
timeout: null
|
||||
};
|
||||
|
||||
componentWillUnmount () {
|
||||
const { timeoutId } = this.state;
|
||||
if (timeoutId) {
|
||||
window.clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { data, label, size } = this.props;
|
||||
const { data, size } = this.props;
|
||||
const { copied } = this.state;
|
||||
|
||||
return (
|
||||
<Clipboard onCopy={ this.onCopy } text={ data }>
|
||||
<IconButton
|
||||
tooltip={ copied ? 'done!' : label }
|
||||
disableTouchRipple
|
||||
tooltipPosition={ 'top-right' }
|
||||
tooltipStyles={ { marginTop: `-${size / 4}px` } }
|
||||
style={ { width: size, height: size, padding: '0' } }
|
||||
iconStyle={ { width: size, height: size } }
|
||||
>
|
||||
<CopyIcon color={ copied ? disabledTextColor : textColor } />
|
||||
</IconButton>
|
||||
<div className={ styles.wrapper }>
|
||||
<Snackbar
|
||||
open={ copied }
|
||||
message={
|
||||
<div>copied <code className={ styles.data }>{ data }</code> to clipboard</div>
|
||||
}
|
||||
autoHideDuration={ 2000 }
|
||||
bodyStyle={ { backgroundColor: darkBlack } }
|
||||
/>
|
||||
<IconButton
|
||||
disableTouchRipple
|
||||
style={ { width: size, height: size, padding: '0' } }
|
||||
iconStyle={ { width: size, height: size } }
|
||||
>
|
||||
<CopyIcon color={ copied ? disabledTextColor : textColor } />
|
||||
</IconButton>
|
||||
</div>
|
||||
</Clipboard>
|
||||
);
|
||||
}
|
||||
@ -65,11 +82,12 @@ export default class CopyToClipboard extends Component {
|
||||
onCopy = () => {
|
||||
const { cooldown, onCopy } = this.props;
|
||||
|
||||
this.setState({ copied: true });
|
||||
setTimeout(() => {
|
||||
this.setState({ copied: false });
|
||||
}, cooldown);
|
||||
|
||||
this.setState({
|
||||
copied: true,
|
||||
timeout: setTimeout(() => {
|
||||
this.setState({ copied: false, timeout: null });
|
||||
}, cooldown)
|
||||
});
|
||||
onCopy();
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import keycode from 'keycode';
|
||||
import { MenuItem, AutoComplete as MUIAutoComplete } from 'material-ui';
|
||||
import { PopoverAnimationVertical } from 'material-ui/Popover';
|
||||
|
||||
@ -40,7 +41,8 @@ export default class AutoComplete extends Component {
|
||||
state = {
|
||||
lastChangedValue: undefined,
|
||||
entry: null,
|
||||
open: false
|
||||
open: false,
|
||||
fakeBlur: false
|
||||
}
|
||||
|
||||
render () {
|
||||
@ -67,6 +69,9 @@ export default class AutoComplete extends Component {
|
||||
fullWidth
|
||||
floatingLabelFixed
|
||||
dataSource={ this.getDataSource() }
|
||||
menuProps={ { maxHeight: 400 } }
|
||||
ref='muiAutocomplete'
|
||||
onKeyDown={ this.onKeyDown }
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -91,6 +96,30 @@ export default class AutoComplete extends Component {
|
||||
}));
|
||||
}
|
||||
|
||||
onKeyDown = (event) => {
|
||||
const { muiAutocomplete } = this.refs;
|
||||
|
||||
switch (keycode(event)) {
|
||||
case 'down':
|
||||
const { menu } = muiAutocomplete.refs;
|
||||
menu.handleKeyDown(event);
|
||||
this.setState({ fakeBlur: true });
|
||||
break;
|
||||
|
||||
case 'enter':
|
||||
case 'tab':
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
event.which = 'useless';
|
||||
|
||||
const e = new CustomEvent('down');
|
||||
e.which = 40;
|
||||
|
||||
muiAutocomplete.handleKeyDown(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onChange = (item, idx) => {
|
||||
if (idx === -1) {
|
||||
return;
|
||||
@ -108,17 +137,22 @@ export default class AutoComplete extends Component {
|
||||
this.setState({ entry, open: false });
|
||||
}
|
||||
|
||||
onBlur = () => {
|
||||
onBlur = (event) => {
|
||||
const { onUpdateInput } = this.props;
|
||||
|
||||
// TODO: Handle blur gracefully where we use onUpdateInput (currently replaces input
|
||||
// TODO: Handle blur gracefully where we use onUpdateInput (currently replaces
|
||||
// input where text is allowed with the last selected value from the dropdown)
|
||||
if (!onUpdateInput) {
|
||||
window.setTimeout(() => {
|
||||
const { entry } = this.state;
|
||||
const { entry, fakeBlur } = this.state;
|
||||
|
||||
if (fakeBlur) {
|
||||
this.setState({ fakeBlur: false });
|
||||
return;
|
||||
}
|
||||
|
||||
this.handleOnChange(entry);
|
||||
}, 100);
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,4 @@
|
||||
|
||||
.copy {
|
||||
margin-right: 0.5em;
|
||||
|
||||
svg {
|
||||
transition: all .5s ease-in-out;
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,9 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { TextField } from 'material-ui';
|
||||
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import CopyIcon from 'material-ui/svg-icons/content/content-copy';
|
||||
import { TextField, IconButton } from 'material-ui';
|
||||
import { lightWhite, fullWhite } from 'material-ui/styles/colors';
|
||||
import CopyToClipboard from '../../CopyToClipboard';
|
||||
|
||||
import styles from './input.css';
|
||||
|
||||
@ -77,9 +75,7 @@ export default class Input extends Component {
|
||||
}
|
||||
|
||||
state = {
|
||||
value: this.props.value || '',
|
||||
timeoutId: null,
|
||||
copied: false
|
||||
value: this.props.value || ''
|
||||
}
|
||||
|
||||
componentWillReceiveProps (newProps) {
|
||||
@ -88,14 +84,6 @@ export default class Input extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
const { timeoutId } = this.state;
|
||||
|
||||
if (timeoutId) {
|
||||
window.clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { value } = this.state;
|
||||
const { children, className, hideUnderline, disabled, error, label, hint, multiLine, rows, type } = this.props;
|
||||
@ -151,7 +139,7 @@ export default class Input extends Component {
|
||||
|
||||
renderCopyButton () {
|
||||
const { allowCopy, hideUnderline, label, hint, floatCopy } = this.props;
|
||||
const { copied, value } = this.state;
|
||||
const { value } = this.state;
|
||||
|
||||
if (!allowCopy) {
|
||||
return null;
|
||||
@ -165,8 +153,6 @@ export default class Input extends Component {
|
||||
? allowCopy
|
||||
: value;
|
||||
|
||||
const scale = copied ? 'scale(1.15)' : 'scale(1)';
|
||||
|
||||
if (hideUnderline && !label) {
|
||||
style.marginBottom = 2;
|
||||
} else if (label && !hint) {
|
||||
@ -184,49 +170,11 @@ export default class Input extends Component {
|
||||
|
||||
return (
|
||||
<div className={ styles.copy } style={ style }>
|
||||
<CopyToClipboard
|
||||
onCopy={ this.handleCopy }
|
||||
text={ text } >
|
||||
<IconButton
|
||||
tooltip={ `${copied ? 'Copied' : 'Copy'} to clipboard` }
|
||||
tooltipPosition='bottom-right'
|
||||
style={ {
|
||||
width: 16,
|
||||
height: 16,
|
||||
padding: 0
|
||||
} }
|
||||
iconStyle={ {
|
||||
width: 16,
|
||||
height: 16,
|
||||
transform: scale
|
||||
} }
|
||||
tooltipStyles={ {
|
||||
top: 16
|
||||
} }
|
||||
>
|
||||
<CopyIcon
|
||||
color={ copied ? lightWhite : fullWhite }
|
||||
/>
|
||||
</IconButton>
|
||||
</CopyToClipboard>
|
||||
<CopyToClipboard data={ text } />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
handleCopy = () => {
|
||||
if (this.state.timeoutId) {
|
||||
window.clearTimeout(this.state.timeoutId);
|
||||
}
|
||||
|
||||
this.setState({ copied: true }, () => {
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
this.setState({ copied: false });
|
||||
}, 500);
|
||||
|
||||
this.setState({ timeoutId });
|
||||
});
|
||||
}
|
||||
|
||||
onChange = (event, value) => {
|
||||
this.setValue(value);
|
||||
|
||||
|
@ -43,6 +43,6 @@
|
||||
}
|
||||
|
||||
.address {
|
||||
white-space: nowrap;
|
||||
font-family: monospace;
|
||||
display: inline-block;
|
||||
margin-left: .5em;
|
||||
}
|
||||
|
@ -15,13 +15,9 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import IconButton from 'material-ui/IconButton';
|
||||
import Snackbar from 'material-ui/Snackbar';
|
||||
import CopyIcon from 'material-ui/svg-icons/content/content-copy';
|
||||
import { lightWhite, fullWhite, darkBlack } from 'material-ui/styles/colors';
|
||||
|
||||
import { Balance, Container, ContainerTitle, IdentityIcon, IdentityName, Tags } from '../../../ui';
|
||||
import CopyToClipboard from '../../../ui/CopyToClipboard';
|
||||
|
||||
import styles from './header.css';
|
||||
|
||||
@ -37,8 +33,7 @@ export default class Header extends Component {
|
||||
}
|
||||
|
||||
state = {
|
||||
name: null,
|
||||
addressCopied: false
|
||||
name: null
|
||||
}
|
||||
|
||||
componentWillMount () {
|
||||
@ -51,7 +46,6 @@ export default class Header extends Component {
|
||||
|
||||
render () {
|
||||
const { account, balance } = this.props;
|
||||
const { addressCopied } = this.state;
|
||||
const { address, meta, uuid } = account;
|
||||
|
||||
if (!account) {
|
||||
@ -64,50 +58,14 @@ export default class Header extends Component {
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
<Snackbar
|
||||
open={ addressCopied }
|
||||
message={
|
||||
<span>
|
||||
Address
|
||||
<span className={ styles.address }> { address } </span>
|
||||
copied to clipboard
|
||||
</span>
|
||||
}
|
||||
autoHideDuration={ 4000 }
|
||||
onRequestClose={ this.handleCopyAddressClose }
|
||||
bodyStyle={ {
|
||||
backgroundColor: darkBlack
|
||||
} }
|
||||
/>
|
||||
|
||||
<Container>
|
||||
<IdentityIcon
|
||||
address={ address } />
|
||||
<div className={ styles.floatleft }>
|
||||
<ContainerTitle title={ <IdentityName address={ address } unknown /> } />
|
||||
<div className={ styles.addressline }>
|
||||
<CopyToClipboard
|
||||
onCopy={ this.handleCopyAddress }
|
||||
text={ address } >
|
||||
<IconButton
|
||||
tooltip='Copy address to clipboard'
|
||||
tooltipPosition='top-center'
|
||||
style={ {
|
||||
width: 32,
|
||||
height: 16,
|
||||
padding: 0
|
||||
} }
|
||||
iconStyle={ {
|
||||
width: 16,
|
||||
height: 16
|
||||
} }>
|
||||
<CopyIcon
|
||||
color={ addressCopied ? lightWhite : fullWhite }
|
||||
/>
|
||||
</IconButton>
|
||||
</CopyToClipboard>
|
||||
<span>{ address } </span>
|
||||
<CopyToClipboard data={ address } />
|
||||
<div className={ styles.address }>{ address }</div>
|
||||
</div>
|
||||
{ uuidText }
|
||||
<div className={ styles.infoline }>
|
||||
@ -157,14 +115,6 @@ export default class Header extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
handleCopyAddress = () => {
|
||||
this.setState({ addressCopied: true });
|
||||
}
|
||||
|
||||
handleCopyAddressClose = () => {
|
||||
this.setState({ addressCopied: false });
|
||||
}
|
||||
|
||||
setName () {
|
||||
const { account } = this.props;
|
||||
|
||||
|
@ -32,8 +32,8 @@ Operating Options:
|
||||
(default: {flag_mode_alarm}).
|
||||
--chain CHAIN Specify the blockchain type. CHAIN may be either a
|
||||
JSON chain specification file or olympic, frontier,
|
||||
homestead, mainnet, morden, classic, expanse or
|
||||
testnet (default: {flag_chain}).
|
||||
homestead, mainnet, morden, classic, expanse,
|
||||
testnet or dev (default: {flag_chain}).
|
||||
-d --db-path PATH Specify the database & configuration directory path
|
||||
(default: {flag_db_path}).
|
||||
--keys-path PATH Specify the path for JSON key files to be found
|
||||
|
@ -31,6 +31,7 @@ pub enum SpecType {
|
||||
Olympic,
|
||||
Classic,
|
||||
Expanse,
|
||||
Dev,
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
@ -50,6 +51,7 @@ impl str::FromStr for SpecType {
|
||||
"morden" | "testnet" => SpecType::Testnet,
|
||||
"olympic" => SpecType::Olympic,
|
||||
"expanse" => SpecType::Expanse,
|
||||
"dev" => SpecType::Dev,
|
||||
other => SpecType::Custom(other.into()),
|
||||
};
|
||||
Ok(spec)
|
||||
@ -64,6 +66,7 @@ impl SpecType {
|
||||
SpecType::Olympic => Ok(ethereum::new_olympic()),
|
||||
SpecType::Classic => Ok(ethereum::new_classic()),
|
||||
SpecType::Expanse => Ok(ethereum::new_expanse()),
|
||||
SpecType::Dev => Ok(Spec::new_instant()),
|
||||
SpecType::Custom(ref filename) => {
|
||||
let file = try!(fs::File::open(filename).map_err(|_| "Could not load specification file."));
|
||||
Spec::load(file)
|
||||
|
@ -24,7 +24,7 @@
|
||||
#![feature(asm)]
|
||||
|
||||
extern crate test;
|
||||
extern crate bigint;
|
||||
extern crate ethcore_bigint as bigint;
|
||||
|
||||
use test::{Bencher, black_box};
|
||||
use bigint::uint::{U256, U512, Uint, U128};
|
||||
|
@ -23,12 +23,13 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
extern crate ethcore_util;
|
||||
extern crate rlp;
|
||||
extern crate ethcore_bigint as bigint;
|
||||
|
||||
use test::Bencher;
|
||||
use std::str::FromStr;
|
||||
use ethcore_util::rlp::*;
|
||||
use ethcore_util::U256;
|
||||
use rlp::*;
|
||||
use bigint::uint::U256;
|
||||
|
||||
#[bench]
|
||||
fn bench_stream_u64_value(b: &mut Bencher) {
|
||||
|
Loading…
Reference in New Issue
Block a user