Merge pull request #42 from gavofyork/json_aid_changes

json aid changes
This commit is contained in:
Gav Wood 2016-01-13 23:20:00 +01:00
commit 8be95e57ec

View File

@ -18,12 +18,7 @@ pub fn bytes_from_json(json: &Json) -> Bytes {
}
pub fn address_from_json(json: &Json) -> Address {
let s = json.as_string().unwrap_or("0000000000000000000000000000000000000000");
if s.len() % 2 == 1 {
address_from_hex(&("0".to_string() + &(clean(s).to_string()))[..])
} else {
address_from_hex(clean(s))
}
From::from(json.as_string().unwrap_or("0000000000000000000000000000000000000000"))
}
pub fn h256_from_json(json: &Json) -> H256 {
@ -35,7 +30,7 @@ pub fn h256_from_json(json: &Json) -> H256 {
}
}
pub fn u256_from_hex(s: &str) -> U256 {
pub fn u256_from_str(s: &str) -> U256 {
if s.len() >= 2 && &s[0..2] == "0x" {
U256::from_str(&s[2..]).unwrap_or(U256::from(0))
} else {
@ -44,7 +39,7 @@ pub fn u256_from_hex(s: &str) -> U256 {
}
pub fn u256_from_json(json: &Json) -> U256 {
u256_from_hex(json.as_string().unwrap_or(""))
u256_from_str(json.as_string().unwrap_or(""))
}
pub fn usize_from_json(json: &Json) -> usize {