Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
handle string case
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 4, 2023
1 parent f80c610 commit 3328fdd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ethers-core/src/utils/genesis.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Expand Down Expand Up @@ -354,12 +354,21 @@ where
match Option::<serde_json::Value>::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"))
Expand Down

0 comments on commit 3328fdd

Please sign in to comment.