revert: unify get_block_receipts for eth/parity RPCs (#601)

This commit is contained in:
univerz 2021-11-21 17:14:35 +01:00 committed by GitHub
parent a68f4ec9a7
commit ec00325aa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View File

@ -616,6 +616,14 @@ pub trait Middleware: Sync + Send + Debug {
// Parity namespace // Parity namespace
/// Returns all receipts for that block. Must be done on a parity node.
async fn parity_block_receipts<T: Into<BlockNumber> + Send + Sync>(
&self,
block: T,
) -> Result<Vec<TransactionReceipt>, Self::Error> {
self.inner().parity_block_receipts(block).await.map_err(FromErr::from)
}
async fn subscribe<T, R>( async fn subscribe<T, R>(
&self, &self,
params: T, params: T,

View File

@ -338,19 +338,21 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
/// Returns all receipts for a block. /// Returns all receipts for a block.
/// ///
/// Note that this uses the `eth_getBlockReceipts` or `parity_getBlockReceipts` RPC, which is /// Note that this uses the `eth_getBlockReceipts` RPC, which is
/// non-standard and currently supported by Erigon, OpenEthereum and Nethermind. /// non-standard and currently supported by Erigon.
async fn get_block_receipts<T: Into<BlockNumber> + Send + Sync>( async fn get_block_receipts<T: Into<BlockNumber> + Send + Sync>(
&self, &self,
block: T, block: T,
) -> Result<Vec<TransactionReceipt>, Self::Error> { ) -> Result<Vec<TransactionReceipt>, Self::Error> {
let method = match self.node_client().await? { self.request("eth_getBlockReceipts", [block.into()]).await
NodeClient::Erigon => "eth_getBlockReceipts", }
NodeClient::OpenEthereum | NodeClient::Nethermind => "parity_getBlockReceipts",
_ => return Err(ProviderError::UnsupportedRPC),
};
self.request(method, [block.into()]).await /// Returns all receipts for that block. Must be done on a parity node.
async fn parity_block_receipts<T: Into<BlockNumber> + Send + Sync>(
&self,
block: T,
) -> Result<Vec<TransactionReceipt>, Self::Error> {
self.request("parity_getBlockReceipts", vec![block.into()]).await
} }
/// Gets the current gas price as estimated by the node /// Gets the current gas price as estimated by the node
@ -1160,7 +1162,7 @@ mod tests {
_ => return, _ => return,
}; };
let provider = Provider::<Http>::try_from(url.as_str()).unwrap(); let provider = Provider::<Http>::try_from(url.as_str()).unwrap();
let receipts = provider.get_block_receipts(10657200).await.unwrap(); let receipts = provider.parity_block_receipts(10657200).await.unwrap();
assert!(!receipts.is_empty()); assert!(!receipts.is_empty());
} }