Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move FeeHistory to core types
- Loading branch information
Showing
4 changed files
with
44 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::str::FromStr; | ||
|
||
use crate::types::U256; | ||
use serde::{de::Deserializer, Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Serialize, Debug, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct FeeHistory { | ||
pub base_fee_per_gas: Vec<U256>, | ||
pub gas_used_ratio: Vec<f64>, | ||
#[serde(deserialize_with = "from_int_or_hex")] | ||
/// oldestBlock is returned as an unsigned integer up to geth v1.10.6. From | ||
/// geth v1.10.7, this has been updated to return in the hex encoded form. | ||
/// The custom deserializer allows backward compatibility for those clients | ||
/// not running v1.10.7 yet. | ||
pub oldest_block: U256, | ||
pub reward: Vec<Vec<U256>>, | ||
} | ||
|
||
fn from_int_or_hex<'de, D>(deserializer: D) -> Result<U256, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
#[derive(Deserialize)] | ||
#[serde(untagged)] | ||
enum IntOrHex { | ||
Int(u64), | ||
Hex(String), | ||
} | ||
match IntOrHex::deserialize(deserializer)? { | ||
IntOrHex::Int(n) => Ok(U256::from(n)), | ||
IntOrHex::Hex(s) => U256::from_str(s.as_str()).map_err(serde::de::Error::custom), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,6 @@ pub use chain::*; | |
mod proof; | ||
|
||
pub use proof::*; | ||
|
||
mod fee; | ||
pub use fee::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters