Skip to content

Commit

Permalink
feat: add get_block
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Nov 13, 2023
1 parent 330203f commit d1ba59d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ pub trait TempProvider: Send + Sync {
where
Self: Sync;

/// Gets a block by either its hash, tag, or number, with full transactions or only hashes.
async fn get_block(
&self,
id: BlockId,
full: bool,
) -> RpcResult<Option<Block>, Box<RawValue>, TransportError> {
match id {
BlockId::Hash(hash) => self.get_block_by_hash(hash.into(), full).await,
BlockId::Number(number) => self.get_block_by_number(number, full).await,
}
}

/// Gets a block by its [BlockHash], with full transactions or only hashes.
async fn get_block_by_hash(
&self,
Expand Down Expand Up @@ -683,7 +695,7 @@ mod providers_test {
let count = provider
.get_transaction_count(
address!("328375e18E7db8F1CA9d9bA8bF3E9C94ee34136A"),
Some(BlockNumberOrTag::Latest),
Some(BlockNumberOrTag::Latest.into()),
)
.await
.unwrap();
Expand Down

0 comments on commit d1ba59d

Please sign in to comment.