From 0bbd1e3bca1b0d69ca184e01c678fdef5a1fe359 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 13 Apr 2022 17:23:05 +0200 Subject: [PATCH] chore: add as number helper function (#1139) --- ethers-core/src/types/block.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ethers-core/src/types/block.rs b/ethers-core/src/types/block.rs index c738ac99..cfe9d179 100644 --- a/ethers-core/src/types/block.rs +++ b/ethers-core/src/types/block.rs @@ -222,6 +222,16 @@ pub enum BlockNumber { Number(U64), } +impl BlockNumber { + /// Returns the numeric block number if explicitly set + pub fn as_number(&self) -> Option { + match *self { + BlockNumber::Number(num) => Some(num), + _ => None, + } + } +} + impl> From for BlockNumber { fn from(num: T) -> Self { BlockNumber::Number(num.into())