feat: extend Middleware trait customized for celo (#314)
* Add CeloMiddleware trait * change types of block number and returned keys
This commit is contained in:
parent
1dda336a78
commit
5715bcd312
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue