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

Commit

Permalink
feat: extend Middleware trait customized for celo (#314)
Browse files Browse the repository at this point in the history
* Add CeloMiddleware trait

* change types of block number and returned keys
  • Loading branch information
hanyunx authored Jun 15, 2021
1 parent 1dda336 commit 5715bcd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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,
block: Option<BlockId>,
) -> Result<Vec<Vec<u8>>, ProviderError> {
self.provider()
.get_validators_bls_public_keys(block)
.await
.map_err(FromErr::from)
}
}
15 changes: 15 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,19 @@ 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: Option<BlockId>,
) -> Result<Vec<Vec<u8>>, ProviderError> {
let block = utils::serialize(&block.unwrap_or_else(|| BlockNumber::Latest.into()));
self.request("istanbul_getValidatorsBLSPublicKeys", [block])
.await
}
}

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

0 comments on commit 5715bcd

Please sign in to comment.