Parses a canonical JSON-RPC hexadecimal quantity.
(value: Option<&Value>)
| 776 | |
| 777 | /// Parses a canonical JSON-RPC hexadecimal quantity. |
| 778 | pub fn hex(value: Option<&Value>) -> Result<u64> { |
| 779 | let text = value.and_then(Value::as_str).ok_or_else(|| eyre!("hex quantity missing"))?; |
| 780 | let digits = |
| 781 | text.strip_prefix("0x").ok_or_else(|| eyre!("hex quantity lacks 0x prefix"))?; |
| 782 | if digits.is_empty() || (digits.len() > 1 && digits.starts_with('0')) { |
| 783 | bail!("non-canonical hex quantity"); |
| 784 | } |
| 785 | u64::from_str_radix(digits, 16).map_err(|_| eyre!("invalid hex quantity")) |
| 786 | } |
| 787 | |
| 788 | /// Validates and returns a lowercase-or-uppercase 32-byte hash. |
| 789 | pub fn hash(value: Option<&Value>) -> Result<String> { |