Additional helper function.
This commit is contained in:
parent
635bf284b4
commit
6447f9b90b
@ -35,8 +35,7 @@ pub fn h256_from_json(json: &Json) -> H256 {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u256_from_json(json: &Json) -> U256 {
|
||||
let s = json.as_string().unwrap_or("");
|
||||
pub fn u256_from_hex(s: &str) -> U256 {
|
||||
if s.len() >= 2 && &s[0..2] == "0x" {
|
||||
U256::from_str(&s[2..]).unwrap_or(U256::from(0))
|
||||
} else {
|
||||
@ -44,6 +43,10 @@ pub fn u256_from_json(json: &Json) -> U256 {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u256_from_json(json: &Json) -> U256 {
|
||||
u256_from_hex(json.as_string().unwrap_or(""))
|
||||
}
|
||||
|
||||
pub fn usize_from_json(json: &Json) -> usize {
|
||||
u256_from_json(json).low_u64() as usize
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user