Merge branch 'master' into optional-spec

This commit is contained in:
keorn
2017-01-03 15:42:56 +01:00
682 changed files with 14124 additions and 14074 deletions

View File

@@ -54,12 +54,12 @@ macro_rules! impl_hash {
let value = match value.len() {
0 => $inner::from(0),
2 if value == "0x" => $inner::from(0),
_ if value.starts_with("0x") => try!($inner::from_str(&value[2..]).map_err(|_| {
_ if value.starts_with("0x") => $inner::from_str(&value[2..]).map_err(|_| {
Error::custom(format!("Invalid hex value {}.", value).as_str())
})),
_ => try!($inner::from_str(value).map_err(|_| {
})?,
_ => $inner::from_str(value).map_err(|_| {
Error::custom(format!("Invalid hex value {}.", value).as_str())
}))
})?,
};
Ok($name(value))

View File

@@ -32,8 +32,10 @@ pub struct Account {
pub nonce: Option<Uint>,
/// Code.
pub code: Option<Bytes>,
/// Storage
/// Storage.
pub storage: Option<BTreeMap<Uint, Uint>>,
/// Constructor.
pub constructor: Option<Bytes>,
}
impl Account {

View File

@@ -35,6 +35,10 @@ pub struct Params {
/// Network id.
#[serde(rename="networkID")]
pub network_id: Uint,
/// Chain id.
#[serde(rename="chainID")]
pub chain_id: Option<Uint>,
/// Name of the main ("eth") subprotocol.
#[serde(rename="subprotocolName")]
pub subprotocol_name: Option<String>,
@@ -58,6 +62,7 @@ mod tests {
"homesteadTransition": "0x118c30",
"maximumExtraDataSize": "0x20",
"networkID" : "0x1",
"chainID" : "0x15",
"subprotocolName" : "exp",
"minGasLimit": "0x1388",
"accountStartNonce": "0x00"

View File

@@ -18,6 +18,7 @@
use std::collections::BTreeMap;
use hash::Address;
use bytes::Bytes;
use spec::{Account, Builtin};
/// Blockchain test state deserializer.
@@ -29,7 +30,15 @@ impl State {
pub fn builtins(&self) -> BTreeMap<Address, Builtin> {
self.0
.iter()
.filter_map(|ref pair| pair.1.builtin.clone().map(|b| (pair.0.clone(), b.clone())))
.filter_map(|(add, ref acc)| acc.builtin.clone().map(|b| (add.clone(), b)))
.collect()
}
/// Returns all constructors.
pub fn constructors(&self) -> BTreeMap<Address, Bytes> {
self.0
.iter()
.filter_map(|(add, ref acc)| acc.constructor.clone().map(|b| (add.clone(), b)))
.collect()
}
}

View File

@@ -46,16 +46,16 @@ impl Visitor for InputVisitor {
let mut result = BTreeMap::new();
loop {
let key_str: Option<String> = try!(visitor.visit_key());
let key_str: Option<String> = visitor.visit_key()?;
let key = match key_str {
Some(ref k) if k.starts_with("0x") => try!(Bytes::from_str(k).map_err(Error::custom)),
Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(Error::custom)?,
Some(k) => Bytes::new(k.into_bytes()),
None => { break; }
};
let val_str: Option<String> = try!(visitor.visit_value());
let val_str: Option<String> = visitor.visit_value()?;
let val = match val_str {
Some(ref v) if v.starts_with("0x") => Some(try!(Bytes::from_str(v).map_err(Error::custom))),
Some(ref v) if v.starts_with("0x") => Some(Bytes::from_str(v).map_err(Error::custom)?),
Some(v) => Some(Bytes::new(v.into_bytes())),
None => None,
};
@@ -63,7 +63,7 @@ impl Visitor for InputVisitor {
result.insert(key, val);
}
try!(visitor.end());
visitor.end()?;
let input = Input {
data: result
@@ -76,7 +76,7 @@ impl Visitor for InputVisitor {
let mut result = BTreeMap::new();
loop {
let keyval: Option<Vec<Option<String>>> = try!(visitor.visit());
let keyval: Option<Vec<Option<String>>> = visitor.visit()?;
let keyval = match keyval {
Some(k) => k,
_ => { break; },
@@ -90,13 +90,13 @@ impl Visitor for InputVisitor {
let ref val_str: Option<String> = keyval[1];
let key = match *key_str {
Some(ref k) if k.starts_with("0x") => try!(Bytes::from_str(k).map_err(Error::custom)),
Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(Error::custom)?,
Some(ref k) => Bytes::new(k.clone().into_bytes()),
None => { break; }
};
let val = match *val_str {
Some(ref v) if v.starts_with("0x") => Some(try!(Bytes::from_str(v).map_err(Error::custom))),
Some(ref v) if v.starts_with("0x") => Some(Bytes::from_str(v).map_err(Error::custom)?),
Some(ref v) => Some(Bytes::new(v.clone().into_bytes())),
None => None,
};
@@ -104,7 +104,7 @@ impl Visitor for InputVisitor {
result.insert(key, val);
}
try!(visitor.end());
visitor.end()?;
let input = Input {
data: result

View File

@@ -69,12 +69,12 @@ impl Visitor for UintVisitor {
let value = match value.len() {
0 => U256::from(0),
2 if value.starts_with("0x") => U256::from(0),
_ if value.starts_with("0x") => try!(U256::from_str(&value[2..]).map_err(|_| {
_ if value.starts_with("0x") => U256::from_str(&value[2..]).map_err(|_| {
Error::custom(format!("Invalid hex value {}.", value).as_str())
})),
_ => try!(U256::from_dec_str(value).map_err(|_| {
})?,
_ => U256::from_dec_str(value).map_err(|_| {
Error::custom(format!("Invalid decimal value {}.", value).as_str())
}))
})?
};
Ok(Uint(value))