From ea4247bd9ed57ab7ceecb04d60194303d9de3a1b Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 19 Mar 2024 16:16:51 +0000 Subject: [PATCH] avoid using RootProvider directly, use on_client and new_http --- examples/wallets/Cargo.toml | 1 - examples/wallets/examples/ledger_signer.rs | 12 ++++-------- examples/wallets/examples/private_key_signer.rs | 10 ++++------ examples/wallets/examples/trezor_signer.rs | 10 ++++------ examples/wallets/examples/yubi_signer.rs | 10 ++++------ 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/examples/wallets/Cargo.toml b/examples/wallets/Cargo.toml index 6839cda9..ad91f843 100644 --- a/examples/wallets/Cargo.toml +++ b/examples/wallets/Cargo.toml @@ -22,7 +22,6 @@ alloy-signer-ledger.workspace = true alloy-signer-trezor.workspace = true alloy-signer-wallet = { workspace = true, features = ["mnemonic", "yubihsm"] } alloy-sol-types.workspace = true -alloy-transport-http.workspace = true eyre.workspace = true reqwest.workspace = true diff --git a/examples/wallets/examples/ledger_signer.rs b/examples/wallets/examples/ledger_signer.rs index d887710a..a33cc592 100644 --- a/examples/wallets/examples/ledger_signer.rs +++ b/examples/wallets/examples/ledger_signer.rs @@ -2,26 +2,22 @@ use alloy_network::EthereumSigner; use alloy_primitives::{address, U256}; -use alloy_provider::{Provider, ProviderBuilder, RootProvider}; +use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_client::RpcClient; use alloy_rpc_types::request::TransactionRequest; use alloy_signer_ledger::{HDPath, LedgerSigner}; -use alloy_transport_http::Http; use eyre::Result; -use reqwest::Client; #[tokio::main] async fn main() -> Result<()> { // Instantiate the application by acquiring a lock on the Ledger device. let signer = LedgerSigner::new(HDPath::LedgerLive(0), Some(1)).await?; - // Create a provider with the signer and the network. - let http = Http::::new("http://localhost:8545".parse()?); - - // Initialize the provider. + // Create a provider with the signer. + let http = "http://localhost:8545".parse()?; let provider = ProviderBuilder::new() .signer(EthereumSigner::from(signer)) - .provider(RootProvider::new(RpcClient::new(http, true))); + .on_client(RpcClient::new_http(http)); // Create a transaction. let tx = TransactionRequest { diff --git a/examples/wallets/examples/private_key_signer.rs b/examples/wallets/examples/private_key_signer.rs index 095b974e..01c6ad4c 100644 --- a/examples/wallets/examples/private_key_signer.rs +++ b/examples/wallets/examples/private_key_signer.rs @@ -3,13 +3,11 @@ use alloy_network::EthereumSigner; use alloy_node_bindings::Anvil; use alloy_primitives::U256; -use alloy_provider::{Provider, ProviderBuilder, RootProvider}; +use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_client::RpcClient; use alloy_rpc_types::request::TransactionRequest; use alloy_signer_wallet::LocalWallet; -use alloy_transport_http::Http; use eyre::Result; -use reqwest::Client; #[tokio::main] async fn main() -> Result<()> { @@ -20,11 +18,11 @@ async fn main() -> Result<()> { let alice: LocalWallet = anvil.keys()[0].clone().into(); let bob: LocalWallet = anvil.keys()[1].clone().into(); - // Create a provider with a signer and the network. - let http = Http::::new(anvil.endpoint().parse()?); + // Create a provider with the signer. + let http = "http://localhost:8545".parse()?; let provider = ProviderBuilder::new() .signer(EthereumSigner::from(alice)) - .provider(RootProvider::new(RpcClient::new(http, true))); + .on_client(RpcClient::new_http(http)); // Create a transaction. let tx = TransactionRequest { diff --git a/examples/wallets/examples/trezor_signer.rs b/examples/wallets/examples/trezor_signer.rs index 9cb5eb43..8970c769 100644 --- a/examples/wallets/examples/trezor_signer.rs +++ b/examples/wallets/examples/trezor_signer.rs @@ -2,24 +2,22 @@ use alloy_network::EthereumSigner; use alloy_primitives::{address, U256}; -use alloy_provider::{Provider, ProviderBuilder, RootProvider}; +use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_client::RpcClient; use alloy_rpc_types::request::TransactionRequest; use alloy_signer_trezor::{TrezorHDPath, TrezorSigner}; -use alloy_transport_http::Http; use eyre::Result; -use reqwest::Client; #[tokio::main] async fn main() -> Result<()> { // Instantiate the application by acquiring a lock on the Trezor device. let signer = TrezorSigner::new(TrezorHDPath::TrezorLive(0), Some(1)).await?; - // Create a provider with the signer and the network. - let http = Http::::new("http://localhost:8545".parse()?); + // Create a provider with the signer. + let http = "http://localhost:8545".parse()?; let provider = ProviderBuilder::new() .signer(EthereumSigner::from(signer)) - .provider(RootProvider::new(RpcClient::new(http, true))); + .on_client(RpcClient::new_http(http)); // Create a transaction. let tx = TransactionRequest { diff --git a/examples/wallets/examples/yubi_signer.rs b/examples/wallets/examples/yubi_signer.rs index 14c6e6b3..28a0430e 100644 --- a/examples/wallets/examples/yubi_signer.rs +++ b/examples/wallets/examples/yubi_signer.rs @@ -2,16 +2,14 @@ use alloy_network::EthereumSigner; use alloy_primitives::{address, U256}; -use alloy_provider::{Provider, ProviderBuilder, RootProvider}; +use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_client::RpcClient; use alloy_rpc_types::request::TransactionRequest; use alloy_signer_wallet::{ yubihsm::{Connector, Credentials, UsbConfig}, YubiWallet, }; -use alloy_transport_http::Http; use eyre::Result; -use reqwest::Client; #[tokio::main] async fn main() -> Result<()> { @@ -24,11 +22,11 @@ async fn main() -> Result<()> { // to generate a new keypair. let signer = YubiWallet::connect(connector, Credentials::default(), 0); - // Create a provider with the signer and the network. - let http = Http::::new("http://localhost:8545".parse()?); + // Create a provider with the signer. + let http = "http://localhost:8545".parse()?; let provider = ProviderBuilder::new() .signer(EthereumSigner::from(signer)) - .provider(RootProvider::new(RpcClient::new(http, true))); + .on_client(RpcClient::new_http(http)); // Create a transaction. let tx = TransactionRequest {