feat(rpc): implement block_transaction_count (#1471)

This commit is contained in:
Matthias Seitz
2023-02-20 20:46:25 +01:00
committed by GitHub
parent 8d1dc58af5
commit cc5e5cab3c
3 changed files with 20 additions and 10 deletions

View File

@ -69,16 +69,12 @@ where
EthApiClient::storage_at(client, address, U256::default(), None).await.unwrap();
EthApiClient::block_by_hash(client, hash, false).await.unwrap();
EthApiClient::block_by_number(client, block_number, false).await.unwrap();
EthApiClient::block_transaction_count_by_number(client, block_number).await.unwrap();
EthApiClient::block_transaction_count_by_hash(client, hash).await.unwrap();
// Unimplemented
assert!(is_unimplemented(EthApiClient::syncing(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::author(client).await.err().unwrap()));
assert!(is_unimplemented(
EthApiClient::block_transaction_count_by_hash(client, hash).await.err().unwrap()
));
assert!(is_unimplemented(
EthApiClient::block_transaction_count_by_number(client, block_number).await.err().unwrap()
));
assert!(is_unimplemented(
EthApiClient::block_uncles_count_by_hash(client, hash).await.err().unwrap()
));

View File

@ -12,6 +12,20 @@ impl<Client, Pool, Network> EthApi<Client, Pool, Network>
where
Client: BlockProvider + StateProviderFactory + 'static,
{
pub(crate) async fn block_transaction_count(
&self,
block_id: impl Into<BlockId>,
) -> EthResult<Option<usize>> {
let block_id = block_id.into();
// TODO support pending block
if let Some(txs) = self.client().transactions_by_block(block_id)? {
Ok(Some(txs.len()))
} else {
Ok(None)
}
}
pub(crate) async fn block(
&self,
block_id: impl Into<BlockId>,

View File

@ -67,15 +67,15 @@ where
Ok(EthApi::block(self, number, full).await?)
}
async fn block_transaction_count_by_hash(&self, _hash: H256) -> Result<Option<U256>> {
Err(internal_rpc_err("unimplemented"))
async fn block_transaction_count_by_hash(&self, hash: H256) -> Result<Option<U256>> {
Ok(EthApi::block_transaction_count(self, hash).await?.map(U256::from))
}
async fn block_transaction_count_by_number(
&self,
_number: BlockNumberOrTag,
number: BlockNumberOrTag,
) -> Result<Option<U256>> {
Err(internal_rpc_err("unimplemented"))
Ok(EthApi::block_transaction_count(self, number).await?.map(U256::from))
}
async fn block_uncles_count_by_hash(&self, _hash: H256) -> Result<U256> {