zebra_chain/block/height/
json_conversion.rs
1use serde_json::Value;
4
5use crate::BoxError;
6
7use super::{Height, TryIntoHeight};
8
9impl TryIntoHeight for Value {
10 type Error = BoxError;
11
12 fn try_into_height(&self) -> Result<Height, Self::Error> {
13 if self.is_number() {
14 let height = self.as_u64().ok_or("JSON value outside u64 range")?;
15 return height.try_into_height();
16 }
17
18 if let Some(height) = self.as_str() {
19 return height.try_into_height();
20 }
21
22 Err("JSON value must be a number or string".into())
23 }
24}