,
pool: Arc,
@@ -126,6 +135,117 @@ impl Eth {
_marker: PhantomData,
}
}
+
+ pub async fn block_info_by_number(&self, number: BlockNumber) -> RpcResult> {
+ let id = match frontier_backend_client::native_block_id::(
+ self.client.as_ref(),
+ self.backend.as_ref(),
+ Some(number),
+ )
+ .await?
+ {
+ Some(id) => id,
+ None => return Ok(BlockInfo::default()),
+ };
+
+ let substrate_hash = self
+ .client
+ .expect_block_hash_from_id(&id)
+ .map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?;
+
+ self.block_info_by_substrate_hash(substrate_hash).await
+ }
+
+ pub async fn block_info_by_eth_block_hash(
+ &self,
+ eth_block_hash: H256,
+ ) -> RpcResult> {
+ let substrate_hash = match frontier_backend_client::load_hash::(
+ self.client.as_ref(),
+ self.backend.as_ref(),
+ eth_block_hash,
+ )
+ .await
+ .map_err(|err| internal_err(format!("{:?}", err)))?
+ {
+ Some(hash) => hash,
+ _ => return Ok(BlockInfo::default()),
+ };
+
+ self.block_info_by_substrate_hash(substrate_hash).await
+ }
+
+ pub async fn block_info_by_eth_transaction_hash(
+ &self,
+ ethereum_tx_hash: H256,
+ ) -> RpcResult<(BlockInfo, usize)> {
+ let (eth_block_hash, index) = match frontier_backend_client::load_transactions::(
+ self.client.as_ref(),
+ self.backend.as_ref(),
+ ethereum_tx_hash,
+ true,
+ )
+ .await
+ .map_err(|err| internal_err(format!("{:?}", err)))?
+ {
+ Some((hash, index)) => (hash, index as usize),
+ None => return Ok((BlockInfo::default(), 0)),
+ };
+
+ let substrate_hash = match frontier_backend_client::load_hash::(
+ self.client.as_ref(),
+ self.backend.as_ref(),
+ eth_block_hash,
+ )
+ .await
+ .map_err(|err| internal_err(format!("{:?}", err)))?
+ {
+ Some(hash) => hash,
+ _ => return Ok((BlockInfo::default(), 0)),
+ };
+
+ Ok((
+ self.block_info_by_substrate_hash(substrate_hash).await?,
+ index,
+ ))
+ }
+
+ pub async fn block_info_by_substrate_hash(
+ &self,
+ substrate_hash: B::Hash,
+ ) -> RpcResult> {
+ let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash);
+ let handler = self
+ .overrides
+ .schemas
+ .get(&schema)
+ .unwrap_or(&self.overrides.fallback);
+
+ let block = self
+ .block_data_cache
+ .current_block(schema, substrate_hash)
+ .await;
+ let receipts = handler.current_receipts(substrate_hash);
+ let statuses = self
+ .block_data_cache
+ .current_transaction_statuses(schema, substrate_hash)
+ .await;
+ let is_eip1559 = handler.is_eip1559(substrate_hash);
+ let base_fee = self
+ .client
+ .runtime_api()
+ .gas_price(substrate_hash)
+ .unwrap_or_default();
+
+ Ok(BlockInfo::new(
+ block,
+ receipts,
+ statuses,
+ substrate_hash,
+ is_eip1559,
+ base_fee,
+ ))
+ }
}
impl> Eth {
@@ -236,6 +356,13 @@ where
self.block_transaction_count_by_number(number).await
}
+ async fn block_transaction_receipts(
+ &self,
+ number: BlockNumber,
+ ) -> RpcResult