-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc): limit block_range by 100_000 per eth_getLogs request (#5243)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
- Loading branch information
1 parent
24fade3
commit 0449c5e
Showing
9 changed files
with
200 additions
and
29 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Additional helper types for CLI parsing. | ||
use std::{fmt, str::FromStr}; | ||
|
||
/// A helper type that maps `0` to `None` when parsing CLI arguments. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct ZeroAsNone(pub Option<u64>); | ||
|
||
impl ZeroAsNone { | ||
/// Returns the inner value. | ||
pub const fn new(value: u64) -> Self { | ||
Self(Some(value)) | ||
} | ||
|
||
/// Returns the inner value or `u64::MAX` if `None`. | ||
pub fn unwrap_or_max(self) -> u64 { | ||
self.0.unwrap_or(u64::MAX) | ||
} | ||
} | ||
|
||
impl fmt::Display for ZeroAsNone { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self.0 { | ||
Some(value) => write!(f, "{}", value), | ||
None => write!(f, "0"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for ZeroAsNone { | ||
type Err = std::num::ParseIntError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let value = s.parse::<u64>()?; | ||
Ok(Self(if value == 0 { None } else { Some(value) })) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_zero_parse() { | ||
let val = "0".parse::<ZeroAsNone>().unwrap(); | ||
assert_eq!(val, ZeroAsNone(None)); | ||
assert_eq!(val.unwrap_or_max(), u64::MAX); | ||
} | ||
} |
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
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
Oops, something went wrong.