json aid changes
This commit is contained in:
parent
dca7c65345
commit
6c44f29b06
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user