the localsigner wallet

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Cyrill Leutwiler
2025-03-31 10:19:12 +02:00
parent ea17166448
commit 9505e30fe1
5 changed files with 45 additions and 0 deletions
Generated
+19
View File
@@ -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",
+1
View File
@@ -52,6 +52,7 @@ features = [
"provider-debug-api",
"reqwest",
"rpc-types",
"signer-local",
"std",
]
+1
View File
@@ -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 }
+17
View File
@@ -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::<PrivateKeySigner>()
.unwrap_or_else(|error| {
panic!("private key '{}' parsing error: {error}", self.account);
});
EthereumWallet::new(signer)
}
}
impl Default for Arguments {
+7
View File
@@ -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<Child>,
network_id: u64,
start_timeout: u64,
wallet: EthereumWallet,
}
impl Instance {
@@ -148,9 +150,11 @@ impl EthereumNode for Instance {
transaction: TransactionRequest,
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
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(),
}
}