From c96f6ba6164fabc337500599b9eb2e9fccd2884a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 10 Jun 2022 15:45:46 +0200 Subject: [PATCH] chore: add blocknumber convenience impls (#1368) --- ethers-core/src/types/block.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ethers-core/src/types/block.rs b/ethers-core/src/types/block.rs index c516318c..cffee94a 100644 --- a/ethers-core/src/types/block.rs +++ b/ethers-core/src/types/block.rs @@ -533,6 +533,26 @@ impl BlockNumber { _ => None, } } + + /// Returns `true` if a numeric block number is set + pub fn is_number(&self) -> bool { + matches!(self, BlockNumber::Number(_)) + } + + /// Returns `true` if it's "latest" + pub fn is_latest(&self) -> bool { + matches!(self, BlockNumber::Latest) + } + + /// Returns `true` if it's "pending" + pub fn is_pending(&self) -> bool { + matches!(self, BlockNumber::Pending) + } + + /// Returns `true` if it's "earliest" + pub fn is_earliest(&self) -> bool { + matches!(self, BlockNumber::Earliest) + } } impl> From for BlockNumber { @@ -590,6 +610,12 @@ impl fmt::Display for BlockNumber { } } +impl Default for BlockNumber { + fn default() -> Self { + BlockNumber::Latest + } +} + #[cfg(test)] #[cfg(not(feature = "celo"))] mod tests {