mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat(rpc): implement block_transaction_count (#1471)
This commit is contained in:
@ -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()
|
||||
));
|
||||
|
||||
@ -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>,
|
||||
|
||||
@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user