Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use u64 for block numbers #38

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub trait TempProvider: Send + Sync {
Self: Sync;

/// Gets the last block number available.
async fn get_block_number(&self) -> TransportResult<U64>
async fn get_block_number(&self) -> TransportResult<u64>
where
Self: Sync;

Expand Down Expand Up @@ -289,7 +289,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
}

/// Gets the last block number available.
async fn get_block_number(&self) -> TransportResult<U64>
async fn get_block_number(&self) -> TransportResult<u64>
where
Self: Sync,
{
Expand Down Expand Up @@ -718,7 +718,7 @@ mod providers_test {
let anvil = Anvil::new().spawn();
let provider = Provider::try_from(&anvil.endpoint()).unwrap();
let num = provider.get_block_number().await.unwrap();
assert_eq!(U64::ZERO, num)
assert_eq!(0, num)
}

#[tokio::test]
Expand Down
14 changes: 7 additions & 7 deletions crates/rpc-types/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ pub enum BlockNumberOrTag {
/// Pending block (not yet part of the blockchain)
Pending,
/// Block by number from canon chain
Number(U64),
Number(u64),
}

impl BlockNumberOrTag {
/// Returns the numeric block number if explicitly set
pub const fn as_number(&self) -> Option<U64> {
pub const fn as_number(&self) -> Option<u64> {
match *self {
BlockNumberOrTag::Number(num) => Some(num),
_ => None,
Expand Down Expand Up @@ -292,13 +292,13 @@ impl BlockNumberOrTag {

impl From<u64> for BlockNumberOrTag {
fn from(num: u64) -> Self {
BlockNumberOrTag::Number(U64::from(num))
BlockNumberOrTag::Number(num)
}
}

impl From<U64> for BlockNumberOrTag {
fn from(num: U64) -> Self {
BlockNumberOrTag::Number(num)
num.to::<u64>().into()
}
}

Expand Down Expand Up @@ -340,7 +340,7 @@ impl FromStr for BlockNumberOrTag {
"pending" => Self::Pending,
_number => {
if let Some(hex_val) = s.strip_prefix("0x") {
let number = U64::from_str_radix(hex_val, 16);
let number = u64::from_str_radix(hex_val, 16);
BlockNumberOrTag::Number(number?)
} else {
return Err(HexStringMissingPrefixError::default().into());
Expand Down Expand Up @@ -418,13 +418,13 @@ impl BlockId {

impl From<u64> for BlockId {
fn from(num: u64) -> Self {
BlockNumberOrTag::Number(U64::from(num)).into()
BlockNumberOrTag::Number(num).into()
}
}

impl From<U64> for BlockId {
fn from(num: U64) -> Self {
BlockNumberOrTag::Number(num).into()
BlockNumberOrTag::Number(num.to()).into()
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rpc-types/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,12 @@ impl Filter {
}

/// Returns the numeric value of the `toBlock` field
pub fn get_to_block(&self) -> Option<U64> {
pub fn get_to_block(&self) -> Option<u64> {
self.block_option.get_to_block().and_then(|b| b.as_number())
}

/// Returns the numeric value of the `fromBlock` field
pub fn get_from_block(&self) -> Option<U64> {
pub fn get_from_block(&self) -> Option<u64> {
self.block_option.get_from_block().and_then(|b| b.as_number())
}

Expand Down Expand Up @@ -759,7 +759,7 @@ impl FilteredParams {
}

/// Returns true if the filter matches the given block number
pub fn filter_block_range(&self, block_number: U64) -> bool {
pub fn filter_block_range(&self, block_number: u64) -> bool {
if self.filter.is_none() {
return true;
}
Expand Down
Loading