Skip to content

Commit

Permalink
feat(provider): get_uncle_count (alloy-rs#524)
Browse files Browse the repository at this point in the history
* feat(provider): get_uncle_count

* fix: test_uncle_count - rm rpc url

* nit

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
  • Loading branch information
2 people authored and ben186 committed Jul 27, 2024
1 parent 22bb037 commit 6db2d85
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions crates/provider/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,22 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
}
}

/// Gets the number of uncles for the block specified by the tag [BlockId].
async fn get_uncle_count(&self, tag: BlockId) -> TransportResult<u64> {
match tag {
BlockId::Hash(hash) => self
.client()
.request("eth_getUncleCountByBlockHash", (hash,))
.await
.map(|count: U64| count.to::<u64>()),
BlockId::Number(number) => self
.client()
.request("eth_getUncleCountByBlockNumber", (number,))
.await
.map(|count: U64| count.to::<u64>()),
}
}

/// Gets syncing info.
async fn syncing(&self) -> TransportResult<SyncStatus> {
self.client().request("eth_syncing", ()).await
Expand Down Expand Up @@ -1539,4 +1555,13 @@ mod tests {
}
}
}

#[tokio::test]
async fn test_uncle_count() {
init_tracing();
let (provider, _anvil) = spawn_anvil();

let count = provider.get_uncle_count(BlockId::Number(0.into())).await.unwrap();
assert_eq!(count, 0);
}
}

0 comments on commit 6db2d85

Please sign in to comment.