chore: add blocknumber convenience impls (#1368)

This commit is contained in:
Matthias Seitz 2022-06-10 15:45:46 +02:00 committed by GitHub
parent ab988e6bc0
commit c96f6ba616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

View File

@ -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<T: Into<U64>> From<T> 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 {