diff --git a/Cargo.lock b/Cargo.lock index d1b5acc..15e96eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,8 @@ dependencies = [ "alloy-rpc-client", "alloy-rpc-types", "alloy-serde", + "alloy-signer", + "alloy-signer-local", "alloy-transport", "alloy-transport-http", "alloy-transport-ipc", @@ -519,6 +521,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-signer-local" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6e72002cc1801d8b41e9892165e3a6551b7bd382bd9d0414b21e90c0c62551" +dependencies = [ + "alloy-consensus", + "alloy-network", + "alloy-primitives", + "alloy-signer", + "async-trait", + "k256", + "rand", + "thiserror", +] + [[package]] name = "alloy-sol-macro" version = "0.8.23" @@ -2967,6 +2985,7 @@ dependencies = [ name = "revive-dt-config" version = "0.1.0" dependencies = [ + "alloy", "clap", "semver 1.0.26", "temp-dir", diff --git a/Cargo.toml b/Cargo.toml index b73b8e7..706e657 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,7 @@ features = [ "provider-debug-api", "reqwest", "rpc-types", + "signer-local", "std", ] diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index 3ab45c0..5df52e9 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -9,6 +9,7 @@ repository.workspace = true rust-version.workspace = true [dependencies] +alloy = { workspace = true } clap = { workspace = true } semver = { workspace = true } temp-dir = { workspace = true } diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 0c6114e..b186416 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -2,6 +2,7 @@ use std::path::{Path, PathBuf}; +use alloy::{network::EthereumWallet, signers::local::PrivateKeySigner}; use clap::{Parser, ValueEnum}; use semver::Version; use temp_dir::TempDir; @@ -85,6 +86,10 @@ pub struct Arguments { } impl Arguments { + /// Return the configured working directory with the following precedence: + /// 1. `self.working_directory` if it was provided. + /// 2. `self.temp_dir` if it it was provided + /// 3. Panic. pub fn directory(&self) -> &Path { if let Some(path) = &self.working_directory { return path.as_path(); @@ -96,6 +101,18 @@ impl Arguments { panic!("should have a workdir configured") } + + /// Try to parse `self.account` into a [PrivateKeySigner], + /// panicing on error. + pub fn wallet(&self) -> EthereumWallet { + let signer = self + .account + .parse::() + .unwrap_or_else(|error| { + panic!("private key '{}' parsing error: {error}", self.account); + }); + EthereumWallet::new(signer) + } } impl Default for Arguments { diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 84c6b31..e3de017 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -11,6 +11,7 @@ use std::{ }; use alloy::{ + network::EthereumWallet, providers::{Provider, ProviderBuilder, ext::DebugApi}, rpc::types::{ TransactionReceipt, TransactionRequest, @@ -43,6 +44,7 @@ pub struct Instance { handle: Option, network_id: u64, start_timeout: u64, + wallet: EthereumWallet, } impl Instance { @@ -148,9 +150,11 @@ impl EthereumNode for Instance { transaction: TransactionRequest, ) -> anyhow::Result { let connection_string = self.connection_string(); + let wallet = self.wallet.clone(); execute_transaction(Box::pin(async move { Ok(ProviderBuilder::new() + .wallet(wallet) .connect(&connection_string) .await? .send_transaction(transaction) @@ -170,9 +174,11 @@ impl EthereumNode for Instance { disable_code: None, disable_storage: None, }); + let wallet = self.wallet.clone(); trace_transaction(Box::pin(async move { Ok(ProviderBuilder::new() + .wallet(wallet) .connect(&connection_string) .await? .debug_trace_transaction(transaction.transaction_hash, trace_options) @@ -196,6 +202,7 @@ impl Node for Instance { handle: None, network_id: config.network_id, start_timeout: config.geth_start_timeout, + wallet: config.wallet(), } }