feat: use BlockHashOrNum in providers (#2627)

This commit is contained in:
Dan Cline
2023-05-10 16:03:16 -04:00
committed by GitHub
parent abcadd987c
commit 7d3016f0f2
31 changed files with 498 additions and 248 deletions

View File

@ -1,4 +1,4 @@
use crate::{BlockNumber, BlockNumberOrTag, H256};
use crate::{BlockNumber, H256};
/// Current status of the blockchain's head.
#[derive(Default, Clone, Debug, Eq, PartialEq)]
@ -7,22 +7,4 @@ pub struct ChainInfo {
pub best_hash: H256,
/// The block number of the highest fully synced block.
pub best_number: BlockNumber,
/// Last block that was finalized.
pub last_finalized: Option<BlockNumber>,
/// Safe block
pub safe_finalized: Option<BlockNumber>,
}
impl ChainInfo {
/// Attempts to convert a [BlockNumber](crate::rpc::BlockNumber) enum to a numeric value
pub fn convert_block_number(&self, number: BlockNumberOrTag) -> Option<u64> {
match number {
BlockNumberOrTag::Finalized => self.last_finalized,
BlockNumberOrTag::Safe => self.safe_finalized,
BlockNumberOrTag::Earliest => Some(0),
BlockNumberOrTag::Number(num) => Some(num),
BlockNumberOrTag::Pending => None,
BlockNumberOrTag::Latest => Some(self.best_number),
}
}
}