chore: export quorum's JsonRpcClientWrapper (#1439)

This commit is contained in:
Matthias Seitz 2022-06-30 19:04:43 +02:00 committed by GitHub
parent ee8a02502e
commit de1020c91e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 6 deletions

View File

@ -33,8 +33,7 @@ mod ws;
pub use ws::{ClientError as WsClientError, Ws}; pub use ws::{ClientError as WsClientError, Ws};
mod quorum; mod quorum;
pub(crate) use quorum::JsonRpcClientWrapper; pub use quorum::{JsonRpcClientWrapper, Quorum, QuorumError, QuorumProvider, WeightedProvider};
pub use quorum::{Quorum, QuorumError, QuorumProvider, WeightedProvider};
mod rw; mod rw;
pub use rw::{RwClient, RwClientError}; pub use rw::{RwClient, RwClientError};

View File

@ -20,10 +20,10 @@ use thiserror::Error;
/// ///
/// # Example /// # Example
/// ///
/// Create a `QuorumProvider` that only returns a value if the `Quorum::Majority` of /// Create a `QuorumProvider` that uses a homogenous `Provider` type only returns a value if the
/// the weighted providers return the same value. /// `Quorum::Majority` of the weighted providers return the same value.
/// ///
/// ```no_run /// ```
/// use ethers_core::types::U64; /// use ethers_core::types::U64;
/// use ethers_providers::{JsonRpcClient, QuorumProvider, Quorum, WeightedProvider, Http}; /// use ethers_providers::{JsonRpcClient, QuorumProvider, Quorum, WeightedProvider, Http};
/// use std::str::FromStr; /// use std::str::FromStr;
@ -43,8 +43,37 @@ use thiserror::Error;
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
///
/// # 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;
///
/// # async fn foo() -> Result<(), Box<dyn std::error::Error>> {
/// 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();
///
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct QuorumProvider<T> { pub struct QuorumProvider<T = Box<dyn JsonRpcClientWrapper>> {
/// What kind of quorum is required /// What kind of quorum is required
quorum: Quorum, quorum: Quorum,
/// The weight at which quorum is reached /// The weight at which quorum is reached