From 3328fddb6428173b6fdef60f511b6472514c6160 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 4 Nov 2023 07:57:04 +0100 Subject: [PATCH] handle string case --- ethers-core/src/utils/genesis.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ethers-core/src/utils/genesis.rs b/ethers-core/src/utils/genesis.rs index 02722b5c25..7b6f2c6543 100644 --- a/ethers-core/src/utils/genesis.rs +++ b/ethers-core/src/utils/genesis.rs @@ -1,11 +1,11 @@ -use std::collections::HashMap; +use std::{collections::HashMap, str::FromStr}; use crate::{ types::{ serde_helpers::{ deserialize_stringified_eth_u64, deserialize_stringified_eth_u64_opt, deserialize_stringified_numeric, deserialize_stringified_numeric_opt, - deserialize_stringified_u64_opt, + deserialize_stringified_u64_opt, Numeric, }, Address, Bytes, H256, U256, U64, }, @@ -354,12 +354,21 @@ where match Option::::deserialize(deserializer)? { None => Ok(None), Some(val) => { + if let Some(num) = val.as_str() { + return Numeric::from_str(num) + .map(U256::from) + .map(Some) + .map_err(serde::de::Error::custom); + } + if let serde_json::Value::Number(num) = val { // mainnet ttd is serialized as number, which serde is unable to deserialize as // integer if num.as_f64() == Some(5.875e22) { + dbg!("here2"); Ok(Some(U256::from(58750000000000000000000u128))) } else { + dbg!("here3"); num.as_u64() .map(U256::from) .ok_or_else(|| serde::de::Error::custom("expected a number"))