feat: extend Middleware trait customized for celo (#314)

* Add CeloMiddleware trait

* change types of block number and returned keys
This commit is contained in:
Hanyun Xu 2021-06-15 05:22:53 -07:00 committed by GitHub
parent 1dda336a78
commit 5715bcd312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -561,3 +561,17 @@ pub trait Middleware: Sync + Send + Debug {
.map_err(FromErr::from) .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)
}
}

View File

@ -15,6 +15,8 @@ use ethers_core::{
utils, utils,
}; };
#[cfg(feature = "celo")]
use crate::CeloMiddleware;
use crate::Middleware; use crate::Middleware;
use async_trait::async_trait; use async_trait::async_trait;
use hex::FromHex; use hex::FromHex;
@ -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] #[async_trait]
impl<P: JsonRpcClient> Middleware for Provider<P> { impl<P: JsonRpcClient> Middleware for Provider<P> {
type Error = ProviderError; type Error = ProviderError;