Merge branch 'master' into pip-msg
This commit is contained in:
commit
e99884d0c0
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -406,6 +406,7 @@ dependencies = [
|
|||||||
"linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lru-cache 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lru-cache 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num_cpus 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num_cpus 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rlp 0.1.0",
|
"rlp 0.1.0",
|
||||||
@ -1696,7 +1697,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-ui-precompiled"
|
name = "parity-ui-precompiled"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
source = "git+https://github.com/ethcore/js-precompiled.git#7039b5b8e44196718333dc3fcdfcadae2a97c7fd"
|
source = "git+https://github.com/ethcore/js-precompiled.git#47da49294ad958933e85a9c4f0f2bb4df5dc47de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
@ -44,6 +44,7 @@ ethcore-stratum = { path = "../stratum" }
|
|||||||
ethcore-bloom-journal = { path = "../util/bloom" }
|
ethcore-bloom-journal = { path = "../util/bloom" }
|
||||||
hardware-wallet = { path = "../hw" }
|
hardware-wallet = { path = "../hw" }
|
||||||
stats = { path = "../util/stats" }
|
stats = { path = "../util/stats" }
|
||||||
|
num = "0.1"
|
||||||
|
|
||||||
[dependencies.hyper]
|
[dependencies.hyper]
|
||||||
git = "https://github.com/ethcore/hyper"
|
git = "https://github.com/ethcore/hyper"
|
||||||
|
@ -189,6 +189,7 @@
|
|||||||
"0000000000000000000000000000000000000002": { "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
"0000000000000000000000000000000000000002": { "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
||||||
"0000000000000000000000000000000000000003": { "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
"0000000000000000000000000000000000000003": { "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
||||||
"0000000000000000000000000000000000000004": { "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
"0000000000000000000000000000000000000004": { "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
||||||
|
"0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "0x7fffffffffffff", "pricing": { "modexp": { "divisor": 20 } } } },
|
||||||
"3282791d6fd713f1e94f4bfd565eaa78b3a0599d": {
|
"3282791d6fd713f1e94f4bfd565eaa78b3a0599d": {
|
||||||
"balance": "1337000000000000000000"
|
"balance": "1337000000000000000000"
|
||||||
},
|
},
|
||||||
|
@ -14,11 +14,16 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use std::cmp::{max, min};
|
||||||
|
use std::io::{self, Read};
|
||||||
|
|
||||||
|
use byteorder::{ByteOrder, BigEndian};
|
||||||
use crypto::sha2::Sha256 as Sha256Digest;
|
use crypto::sha2::Sha256 as Sha256Digest;
|
||||||
use crypto::ripemd160::Ripemd160 as Ripemd160Digest;
|
use crypto::ripemd160::Ripemd160 as Ripemd160Digest;
|
||||||
use crypto::digest::Digest;
|
use crypto::digest::Digest;
|
||||||
use std::cmp::min;
|
use num::{BigUint, Zero, One};
|
||||||
use util::{U256, H256, Hashable, BytesRef};
|
|
||||||
|
use util::{U256, H256, Uint, Hashable, BytesRef};
|
||||||
use ethkey::{Signature, recover as ec_recover};
|
use ethkey::{Signature, recover as ec_recover};
|
||||||
use ethjson;
|
use ethjson;
|
||||||
|
|
||||||
@ -30,8 +35,8 @@ pub trait Impl: Send + Sync {
|
|||||||
|
|
||||||
/// A gas pricing scheme for built-in contracts.
|
/// A gas pricing scheme for built-in contracts.
|
||||||
pub trait Pricer: Send + Sync {
|
pub trait Pricer: Send + Sync {
|
||||||
/// The gas cost of running this built-in for the given size of input data.
|
/// The gas cost of running this built-in for the given input data.
|
||||||
fn cost(&self, in_size: usize) -> U256;
|
fn cost(&self, input: &[u8]) -> U256;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A linear pricing model. This computes a price using a base cost and a cost per-word.
|
/// A linear pricing model. This computes a price using a base cost and a cost per-word.
|
||||||
@ -40,40 +45,94 @@ struct Linear {
|
|||||||
word: usize,
|
word: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A special pricing model for modular exponentiation.
|
||||||
|
struct Modexp {
|
||||||
|
divisor: usize,
|
||||||
|
}
|
||||||
|
|
||||||
impl Pricer for Linear {
|
impl Pricer for Linear {
|
||||||
fn cost(&self, in_size: usize) -> U256 {
|
fn cost(&self, input: &[u8]) -> U256 {
|
||||||
U256::from(self.base) + U256::from(self.word) * U256::from((in_size + 31) / 32)
|
U256::from(self.base) + U256::from(self.word) * U256::from((input.len() + 31) / 32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pricing scheme and execution definition for a built-in contract.
|
impl Pricer for Modexp {
|
||||||
|
fn cost(&self, input: &[u8]) -> U256 {
|
||||||
|
let mut reader = input.chain(io::repeat(0));
|
||||||
|
let mut buf = [0; 32];
|
||||||
|
|
||||||
|
// read lengths as U256 here for accurate gas calculation.
|
||||||
|
let mut read_len = || {
|
||||||
|
reader.read_exact(&mut buf[..]).expect("reading from zero-extended memory cannot fail; qed");
|
||||||
|
U256::from(H256::from_slice(&buf[..]))
|
||||||
|
};
|
||||||
|
let base_len = read_len();
|
||||||
|
let exp_len = read_len();
|
||||||
|
let mod_len = read_len();
|
||||||
|
|
||||||
|
// floor(max(length_of_MODULUS, length_of_BASE) ** 2 * max(length_of_EXPONENT, 1) / GQUADDIVISOR)
|
||||||
|
// TODO: is saturating the best behavior here?
|
||||||
|
let m = max(mod_len, base_len);
|
||||||
|
match m.overflowing_mul(m) {
|
||||||
|
(_, true) => U256::max_value(),
|
||||||
|
(val, _) => {
|
||||||
|
match val.overflowing_mul(max(exp_len, U256::one())) {
|
||||||
|
(_, true) => U256::max_value(),
|
||||||
|
(val, _) => val / (self.divisor as u64).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pricing scheme, execution definition, and activation block for a built-in contract.
|
||||||
|
///
|
||||||
|
/// Call `cost` to compute cost for the given input, `execute` to execute the contract
|
||||||
|
/// on the given input, and `is_active` to determine whether the contract is active.
|
||||||
|
///
|
||||||
|
/// Unless `is_active` is true,
|
||||||
pub struct Builtin {
|
pub struct Builtin {
|
||||||
pricer: Box<Pricer>,
|
pricer: Box<Pricer>,
|
||||||
native: Box<Impl>,
|
native: Box<Impl>,
|
||||||
|
activate_at: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Builtin {
|
impl Builtin {
|
||||||
/// Simple forwarder for cost.
|
/// Simple forwarder for cost.
|
||||||
pub fn cost(&self, s: usize) -> U256 { self.pricer.cost(s) }
|
pub fn cost(&self, input: &[u8]) -> U256 { self.pricer.cost(input) }
|
||||||
|
|
||||||
/// Simple forwarder for execute.
|
/// Simple forwarder for execute.
|
||||||
pub fn execute(&self, input: &[u8], output: &mut BytesRef) { self.native.execute(input, output) }
|
pub fn execute(&self, input: &[u8], output: &mut BytesRef) { self.native.execute(input, output) }
|
||||||
|
|
||||||
|
/// Whether the builtin is activated at the given block number.
|
||||||
|
pub fn is_active(&self, at: u64) -> bool { at >= self.activate_at }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ethjson::spec::Builtin> for Builtin {
|
impl From<ethjson::spec::Builtin> for Builtin {
|
||||||
fn from(b: ethjson::spec::Builtin) -> Self {
|
fn from(b: ethjson::spec::Builtin) -> Self {
|
||||||
let pricer = match b.pricing {
|
let pricer: Box<Pricer> = match b.pricing {
|
||||||
ethjson::spec::Pricing::Linear(linear) => {
|
ethjson::spec::Pricing::Linear(linear) => {
|
||||||
Box::new(Linear {
|
Box::new(Linear {
|
||||||
base: linear.base,
|
base: linear.base,
|
||||||
word: linear.word,
|
word: linear.word,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
ethjson::spec::Pricing::Modexp(exp) => {
|
||||||
|
Box::new(Modexp {
|
||||||
|
divisor: if exp.divisor == 0 {
|
||||||
|
warn!("Zero modexp divisor specified. Falling back to default.");
|
||||||
|
10
|
||||||
|
} else {
|
||||||
|
exp.divisor
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Builtin {
|
Builtin {
|
||||||
pricer: pricer,
|
pricer: pricer,
|
||||||
native: ethereum_builtin(&b.name),
|
native: ethereum_builtin(&b.name),
|
||||||
|
activate_at: b.activate_at.map(Into::into).unwrap_or(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,6 +144,7 @@ fn ethereum_builtin(name: &str) -> Box<Impl> {
|
|||||||
"ecrecover" => Box::new(EcRecover) as Box<Impl>,
|
"ecrecover" => Box::new(EcRecover) as Box<Impl>,
|
||||||
"sha256" => Box::new(Sha256) as Box<Impl>,
|
"sha256" => Box::new(Sha256) as Box<Impl>,
|
||||||
"ripemd160" => Box::new(Ripemd160) as Box<Impl>,
|
"ripemd160" => Box::new(Ripemd160) as Box<Impl>,
|
||||||
|
"modexp" => Box::new(ModexpImpl) as Box<Impl>,
|
||||||
_ => panic!("invalid builtin name: {}", name),
|
_ => panic!("invalid builtin name: {}", name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,6 +155,7 @@ fn ethereum_builtin(name: &str) -> Box<Impl> {
|
|||||||
// - ec recovery
|
// - ec recovery
|
||||||
// - sha256
|
// - sha256
|
||||||
// - ripemd160
|
// - ripemd160
|
||||||
|
// - modexp (EIP198)
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Identity;
|
struct Identity;
|
||||||
@ -108,6 +169,9 @@ struct Sha256;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Ripemd160;
|
struct Ripemd160;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ModexpImpl;
|
||||||
|
|
||||||
impl Impl for Identity {
|
impl Impl for Identity {
|
||||||
fn execute(&self, input: &[u8], output: &mut BytesRef) {
|
fn execute(&self, input: &[u8], output: &mut BytesRef) {
|
||||||
output.write(0, input);
|
output.write(0, input);
|
||||||
@ -166,9 +230,76 @@ impl Impl for Ripemd160 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Impl for ModexpImpl {
|
||||||
|
fn execute(&self, input: &[u8], output: &mut BytesRef) {
|
||||||
|
let mut reader = input.chain(io::repeat(0));
|
||||||
|
let mut buf = [0; 32];
|
||||||
|
|
||||||
|
// read lengths as usize.
|
||||||
|
// ignoring the first 24 bytes might technically lead us to fall out of consensus,
|
||||||
|
// but so would running out of addressable memory!
|
||||||
|
let mut read_len = |reader: &mut io::Chain<&[u8], io::Repeat>| {
|
||||||
|
reader.read_exact(&mut buf[..]).expect("reading from zero-extended memory cannot fail; qed");
|
||||||
|
BigEndian::read_u64(&buf[24..]) as usize
|
||||||
|
};
|
||||||
|
|
||||||
|
let base_len = read_len(&mut reader);
|
||||||
|
let exp_len = read_len(&mut reader);
|
||||||
|
let mod_len = read_len(&mut reader);
|
||||||
|
|
||||||
|
// read the numbers themselves.
|
||||||
|
let mut buf = vec![0; max(mod_len, max(base_len, exp_len))];
|
||||||
|
let mut read_num = |len| {
|
||||||
|
reader.read_exact(&mut buf[..len]).expect("reading from zero-extended memory cannot fail; qed");
|
||||||
|
BigUint::from_bytes_be(&buf[..len])
|
||||||
|
};
|
||||||
|
|
||||||
|
let base = read_num(base_len);
|
||||||
|
let exp = read_num(exp_len);
|
||||||
|
let modulus = read_num(mod_len);
|
||||||
|
|
||||||
|
// calculate modexp: exponentiation by squaring.
|
||||||
|
fn modexp(mut base: BigUint, mut exp: BigUint, modulus: BigUint) -> BigUint {
|
||||||
|
match (base == BigUint::zero(), exp == BigUint::zero()) {
|
||||||
|
(_, true) => return BigUint::one(), // n^0 % m
|
||||||
|
(true, false) => return BigUint::zero(), // 0^n % m, n>0
|
||||||
|
(false, false) if modulus <= BigUint::one() => return BigUint::zero(), // a^b % 1 = 0.
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut result = BigUint::one();
|
||||||
|
base = base % &modulus;
|
||||||
|
|
||||||
|
// fast path for base divisible by modulus.
|
||||||
|
if base == BigUint::zero() { return result }
|
||||||
|
while exp != BigUint::zero() {
|
||||||
|
// exp has to be on the right here to avoid move.
|
||||||
|
if BigUint::one() & &exp == BigUint::one() {
|
||||||
|
result = (result * &base) % &modulus;
|
||||||
|
}
|
||||||
|
|
||||||
|
exp = exp >> 1;
|
||||||
|
base = (base.clone() * base) % &modulus;
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
// write output to given memory, left padded and same length as the modulus.
|
||||||
|
let bytes = modexp(base, exp, modulus).to_bytes_be();
|
||||||
|
|
||||||
|
// always true except in the case of zero-length modulus, which leads to
|
||||||
|
// output of length and value 1.
|
||||||
|
if bytes.len() <= mod_len {
|
||||||
|
let res_start = mod_len - bytes.len();
|
||||||
|
output.write(res_start, &bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Builtin, Linear, ethereum_builtin, Pricer};
|
use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp};
|
||||||
use ethjson;
|
use ethjson;
|
||||||
use util::{U256, BytesRef};
|
use util::{U256, BytesRef};
|
||||||
|
|
||||||
@ -295,24 +426,126 @@ mod tests {
|
|||||||
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);*/
|
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn modexp() {
|
||||||
|
use rustc_serialize::hex::FromHex;
|
||||||
|
|
||||||
|
let f = Builtin {
|
||||||
|
pricer: Box::new(Modexp { divisor: 20 }),
|
||||||
|
native: ethereum_builtin("modexp"),
|
||||||
|
activate_at: 0,
|
||||||
|
};
|
||||||
|
// fermat's little theorem example.
|
||||||
|
{
|
||||||
|
let input = FromHex::from_hex("\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000001\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000020\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000020\
|
||||||
|
03\
|
||||||
|
fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e\
|
||||||
|
fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
let mut output = vec![0u8; 32];
|
||||||
|
let expected = FromHex::from_hex("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
|
||||||
|
let expected_cost = 1638;
|
||||||
|
|
||||||
|
f.execute(&input[..], &mut BytesRef::Fixed(&mut output[..]));
|
||||||
|
assert_eq!(output, expected);
|
||||||
|
assert_eq!(f.cost(&input[..]), expected_cost.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// second example from EIP: zero base.
|
||||||
|
{
|
||||||
|
let input = FromHex::from_hex("\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000020\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000020\
|
||||||
|
fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e\
|
||||||
|
fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
let mut output = vec![0u8; 32];
|
||||||
|
let expected = FromHex::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
||||||
|
let expected_cost = 1638;
|
||||||
|
|
||||||
|
f.execute(&input[..], &mut BytesRef::Fixed(&mut output[..]));
|
||||||
|
assert_eq!(output, expected);
|
||||||
|
assert_eq!(f.cost(&input[..]), expected_cost.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// another example from EIP: zero-padding
|
||||||
|
{
|
||||||
|
let input = FromHex::from_hex("\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000001\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000002\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000020\
|
||||||
|
03\
|
||||||
|
ffff\
|
||||||
|
80"
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
let mut output = vec![0u8; 32];
|
||||||
|
let expected = FromHex::from_hex("3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab").unwrap();
|
||||||
|
let expected_cost = 102;
|
||||||
|
|
||||||
|
f.execute(&input[..], &mut BytesRef::Fixed(&mut output[..]));
|
||||||
|
assert_eq!(output, expected);
|
||||||
|
assert_eq!(f.cost(&input[..]), expected_cost.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// zero-length modulus.
|
||||||
|
{
|
||||||
|
let input = FromHex::from_hex("\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000001\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000002\
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000\
|
||||||
|
03\
|
||||||
|
ffff"
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
let mut output = vec![];
|
||||||
|
let expected_cost = 0;
|
||||||
|
|
||||||
|
f.execute(&input[..], &mut BytesRef::Flexible(&mut output));
|
||||||
|
assert_eq!(output.len(), 0); // shouldn't have written any output.
|
||||||
|
assert_eq!(f.cost(&input[..]), expected_cost.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn from_unknown_linear() {
|
fn from_unknown_linear() {
|
||||||
let _ = ethereum_builtin("foo");
|
let _ = ethereum_builtin("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_active() {
|
||||||
|
let pricer = Box::new(Linear { base: 10, word: 20} );
|
||||||
|
let b = Builtin {
|
||||||
|
pricer: pricer as Box<Pricer>,
|
||||||
|
native: ethereum_builtin("identity"),
|
||||||
|
activate_at: 100_000,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(!b.is_active(99_999));
|
||||||
|
assert!(b.is_active(100_000));
|
||||||
|
assert!(b.is_active(100_001));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_named_linear() {
|
fn from_named_linear() {
|
||||||
let pricer = Box::new(Linear { base: 10, word: 20 });
|
let pricer = Box::new(Linear { base: 10, word: 20 });
|
||||||
let b = Builtin {
|
let b = Builtin {
|
||||||
pricer: pricer as Box<Pricer>,
|
pricer: pricer as Box<Pricer>,
|
||||||
native: ethereum_builtin("identity"),
|
native: ethereum_builtin("identity"),
|
||||||
|
activate_at: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(b.cost(0), U256::from(10));
|
assert_eq!(b.cost(&[0; 0]), U256::from(10));
|
||||||
assert_eq!(b.cost(1), U256::from(30));
|
assert_eq!(b.cost(&[0; 1]), U256::from(30));
|
||||||
assert_eq!(b.cost(32), U256::from(30));
|
assert_eq!(b.cost(&[0; 32]), U256::from(30));
|
||||||
assert_eq!(b.cost(33), U256::from(50));
|
assert_eq!(b.cost(&[0; 33]), U256::from(50));
|
||||||
|
|
||||||
let i = [0u8, 1, 2, 3];
|
let i = [0u8, 1, 2, 3];
|
||||||
let mut o = [255u8; 4];
|
let mut o = [255u8; 4];
|
||||||
@ -327,13 +560,14 @@ mod tests {
|
|||||||
pricing: ethjson::spec::Pricing::Linear(ethjson::spec::Linear {
|
pricing: ethjson::spec::Pricing::Linear(ethjson::spec::Linear {
|
||||||
base: 10,
|
base: 10,
|
||||||
word: 20,
|
word: 20,
|
||||||
})
|
}),
|
||||||
|
activate_at: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(b.cost(0), U256::from(10));
|
assert_eq!(b.cost(&[0; 0]), U256::from(10));
|
||||||
assert_eq!(b.cost(1), U256::from(30));
|
assert_eq!(b.cost(&[0; 1]), U256::from(30));
|
||||||
assert_eq!(b.cost(32), U256::from(30));
|
assert_eq!(b.cost(&[0; 32]), U256::from(30));
|
||||||
assert_eq!(b.cost(33), U256::from(50));
|
assert_eq!(b.cost(&[0; 33]), U256::from(50));
|
||||||
|
|
||||||
let i = [0u8, 1, 2, 3];
|
let i = [0u8, 1, 2, 3];
|
||||||
let mut o = [255u8; 4];
|
let mut o = [255u8; 4];
|
||||||
|
@ -189,19 +189,14 @@ pub trait Engine : Sync + Send {
|
|||||||
/// updating consensus state and potentially issuing a new one.
|
/// updating consensus state and potentially issuing a new one.
|
||||||
fn handle_message(&self, _message: &[u8]) -> Result<(), Error> { Err(EngineError::UnexpectedMessage.into()) }
|
fn handle_message(&self, _message: &[u8]) -> Result<(), Error> { Err(EngineError::UnexpectedMessage.into()) }
|
||||||
|
|
||||||
|
/// Attempt to get a handle to a built-in contract.
|
||||||
|
/// Only returns references to activated built-ins.
|
||||||
// TODO: builtin contract routing - to do this properly, it will require removing the built-in configuration-reading logic
|
// TODO: builtin contract routing - to do this properly, it will require removing the built-in configuration-reading logic
|
||||||
// from Spec into here and removing the Spec::builtins field.
|
// from Spec into here and removing the Spec::builtins field.
|
||||||
/// Determine whether a particular address is a builtin contract.
|
fn builtin(&self, a: &Address, block_number: ::header::BlockNumber) -> Option<&Builtin> {
|
||||||
fn is_builtin(&self, a: &Address) -> bool { self.builtins().contains_key(a) }
|
self.builtins()
|
||||||
/// Determine the code execution cost of the builtin contract with address `a`.
|
.get(a)
|
||||||
/// Panics if `is_builtin(a)` is not true.
|
.and_then(|b| if b.is_active(block_number) { Some(b) } else { None })
|
||||||
fn cost_of_builtin(&self, a: &Address, input: &[u8]) -> U256 {
|
|
||||||
self.builtins().get(a).expect("queried cost of nonexistent builtin").cost(input.len())
|
|
||||||
}
|
|
||||||
/// Execution the builtin contract `a` on `input` and return `output`.
|
|
||||||
/// Panics if `is_builtin(a)` is not true.
|
|
||||||
fn execute_builtin(&self, a: &Address, input: &[u8], output: &mut BytesRef) {
|
|
||||||
self.builtins().get(a).expect("attempted to execute nonexistent builtin").execute(input, output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find out if the block is a proposal block and should not be inserted into the DB.
|
/// Find out if the block is a proposal block and should not be inserted into the DB.
|
||||||
|
@ -261,17 +261,22 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
|
|||||||
}
|
}
|
||||||
trace!("Executive::call(params={:?}) self.env_info={:?}", params, self.info);
|
trace!("Executive::call(params={:?}) self.env_info={:?}", params, self.info);
|
||||||
|
|
||||||
if self.engine.is_builtin(¶ms.code_address) {
|
// if destination is builtin, try to execute it
|
||||||
// if destination is builtin, try to execute it
|
if let Some(builtin) = self.engine.builtin(¶ms.code_address, self.info.number) {
|
||||||
|
// Engines aren't supposed to return builtins until activation, but
|
||||||
|
// prefer to fail rather than silently break consensus.
|
||||||
|
if !builtin.is_active(self.info.number) {
|
||||||
|
panic!("Consensus failure: engine implementation prematurely enabled built-in at {}", params.code_address);
|
||||||
|
}
|
||||||
|
|
||||||
let default = [];
|
let default = [];
|
||||||
let data = if let Some(ref d) = params.data { d as &[u8] } else { &default as &[u8] };
|
let data = if let Some(ref d) = params.data { d as &[u8] } else { &default as &[u8] };
|
||||||
|
|
||||||
let trace_info = tracer.prepare_trace_call(¶ms);
|
let trace_info = tracer.prepare_trace_call(¶ms);
|
||||||
|
|
||||||
let cost = self.engine.cost_of_builtin(¶ms.code_address, data);
|
let cost = builtin.cost(data);
|
||||||
if cost <= params.gas {
|
if cost <= params.gas {
|
||||||
self.engine.execute_builtin(¶ms.code_address, data, &mut output);
|
builtin.execute(data, &mut output);
|
||||||
self.state.discard_checkpoint();
|
self.state.discard_checkpoint();
|
||||||
|
|
||||||
// trace only top level calls to builtins to avoid DDoS attacks
|
// trace only top level calls to builtins to avoid DDoS attacks
|
||||||
|
@ -106,6 +106,7 @@ extern crate ethcore_stratum;
|
|||||||
extern crate ethabi;
|
extern crate ethabi;
|
||||||
extern crate hardware_wallet;
|
extern crate hardware_wallet;
|
||||||
extern crate stats;
|
extern crate stats;
|
||||||
|
extern crate num;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "parity.js",
|
"name": "parity.js",
|
||||||
"version": "1.7.19",
|
"version": "1.7.22",
|
||||||
"main": "release/index.js",
|
"main": "release/index.js",
|
||||||
"jsnext:main": "src/index.js",
|
"jsnext:main": "src/index.js",
|
||||||
"author": "Parity Team <admin@parity.io>",
|
"author": "Parity Team <admin@parity.io>",
|
||||||
|
@ -23,6 +23,7 @@ import CircularProgress from 'material-ui/CircularProgress';
|
|||||||
import { Card, CardText } from 'material-ui/Card';
|
import { Card, CardText } from 'material-ui/Card';
|
||||||
|
|
||||||
import { nullableProptype } from '~/util/proptypes';
|
import { nullableProptype } from '~/util/proptypes';
|
||||||
|
import { api } from '../parity';
|
||||||
|
|
||||||
import styles from './application.css';
|
import styles from './application.css';
|
||||||
import Accounts from '../Accounts';
|
import Accounts from '../Accounts';
|
||||||
@ -39,7 +40,7 @@ export default class Application extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getChildContext () {
|
getChildContext () {
|
||||||
return { muiTheme, api: window.parity.api };
|
return { muiTheme, api };
|
||||||
}
|
}
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -49,7 +50,6 @@ export default class Application extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { api } = window.parity;
|
|
||||||
const { contract, fee } = this.props;
|
const { contract, fee } = this.props;
|
||||||
let warning = null;
|
let warning = null;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const { api } = window.parity;
|
import { api } from '../parity';
|
||||||
|
|
||||||
export const SET_ACCOUNTS = 'SET_ACCOUNTS';
|
export const SET_ACCOUNTS = 'SET_ACCOUNTS';
|
||||||
export const setAccounts = (accounts) => ({
|
export const setAccounts = (accounts) => ({
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
import Contracts from '~/contracts';
|
import Contracts from '~/contracts';
|
||||||
|
|
||||||
import { loadToken, setTokenPending, deleteToken, setTokenData } from '../Tokens/actions';
|
import { loadToken, setTokenPending, deleteToken, setTokenData } from '../Tokens/actions';
|
||||||
|
import { api } from '../parity';
|
||||||
const { api } = window.parity;
|
|
||||||
|
|
||||||
export const SET_LOADING = 'SET_LOADING';
|
export const SET_LOADING = 'SET_LOADING';
|
||||||
export const setLoading = (isLoading) => ({
|
export const setLoading = (isLoading) => ({
|
||||||
|
@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
|
||||||
|
import { api } from '../parity';
|
||||||
import Chip from '../Chip';
|
import Chip from '../Chip';
|
||||||
|
|
||||||
import styles from './status.css';
|
import styles from './status.css';
|
||||||
|
|
||||||
const { api } = window.parity;
|
|
||||||
|
|
||||||
export default class Status extends Component {
|
export default class Status extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
address: PropTypes.string.isRequired,
|
address: PropTypes.string.isRequired,
|
||||||
|
@ -16,8 +16,9 @@
|
|||||||
|
|
||||||
import { URL_TYPE } from '../Inputs/validation';
|
import { URL_TYPE } from '../Inputs/validation';
|
||||||
import { getTokenTotalSupply, urlToHash } from '../utils';
|
import { getTokenTotalSupply, urlToHash } from '../utils';
|
||||||
|
import { api } from '../parity';
|
||||||
|
|
||||||
const { bytesToHex } = window.parity.api.util;
|
const { bytesToHex } = api.util;
|
||||||
|
|
||||||
export const SET_TOKENS_LOADING = 'SET_TOKENS_LOADING';
|
export const SET_TOKENS_LOADING = 'SET_TOKENS_LOADING';
|
||||||
export const setTokensLoading = (isLoading) => ({
|
export const setTokensLoading = (isLoading) => ({
|
||||||
|
@ -77,7 +77,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.form {
|
.form {
|
||||||
|
box-sizing: border-box;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
padding: 0.75rem 1.5rem 1.5rem 1.5rem;
|
padding: 0.75rem 1.5rem 1.5rem;
|
||||||
background-color: rgba(255, 255, 255, 0.05);
|
background-color: rgba(255, 255, 255, 0.05);
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ export default class SecureApi extends Api {
|
|||||||
this.transport.updateToken(token, false);
|
this.transport.updateToken(token, false);
|
||||||
log.debug('connecting with token', token);
|
log.debug('connecting with token', token);
|
||||||
|
|
||||||
return this.transport.connect()
|
const connectPromise = this.transport.connect()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log.debug('connected with', token);
|
log.debug('connected with', token);
|
||||||
|
|
||||||
@ -258,26 +258,35 @@ export default class SecureApi extends Api {
|
|||||||
log.debug('did not connect ; error', error);
|
log.debug('did not connect ; error', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the Node is up
|
return false;
|
||||||
return this.isNodeUp()
|
});
|
||||||
.then((isNodeUp) => {
|
|
||||||
// If it's not up, try again in a few...
|
|
||||||
if (!isNodeUp) {
|
|
||||||
const timeout = this.transport.retryTimeout;
|
|
||||||
|
|
||||||
log.debug('node is not up ; will try again in', timeout, 'ms');
|
return Promise
|
||||||
|
.all([
|
||||||
|
connectPromise,
|
||||||
|
this.isNodeUp()
|
||||||
|
])
|
||||||
|
.then(([ connected, isNodeUp ]) => {
|
||||||
|
if (connected) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
// If it's not up, try again in a few...
|
||||||
window.setTimeout(() => {
|
if (!isNodeUp) {
|
||||||
this._connectWithToken(token).then(resolve).catch(reject);
|
const timeout = this.transport.retryTimeout;
|
||||||
}, timeout);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// The token is invalid
|
log.debug('node is not up ; will try again in', timeout, 'ms');
|
||||||
log.debug('tried with a wrong token', token);
|
|
||||||
return false;
|
return new Promise((resolve, reject) => {
|
||||||
|
window.setTimeout(() => {
|
||||||
|
this._connectWithToken(token).then(resolve).catch(reject);
|
||||||
|
}, timeout);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// The token is invalid
|
||||||
|
log.debug('tried with a wrong token', token);
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,6 @@
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container > * {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
color: rgba(255, 255, 255, 0.498039);
|
color: rgba(255, 255, 255, 0.498039);
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
top: 11px;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import AddIcon from 'material-ui/svg-icons/content/add';
|
|||||||
import RemoveIcon from 'material-ui/svg-icons/content/remove';
|
import RemoveIcon from 'material-ui/svg-icons/content/remove';
|
||||||
|
|
||||||
import { fromWei, toWei } from '~/api/util/wei';
|
import { fromWei, toWei } from '~/api/util/wei';
|
||||||
|
import { bytesToHex } from '~/api/util/format';
|
||||||
import Input from '~/ui/Form/Input';
|
import Input from '~/ui/Form/Input';
|
||||||
import InputAddressSelect from '~/ui/Form/InputAddressSelect';
|
import InputAddressSelect from '~/ui/Form/InputAddressSelect';
|
||||||
import Select from '~/ui/Form/Select';
|
import Select from '~/ui/Form/Select';
|
||||||
@ -68,7 +69,8 @@ export default class TypedInput extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
componentWillMount () {
|
componentWillMount () {
|
||||||
const { isEth, value } = this.props;
|
const { isEth } = this.props;
|
||||||
|
const value = this.getValue();
|
||||||
|
|
||||||
if (typeof isEth === 'boolean' && value) {
|
if (typeof isEth === 'boolean' && value) {
|
||||||
// Remove formatting commas
|
// Remove formatting commas
|
||||||
@ -95,14 +97,15 @@ export default class TypedInput extends Component {
|
|||||||
const { type } = param;
|
const { type } = param;
|
||||||
|
|
||||||
if (type === ABI_TYPES.ARRAY) {
|
if (type === ABI_TYPES.ARRAY) {
|
||||||
const { accounts, className, label, value = param.default } = this.props;
|
const { accounts, className, label } = this.props;
|
||||||
const { subtype, length } = param;
|
const { subtype, length } = param;
|
||||||
|
const value = this.getValue() || param.default;
|
||||||
|
|
||||||
const fixedLength = !!length;
|
const fixedLength = !!length;
|
||||||
|
|
||||||
const inputs = range(length || value.length).map((_, index) => {
|
const inputs = range(length || value.length).map((_, index) => {
|
||||||
const onChange = (inputValue) => {
|
const onChange = (inputValue) => {
|
||||||
const newValues = [].concat(this.props.value);
|
const newValues = [].concat(value);
|
||||||
|
|
||||||
newValues[index] = inputValue;
|
newValues[index] = inputValue;
|
||||||
this.props.onChange(newValues);
|
this.props.onChange(newValues);
|
||||||
@ -191,7 +194,14 @@ export default class TypedInput extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === ABI_TYPES.BYTES) {
|
if (type === ABI_TYPES.BYTES) {
|
||||||
return this.renderDefault();
|
let value = this.getValue();
|
||||||
|
|
||||||
|
// Convert to hex if it's an array
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
value = bytesToHex(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.renderDefault(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the `isEth` prop is present (true or false)
|
// If the `isEth` prop is present (true or false)
|
||||||
@ -260,7 +270,7 @@ export default class TypedInput extends Component {
|
|||||||
: bnValue.toFixed(); // we need a string representation, could be >15 digits
|
: bnValue.toFixed(); // we need a string representation, could be >15 digits
|
||||||
}
|
}
|
||||||
|
|
||||||
renderInteger (value = this.props.value, onChange = this.onChange) {
|
renderInteger (value = this.getValue(), onChange = this.onChange) {
|
||||||
const { allowCopy, className, label, error, hint, min, max, readOnly } = this.props;
|
const { allowCopy, className, label, error, hint, min, max, readOnly } = this.props;
|
||||||
const param = this.getParam();
|
const param = this.getParam();
|
||||||
|
|
||||||
@ -268,7 +278,7 @@ export default class TypedInput extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
allowCopy={ allowCopy }
|
allowCopy={ allowCopy ? value : undefined }
|
||||||
className={ className }
|
className={ className }
|
||||||
label={ label }
|
label={ label }
|
||||||
hint={ hint }
|
hint={ hint }
|
||||||
@ -291,7 +301,7 @@ export default class TypedInput extends Component {
|
|||||||
*
|
*
|
||||||
* @see https://github.com/facebook/react/issues/1549
|
* @see https://github.com/facebook/react/issues/1549
|
||||||
*/
|
*/
|
||||||
renderFloat (value = this.props.value, onChange = this.onChange) {
|
renderFloat (value = this.getValue(), onChange = this.onChange) {
|
||||||
const { allowCopy, className, label, error, hint, min, max, readOnly } = this.props;
|
const { allowCopy, className, label, error, hint, min, max, readOnly } = this.props;
|
||||||
const param = this.getParam();
|
const param = this.getParam();
|
||||||
|
|
||||||
@ -299,7 +309,7 @@ export default class TypedInput extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
allowCopy={ allowCopy }
|
allowCopy={ allowCopy ? value : undefined }
|
||||||
className={ className }
|
className={ className }
|
||||||
label={ label }
|
label={ label }
|
||||||
hint={ hint }
|
hint={ hint }
|
||||||
@ -314,8 +324,8 @@ export default class TypedInput extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderDefault () {
|
renderDefault (value = this.getValue()) {
|
||||||
const { allowCopy, className, label, value, error, hint, readOnly } = this.props;
|
const { allowCopy, className, label, error, hint, readOnly } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
@ -332,7 +342,8 @@ export default class TypedInput extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderAddress () {
|
renderAddress () {
|
||||||
const { accounts, allowCopy, className, label, value, error, hint, readOnly } = this.props;
|
const { accounts, allowCopy, className, label, error, hint, readOnly } = this.props;
|
||||||
|
const value = this.getValue();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputAddressSelect
|
<InputAddressSelect
|
||||||
@ -350,7 +361,8 @@ export default class TypedInput extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderBoolean () {
|
renderBoolean () {
|
||||||
const { allowCopy, className, label, value, error, hint, readOnly } = this.props;
|
const { allowCopy, className, label, error, hint, readOnly } = this.props;
|
||||||
|
const value = this.getValue();
|
||||||
|
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
return this.renderDefault();
|
return this.renderDefault();
|
||||||
@ -441,7 +453,7 @@ export default class TypedInput extends Component {
|
|||||||
onChange(newValues);
|
onChange(newValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
getParam = () => {
|
getParam () {
|
||||||
const { param } = this.props;
|
const { param } = this.props;
|
||||||
|
|
||||||
if (typeof param === 'string') {
|
if (typeof param === 'string') {
|
||||||
@ -450,4 +462,15 @@ export default class TypedInput extends Component {
|
|||||||
|
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the value comes from `decodeMethodInput`,
|
||||||
|
* it can be an object of the shape:
|
||||||
|
* { value: Object, type: String }
|
||||||
|
*/
|
||||||
|
getValue (value = this.props.value) {
|
||||||
|
return value && value.value
|
||||||
|
? value.value
|
||||||
|
: value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -560,7 +560,7 @@ class MethodDecoding extends Component {
|
|||||||
key={ index }
|
key={ index }
|
||||||
param={ input.type }
|
param={ input.type }
|
||||||
readOnly
|
readOnly
|
||||||
value={ this.renderValue(input.value) }
|
value={ input.value }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -568,16 +568,6 @@ class MethodDecoding extends Component {
|
|||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderValue (value) {
|
|
||||||
const { api } = this.context;
|
|
||||||
|
|
||||||
if (api.util.isArray(value)) {
|
|
||||||
return api.util.bytesToHex(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
renderTokenValue (value) {
|
renderTokenValue (value) {
|
||||||
const { token } = this.props;
|
const { token } = this.props;
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ export function parseAbiType (type) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'bytes') {
|
if (type === 'bytes' || type === 'fixedBytes') {
|
||||||
return {
|
return {
|
||||||
type: BYTES_TYPE,
|
type: BYTES_TYPE,
|
||||||
default: '0x'
|
default: '0x'
|
||||||
|
@ -19,7 +19,7 @@ import moment from 'moment';
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import { IdentityIcon, IdentityName, Input, InputAddress } from '~/ui';
|
import { IdentityIcon, IdentityName, TypedInput } from '~/ui';
|
||||||
import ShortenedHash from '~/ui/ShortenedHash';
|
import ShortenedHash from '~/ui/ShortenedHash';
|
||||||
import { txLink } from '~/3rdparty/etherscan/links';
|
import { txLink } from '~/3rdparty/etherscan/links';
|
||||||
|
|
||||||
@ -112,41 +112,16 @@ export default class Event extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderParam (name, param) {
|
renderParam (name, param) {
|
||||||
const { api } = this.context;
|
return (
|
||||||
|
<TypedInput
|
||||||
switch (param.type) {
|
allowCopy
|
||||||
case 'address':
|
className={ styles.input }
|
||||||
return (
|
label={ name }
|
||||||
<InputAddress
|
param={ param.type }
|
||||||
disabled
|
readOnly
|
||||||
text
|
value={ param.value }
|
||||||
className={ styles.input }
|
/>
|
||||||
value={ param.value }
|
);
|
||||||
label={ name }
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
default:
|
|
||||||
let value;
|
|
||||||
|
|
||||||
if (api.util.isInstanceOf(param.value, BigNumber)) {
|
|
||||||
value = param.value.toFormat(0);
|
|
||||||
} else if (api.util.isArray(param.value)) {
|
|
||||||
value = api.util.bytesToHex(param.value);
|
|
||||||
} else {
|
|
||||||
value = param.value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Input
|
|
||||||
readOnly
|
|
||||||
allowCopy
|
|
||||||
className={ styles.input }
|
|
||||||
value={ value }
|
|
||||||
label={ name }
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
formatBlockTimestamp (block) {
|
formatBlockTimestamp (block) {
|
||||||
|
@ -46,6 +46,12 @@ export default class Events extends Component {
|
|||||||
events: []
|
events: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
shouldComponentUpdate (nextProps) {
|
||||||
|
return (nextProps.events !== this.props.events) ||
|
||||||
|
(nextProps.netVersion !== this.props.netVersion) ||
|
||||||
|
(nextProps.isLoading !== this.props.isLoading);
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { events, isLoading, netVersion } = this.props;
|
const { events, isLoading, netVersion } = this.props;
|
||||||
|
|
||||||
|
@ -138,10 +138,8 @@ class InputQuery extends Component {
|
|||||||
.map((out, index) => ({
|
.map((out, index) => ({
|
||||||
name: out.name,
|
name: out.name,
|
||||||
type: out.type,
|
type: out.type,
|
||||||
value: results[index],
|
value: results[index]
|
||||||
display: this.renderValue(results[index])
|
|
||||||
}))
|
}))
|
||||||
.sort((outA, outB) => outA.display.length - outB.display.length)
|
|
||||||
.map((out, index) => {
|
.map((out, index) => {
|
||||||
const input = (
|
const input = (
|
||||||
<TypedInput
|
<TypedInput
|
||||||
@ -150,7 +148,7 @@ class InputQuery extends Component {
|
|||||||
isEth={ false }
|
isEth={ false }
|
||||||
param={ out.type }
|
param={ out.type }
|
||||||
readOnly
|
readOnly
|
||||||
value={ out.display }
|
value={ out.value }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -195,25 +193,6 @@ class InputQuery extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderValue (token) {
|
|
||||||
const { api } = this.context;
|
|
||||||
const { type, value } = token;
|
|
||||||
|
|
||||||
if (value === null || value === undefined) {
|
|
||||||
return 'no data';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'array' || type === 'fixedArray') {
|
|
||||||
return value.map((tok) => this.renderValue(tok));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
return api.util.bytesToHex(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
onClick = () => {
|
onClick = () => {
|
||||||
const { inputs, values } = this.state;
|
const { inputs, values } = this.state;
|
||||||
const { contract, name, outputs, signature } = this.props;
|
const { contract, name, outputs, signature } = this.props;
|
||||||
|
@ -139,15 +139,14 @@ export default class Queries extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderValue (tokenValue, output, key) {
|
renderValue (value, output, key) {
|
||||||
if (typeof tokenValue === 'undefined') {
|
if (typeof value === 'undefined') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { accountsInfo } = this.props;
|
const { accountsInfo } = this.props;
|
||||||
const { name, type } = output;
|
const { name, type } = output;
|
||||||
const label = `${name ? `${name}: ` : ''}${type}`;
|
const label = `${name ? `${name}: ` : ''}${type}`;
|
||||||
const value = this.getTokenValue(tokenValue);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TypedInput
|
<TypedInput
|
||||||
@ -163,25 +162,6 @@ export default class Queries extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTokenValue (token) {
|
|
||||||
const { api } = this.context;
|
|
||||||
const { type, value } = token;
|
|
||||||
|
|
||||||
if (value === null || value === undefined) {
|
|
||||||
return 'no data';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'array' || type === 'fixedArray') {
|
|
||||||
return value.map((tok) => this.getTokenValue(tok));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
return api.util.bytesToHex(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
_sortEntries (a, b) {
|
_sortEntries (a, b) {
|
||||||
return a.name.localeCompare(b.name);
|
return a.name.localeCompare(b.name);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import styles from './transactionPendingFormConfirm.css';
|
|||||||
|
|
||||||
export default class TransactionPendingFormConfirm extends Component {
|
export default class TransactionPendingFormConfirm extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
account: PropTypes.object.isRequired,
|
account: PropTypes.object,
|
||||||
address: PropTypes.string.isRequired,
|
address: PropTypes.string.isRequired,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
isSending: PropTypes.bool.isRequired,
|
isSending: PropTypes.bool.isRequired,
|
||||||
@ -36,6 +36,7 @@ export default class TransactionPendingFormConfirm extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
account: {},
|
||||||
focus: false
|
focus: false
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ export default class TransactionPendingFormConfirm extends Component {
|
|||||||
|
|
||||||
getPasswordHint () {
|
getPasswordHint () {
|
||||||
const { account } = this.props;
|
const { account } = this.props;
|
||||||
const accountHint = account && account.meta && account.meta.passwordHint;
|
const accountHint = account.meta && account.meta.passwordHint;
|
||||||
|
|
||||||
if (accountHint) {
|
if (accountHint) {
|
||||||
return accountHint;
|
return accountHint;
|
||||||
@ -149,14 +150,16 @@ export default class TransactionPendingFormConfirm extends Component {
|
|||||||
const { account } = this.props;
|
const { account } = this.props;
|
||||||
const { password } = this.state;
|
const { password } = this.state;
|
||||||
|
|
||||||
if (account && account.hardware) {
|
if (account.hardware) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAccount = account.uuid;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
hint={
|
hint={
|
||||||
account.uuid
|
isAccount
|
||||||
? (
|
? (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='signer.txPendingConfirm.password.unlock.hint'
|
id='signer.txPendingConfirm.password.unlock.hint'
|
||||||
@ -171,7 +174,7 @@ export default class TransactionPendingFormConfirm extends Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
label={
|
label={
|
||||||
account.uuid
|
isAccount
|
||||||
? (
|
? (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='signer.txPendingConfirm.password.unlock.label'
|
id='signer.txPendingConfirm.password.unlock.label'
|
||||||
|
@ -48,7 +48,7 @@ function render (address) {
|
|||||||
|
|
||||||
component = shallow(
|
component = shallow(
|
||||||
<TransactionPendingFormConfirm
|
<TransactionPendingFormConfirm
|
||||||
account={ ACCOUNTS[address] || {} }
|
account={ ACCOUNTS[address] }
|
||||||
address={ address }
|
address={ address }
|
||||||
onConfirm={ onConfirm }
|
onConfirm={ onConfirm }
|
||||||
isSending={ false }
|
isSending={ false }
|
||||||
@ -130,5 +130,9 @@ describe('views/Signer/TransactionPendingFormConfirm', () => {
|
|||||||
it('renders the password', () => {
|
it('renders the password', () => {
|
||||||
expect(instance.renderPassword()).not.to.be.null;
|
expect(instance.renderPassword()).not.to.be.null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders the hint', () => {
|
||||||
|
expect(instance.renderHint()).to.be.null;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -578,6 +578,10 @@ class WriteContract extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderContract (contract) {
|
renderContract (contract) {
|
||||||
|
if (!contract) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const { bytecode } = contract;
|
const { bytecode } = contract;
|
||||||
const abi = contract.interface;
|
const abi = contract.interface;
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
//! Spec builtin deserialization.
|
//! Spec builtin deserialization.
|
||||||
|
|
||||||
|
use uint::Uint;
|
||||||
|
|
||||||
/// Linear pricing.
|
/// Linear pricing.
|
||||||
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||||
pub struct Linear {
|
pub struct Linear {
|
||||||
@ -25,12 +27,22 @@ pub struct Linear {
|
|||||||
pub word: usize,
|
pub word: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pricing for modular exponentiation.
|
||||||
|
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||||
|
pub struct Modexp {
|
||||||
|
/// Price divisor.
|
||||||
|
pub divisor: usize,
|
||||||
|
}
|
||||||
|
|
||||||
/// Pricing variants.
|
/// Pricing variants.
|
||||||
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||||
pub enum Pricing {
|
pub enum Pricing {
|
||||||
/// Linear pricing.
|
/// Linear pricing.
|
||||||
#[serde(rename="linear")]
|
#[serde(rename="linear")]
|
||||||
Linear(Linear),
|
Linear(Linear),
|
||||||
|
/// Pricing for modular exponentiation.
|
||||||
|
#[serde(rename="modexp")]
|
||||||
|
Modexp(Modexp),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spec builtin.
|
/// Spec builtin.
|
||||||
@ -40,12 +52,15 @@ pub struct Builtin {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
/// Builtin pricing.
|
/// Builtin pricing.
|
||||||
pub pricing: Pricing,
|
pub pricing: Pricing,
|
||||||
|
/// Activation block.
|
||||||
|
pub activate_at: Option<Uint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use spec::builtin::{Builtin, Pricing, Linear};
|
use spec::builtin::{Builtin, Pricing, Linear, Modexp};
|
||||||
|
use uint::Uint;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn builtin_deserialization() {
|
fn builtin_deserialization() {
|
||||||
@ -56,5 +71,20 @@ mod tests {
|
|||||||
let deserialized: Builtin = serde_json::from_str(s).unwrap();
|
let deserialized: Builtin = serde_json::from_str(s).unwrap();
|
||||||
assert_eq!(deserialized.name, "ecrecover");
|
assert_eq!(deserialized.name, "ecrecover");
|
||||||
assert_eq!(deserialized.pricing, Pricing::Linear(Linear { base: 3000, word: 0 }));
|
assert_eq!(deserialized.pricing, Pricing::Linear(Linear { base: 3000, word: 0 }));
|
||||||
|
assert!(deserialized.activate_at.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn activate_at() {
|
||||||
|
let s = r#"{
|
||||||
|
"name": "late_start",
|
||||||
|
"activate_at": 100000,
|
||||||
|
"pricing": { "modexp": { "divisor": 5 } }
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let deserialized: Builtin = serde_json::from_str(s).unwrap();
|
||||||
|
assert_eq!(deserialized.name, "late_start");
|
||||||
|
assert_eq!(deserialized.pricing, Pricing::Modexp(Modexp { divisor: 5 }));
|
||||||
|
assert_eq!(deserialized.activate_at, Some(Uint(100000.into())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user