Skip to content

Commit

Permalink
remove third variant from IntOrHex
Browse files Browse the repository at this point in the history
 * unnecessary since serde_json::Number handles smaller ints as well
  • Loading branch information
Rjected committed Nov 26, 2022
1 parent 2fbdc46 commit 6dab223
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions ethers-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,14 @@ where
{
#[derive(Deserialize)]
#[serde(untagged)]
enum IntOrHexOrBigNum {
Int(u64),
enum IntOrHex {
Int(serde_json::Number),
Hex(String),
BigNumber(serde_json::Number),
}

match IntOrHexOrBigNum::deserialize(deserializer)? {
IntOrHexOrBigNum::Int(n) => Ok(U256::from(n)),
IntOrHexOrBigNum::Hex(s) => U256::from_str(s.as_str()).map_err(serde::de::Error::custom),
IntOrHexOrBigNum::BigNumber(b) => {
U256::from_dec_str(&b.to_string()).map_err(serde::de::Error::custom)
}
match IntOrHex::deserialize(deserializer)? {
IntOrHex::Hex(s) => U256::from_str(s.as_str()).map_err(serde::de::Error::custom),
IntOrHex::Int(n) => U256::from_dec_str(&n.to_string()).map_err(serde::de::Error::custom),
}
}

Expand Down
8 changes: 4 additions & 4 deletions ethers-providers/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ mod tests {
let response = r#"{
"id":"6e2fe698f3064cd99410926ce16734e35e3cc947d4354461d2594f2d2dd9f7b6",
"name":"Geth/v1.10.19-stable/darwin-arm64/go1.18.3",
"enode":"enode://d7dfaea49c7ef37701e668652bcf1bc63d3abb2ae97593374a949e175e4ff128730a2f35199f3462a56298b981dfc395a5abebd2d6f0284ffe5bdc3d8e258b86@***REMOVED***:30304?discport=0",
"enode":"enode://d7dfaea49c7ef37701e668652bcf1bc63d3abb2ae97593374a949e175e4ff128730a2f35199f3462a56298b981dfc395a5abebd2d6f0284ffe5bdc3d8e258b86@127.0.0.1:30304?discport=0",
"enr":"enr:-Jy4QIvS0dKBLjTTV_RojS8hjriwWsJNHRVyOh4Pk4aUXc5SZjKRVIOeYc7BqzEmbCjLdIY4Ln7x5ZPf-2SsBAc2_zqGAYSwY1zog2V0aMfGhNegsXuAgmlkgnY0gmlwhBiT_DiJc2VjcDI1NmsxoQLX366knH7zdwHmaGUrzxvGPTq7Kul1kzdKlJ4XXk_xKIRzbmFwwIN0Y3CCdmA",
"ip":"***REMOVED***",
"ip":"127.0.0.1",
"ports":{
"discovery":0,
"listener":30304
Expand Down Expand Up @@ -252,9 +252,9 @@ mod tests {
let response = r#"{
"id":"6e2fe698f3064cd99410926ce16734e35e3cc947d4354461d2594f2d2dd9f7b6",
"name":"Geth/v1.10.19-stable/darwin-arm64/go1.18.3",
"enode":"enode://d7dfaea49c7ef37701e668652bcf1bc63d3abb2ae97593374a949e175e4ff128730a2f35199f3462a56298b981dfc395a5abebd2d6f0284ffe5bdc3d8e258b86@***REMOVED***:30304?discport=0",
"enode":"enode://d7dfaea49c7ef37701e668652bcf1bc63d3abb2ae97593374a949e175e4ff128730a2f35199f3462a56298b981dfc395a5abebd2d6f0284ffe5bdc3d8e258b86@127.0.0.1:30304?discport=0",
"enr":"enr:-Jy4QIvS0dKBLjTTV_RojS8hjriwWsJNHRVyOh4Pk4aUXc5SZjKRVIOeYc7BqzEmbCjLdIY4Ln7x5ZPf-2SsBAc2_zqGAYSwY1zog2V0aMfGhNegsXuAgmlkgnY0gmlwhBiT_DiJc2VjcDI1NmsxoQLX366knH7zdwHmaGUrzxvGPTq7Kul1kzdKlJ4XXk_xKIRzbmFwwIN0Y3CCdmA",
"ip":"***REMOVED***",
"ip":"127.0.0.1",
"ports":{
"discovery":0,
"listener":30304
Expand Down

0 comments on commit 6dab223

Please sign in to comment.