Struct ethers::providers::QuorumProvider [−][src]
pub struct QuorumProvider<T> { /* fields omitted */ }
Expand description
A provider that bundles multiple providers and only returns a value to the caller once the quorum has been reached.
Example
Create a QuorumProvider
that only returns a value if the Quorum::Majority
of
the weighted providers return the same value.
use ethers_core::types::U64;
use ethers_providers::{JsonRpcClient, QuorumProvider, Quorum, WeightedProvider, Http};
use std::str::FromStr;
let provider1 = WeightedProvider::new(Http::from_str("http://localhost:8545")?);
let provider2 = WeightedProvider::with_weight(Http::from_str("http://localhost:8545")?, 2);
let provider3 = WeightedProvider::new(Http::from_str("http://localhost:8545")?);
let provider = QuorumProvider::builder()
.add_providers([provider1, provider2, provider3])
.quorum(Quorum::Majority)
.build();
// the weight at which a quorum is reached,
assert_eq!(provider.quorum_weight(), 4 / 2); // majority >=50%
let block_number: U64 = provider.request("eth_blockNumber", ()).await?;
Implementations
Create a QuorumProvider
for different PubsubClient
types
Convenience method for creating a QuorumProviderBuilder
with same JsonRpcClient
types
pub fn new(
quorum: Quorum,
providers: impl IntoIterator<Item = WeightedProvider<T>>
) -> QuorumProvider<T>
The weight at which the provider reached a quorum
Trait Implementations
type Error = ProviderError
type Error = ProviderError
A JSON-RPC Error
pub fn request<'life0, 'life1, 'async_trait, T, R>(
&'life0 self,
method: &'life1 str,
params: T
) -> Pin<Box<dyn Future<Output = Result<R, <QuorumProvider<C> as JsonRpcClient>::Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
T: Serialize + Send + Sync + 'async_trait,
R: DeserializeOwned + 'async_trait,
QuorumProvider<C>: 'async_trait,
pub fn request<'life0, 'life1, 'async_trait, T, R>(
&'life0 self,
method: &'life1 str,
params: T
) -> Pin<Box<dyn Future<Output = Result<R, <QuorumProvider<C> as JsonRpcClient>::Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
T: Serialize + Send + Sync + 'async_trait,
R: DeserializeOwned + 'async_trait,
QuorumProvider<C>: 'async_trait,
Sends a request with the provided JSON-RPC and parameters serialized as JSON
type NotificationStream = QuorumStream
type NotificationStream = QuorumStream
The type of stream this transport returns
pub fn subscribe<T>(
&self,
id: T
) -> Result<<QuorumProvider<C> as PubsubClient>::NotificationStream, <QuorumProvider<C> as JsonRpcClient>::Error> where
T: Into<U256>,
pub fn subscribe<T>(
&self,
id: T
) -> Result<<QuorumProvider<C> as PubsubClient>::NotificationStream, <QuorumProvider<C> as JsonRpcClient>::Error> where
T: Into<U256>,
Add a subscription to this transport
pub fn unsubscribe<T>(
&self,
id: T
) -> Result<(), <QuorumProvider<C> as JsonRpcClient>::Error> where
T: Into<U256>,
pub fn unsubscribe<T>(
&self,
id: T
) -> Result<(), <QuorumProvider<C> as JsonRpcClient>::Error> where
T: Into<U256>,
Remove a subscription from this transport
Auto Trait Implementations
impl<T> RefUnwindSafe for QuorumProvider<T> where
T: RefUnwindSafe,
impl<T> Send for QuorumProvider<T> where
T: Send,
impl<T> Sync for QuorumProvider<T> where
T: Sync,
impl<T> Unpin for QuorumProvider<T> where
T: Unpin,
impl<T> UnwindSafe for QuorumProvider<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more