-
Notifications
You must be signed in to change notification settings - Fork 795
feature: very permissive etherscan gwei deser #2327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
// This function is used to deserialize a string or number into a U256 with an | ||
// amount of gwei. If the contents is a number, deserialize it. If the contents | ||
// is a string, attempt to deser as first a decimal f64 then a decimal U256. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This function is used to deserialize a string or number into a U256 with an | |
// amount of gwei. If the contents is a number, deserialize it. If the contents | |
// is a string, attempt to deser as first a decimal f64 then a decimal U256. | |
// This function deserializes a string or number into a U256 with an amount of gwei. | |
// If the content is a number, it is deserialized. If the content is a string, we attempt to deserialize it first // as a decimal f64 and then as a decimal U256. |
use serde::{de, Deserialize, Deserializer}; | ||
use std::{collections::HashMap, str::FromStr}; | ||
|
||
const WEI_PER_GWEI: u64 = 1_000_000_000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use super::GWEI_TO_WEI
instead?
const WEI_PER_GWEI: u64 = 1_000_000_000; |
} | ||
|
||
match StringOrInt::deserialize(deserializer)? { | ||
StringOrInt::Number(i) => Ok(U256::from(i) * WEI_PER_GWEI), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringOrInt::Number(i) => Ok(U256::from(i) * WEI_PER_GWEI), | |
StringOrInt::Number(i) => Ok(U256::from(i) * super::GWEI_TO_WEI), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't exist in this package, that's in the middleware, not in the etherscan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, gotcha!
290a155
to
77d118c
Compare
Extremely permissive deserializer for etherscan gas units
Motivation
More complete fix to #2326 #2325
Solution
Introduce a deser that performs the following in order:
change the etherscan response object to have
U256
responses that are ALWAYS inwei
rather than in f64 gweiPR Checklist