Provider {
self
}
- async fn get_block_gen(
+ async fn request(&self, method: &str, params: T) -> Result
+ where
+ T: Debug + Serialize + Send + Sync,
+ R: Serialize + DeserializeOwned + Debug,
+ {
+ let span =
+ tracing::trace_span!("rpc", method = method, params = ?serde_json::to_string(¶ms)?);
+ // https://docs.rs/tracing/0.1.22/tracing/span/struct.Span.html#in-asynchronous-code
+ let res = async move {
+ trace!("tx");
+ let res: R = self.0.request(method, params).await.map_err(Into::into)?;
+ trace!(rx = ?serde_json::to_string(&res)?);
+ Ok::<_, ProviderError>(res)
+ }
+ .instrument(span)
+ .await?;
+ Ok(res)
+ }
+
+ async fn get_block_gen(
&self,
id: BlockId,
include_txs: bool,
@@ -107,17 +131,13 @@ impl Provider {
Ok(match id {
BlockId::Hash(hash) => {
let hash = utils::serialize(&hash);
- self.0
- .request("eth_getBlockByHash", [hash, include_txs])
- .await
- .map_err(Into::into)?
+ self.request("eth_getBlockByHash", [hash, include_txs])
+ .await?
}
BlockId::Number(num) => {
let num = utils::serialize(&num);
- self.0
- .request("eth_getBlockByNumber", [num, include_txs])
- .await
- .map_err(Into::into)?
+ self.request("eth_getBlockByNumber", [num, include_txs])
+ .await?
}
})
}
@@ -143,11 +163,7 @@ impl Middleware for Provider {
/// Gets the latest block number via the `eth_BlockNumber` API
async fn get_block_number(&self) -> Result {
- Ok(self
- .0
- .request("eth_blockNumber", ())
- .await
- .map_err(Into::into)?)
+ self.request("eth_blockNumber", ()).await
}
/// Gets the block at `block_hash_or_number` (transaction hashes only)
@@ -155,9 +171,7 @@ impl Middleware for Provider {
&self,
block_hash_or_number: T,
) -> Result