From 6c44f29b061d478b5f15d97e36bb128576c3fde0 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 13 Jan 2016 17:42:57 +0100 Subject: [PATCH] json aid changes --- src/json_aid.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/json_aid.rs b/src/json_aid.rs index a382c61ec..c0b5a5180 100644 --- a/src/json_aid.rs +++ b/src/json_aid.rs @@ -18,8 +18,13 @@ 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_str(json.as_string().unwrap_or("0000000000000000000000000000000000000000")) +} + +pub fn address_from_str<'a>(s: &'a str) -> Address { + if s.len() == 0 { + Address::new() + } else if s.len() % 2 == 1 { address_from_hex(&("0".to_string() + &(clean(s).to_string()))[..]) } else { address_from_hex(clean(s)) @@ -35,7 +40,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 +49,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 {