2020-10-08 15:56:36 +00:00
|
|
|
//! # Ethers Middleware
|
2020-09-24 21:33:09 +00:00
|
|
|
//!
|
|
|
|
//! Ethers uses a middleware architecture. You start the middleware stack with
|
2020-10-08 15:56:36 +00:00
|
|
|
//! a [`Provider`](ethers_providers::Provider), and wrap it with additional
|
|
|
|
//! middleware functionalities that you need.
|
2020-09-24 21:33:09 +00:00
|
|
|
//!
|
2020-10-08 15:56:36 +00:00
|
|
|
//! ## Available Middleware
|
|
|
|
//! - Signer
|
|
|
|
//! - Nonce Manager
|
|
|
|
//! - Gas Escalator
|
|
|
|
//! - Gas Oracle
|
2020-09-24 21:33:09 +00:00
|
|
|
//!
|
2020-10-08 15:56:36 +00:00
|
|
|
//! ## Example of a middleware stack
|
2020-09-24 21:33:09 +00:00
|
|
|
//!
|
2020-10-08 15:56:36 +00:00
|
|
|
//! ```no_run
|
|
|
|
//! use ethers::{
|
|
|
|
//! providers::{Provider, Http},
|
|
|
|
//! signers::LocalWallet,
|
|
|
|
//! middleware::{
|
|
|
|
//! gas_escalator::{GasEscalatorMiddleware, GeometricGasPrice, Frequency},
|
|
|
|
//! gas_oracle::{GasOracleMiddleware, GasNow, GasCategory},
|
|
|
|
//! signer::SignerMiddleware,
|
|
|
|
//! nonce_manager::NonceManagerMiddleware,
|
|
|
|
//! },
|
|
|
|
//! core::rand,
|
|
|
|
//! };
|
|
|
|
//! use std::convert::TryFrom;
|
2020-09-24 21:33:09 +00:00
|
|
|
//!
|
2020-10-08 15:56:36 +00:00
|
|
|
//! // Start the stack
|
|
|
|
//! let provider = Provider::<Http>::try_from("http://localhost:8545").unwrap();
|
|
|
|
//!
|
|
|
|
//! // Escalate gas prices
|
|
|
|
//! let escalator = GeometricGasPrice::new(1.125, 60u64, None::<u64>);
|
|
|
|
//! let provider =
|
|
|
|
//! GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);
|
|
|
|
//!
|
|
|
|
//! // Sign transactions with a private key
|
|
|
|
//! let signer = LocalWallet::new(&mut rand::thread_rng());
|
|
|
|
//! let address = signer.address();
|
|
|
|
//! let provider = SignerMiddleware::new(provider, signer);
|
|
|
|
//!
|
|
|
|
//! // Use GasNow as the gas oracle
|
|
|
|
//! let gas_oracle = GasNow::new().category(GasCategory::SafeLow);
|
|
|
|
//! let provider = GasOracleMiddleware::new(provider, gas_oracle);
|
|
|
|
//!
|
|
|
|
//! // Manage nonces locally
|
|
|
|
//! let provider = NonceManagerMiddleware::new(provider, address);
|
|
|
|
//!
|
|
|
|
//! // ... do something with the provider
|
|
|
|
//! ```
|
|
|
|
|
|
|
|
/// The gas escalator middleware is used to re-broadcast transactions with an
|
|
|
|
/// increasing gas price to guarantee their timely inclusion
|
|
|
|
pub mod gas_escalator;
|
|
|
|
|
|
|
|
/// The gas oracle middleware is used to get the gas price from a list of gas oracles
|
|
|
|
/// instead of using eth_gasPrice
|
2020-09-24 21:33:09 +00:00
|
|
|
pub mod gas_oracle;
|
|
|
|
|
2020-10-08 15:56:36 +00:00
|
|
|
/// The nonce manager middleware is used to locally calculate nonces instead of
|
|
|
|
/// using eth_getTransactionCount
|
|
|
|
pub mod nonce_manager;
|
2020-09-24 21:33:09 +00:00
|
|
|
|
2020-10-08 15:56:36 +00:00
|
|
|
/// The signer middleware is used to locally sign transactions and messages
|
|
|
|
/// instead of using eth_sendTransaction and eth_sign
|
|
|
|
pub mod signer;
|
|
|
|
pub use signer::SignerMiddleware;
|