Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat: extend Middleware trait customized for celo #314

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ethers-providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,17 @@ pub trait Middleware: Sync + Send + Debug {
.map_err(FromErr::from)
}
}

#[cfg(feature = "celo")]
#[async_trait]
pub trait CeloMiddleware: Middleware {
async fn get_validators_bls_public_keys(
&self,
hanyunx marked this conversation as resolved.
Show resolved Hide resolved
block_number: String,
) -> Result<Vec<String>, ProviderError> {
hanyunx marked this conversation as resolved.
Show resolved Hide resolved
self.provider()
.get_validators_bls_public_keys(block_number)
.await
.map_err(FromErr::from)
}
}
14 changes: 14 additions & 0 deletions ethers-providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use ethers_core::{
utils,
};

#[cfg(feature = "celo")]
use crate::CeloMiddleware;
use crate::Middleware;
use async_trait::async_trait;
use hex::FromHex;
Expand Down Expand Up @@ -150,6 +152,18 @@ impl<P: JsonRpcClient> Provider<P> {
}
}

#[cfg(feature = "celo")]
#[async_trait]
impl<P: JsonRpcClient> CeloMiddleware for Provider<P> {
async fn get_validators_bls_public_keys(
&self,
block_number: String,
) -> Result<Vec<String>, ProviderError> {
self.request("istanbul_getValidatorsBLSPublicKeys", [block_number])
.await
}
}

#[async_trait]
impl<P: JsonRpcClient> Middleware for Provider<P> {
type Error = ProviderError;
Expand Down