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 {