pub struct QuorumProvider<T = Box<dyn JsonRpcClientWrapper>> { /* private fields */ }
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 uses a homogenous Provider type 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?;

Example

Create a QuorumProvider consisting of different Provider types

use ethers_core::types::U64;
use ethers_providers::{JsonRpcClient, QuorumProvider, Quorum, WeightedProvider, Http, Ws};
use std::str::FromStr;

    let provider: QuorumProvider = QuorumProvider::dyn_rpc()
        .add_provider(WeightedProvider::new(Box::new(Http::from_str("http://localhost:8545")?)))
        .add_provider(WeightedProvider::with_weight(
            Box::new(Ws::connect("ws://localhost:8545").await?),
            2,
        ))
        .add_provider(WeightedProvider::with_weight(
            Box::new(Ws::connect("ws://localhost:8545").await?),
            2,
        ))
        // the quorum provider will yield the response if >50% of the weighted inner provider
        // returned the same value
        .quorum(Quorum::Majority)
        .build();

Implementations§

Create a QuorumProvider for different JsonRpcClient types

Create a QuorumProvider for different PubsubClient types

Convenience method for creating a QuorumProviderBuilder with same JsonRpcClient types

The weight at which the provider reached a quorum

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
A JSON-RPC Error
Sends a request with the provided JSON-RPC and parameters serialized as JSON
The type of stream this transport returns
Add a subscription to this transport
Remove a subscription from this transport

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
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