This commit is contained in:
pgherveou
2025-10-08 11:18:31 +02:00
parent 43a1114337
commit dffb80ac0a
2 changed files with 33 additions and 5 deletions
+15 -2
View File
@@ -131,7 +131,11 @@ impl GethNode {
}
pub async fn new_existing(private_key: &str, rpc_port: u16) -> anyhow::Result<Self> {
use alloy::{primitives::FixedBytes, signers::local::PrivateKeySigner};
use alloy::{
primitives::FixedBytes,
providers::{Provider, ProviderBuilder},
signers::local::PrivateKeySigner,
};
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim());
let key_bytes = alloy::hex::decode(key_str)
@@ -152,6 +156,13 @@ impl GethNode {
let address = signer.address();
let wallet = Arc::new(EthereumWallet::new(signer));
let connection_string = format!("http://localhost:{}", rpc_port);
let chain_id = ProviderBuilder::new()
.connect_http(connection_string.parse()?)
.get_chain_id()
.await
.context("Failed to query chain ID from RPC")?;
let node = Self {
connection_string: format!("http://localhost:{}", rpc_port),
@@ -160,7 +171,7 @@ impl GethNode {
logs_directory: PathBuf::new(),
geth: PathBuf::new(),
id: 0,
chain_id: 1337,
chain_id,
handle: None,
start_timeout: Duration::from_secs(0),
wallet,
@@ -174,6 +185,8 @@ impl GethNode {
Ok(node)
}
/// Ensure that the given address has at least 1000 ETH, funding it from the node's managed
/// account if necessary.
async fn ensure_funded(&self, address: Address) -> anyhow::Result<()> {
use alloy::{
primitives::utils::{format_ether, parse_ether},
@@ -80,6 +80,7 @@ pub struct SubstrateNode {
wallet: Arc<EthereumWallet>,
nonce_manager: CachedNonceManager,
provider: OnceCell<ConcreteProvider<ReviveNetwork, Arc<EthereumWallet>>>,
chain_id: alloy::primitives::ChainId,
}
impl SubstrateNode {
@@ -129,11 +130,16 @@ impl SubstrateNode {
wallet: wallet.clone(),
nonce_manager: Default::default(),
provider: Default::default(),
chain_id: CHAIN_ID,
}
}
pub async fn new_existing(private_key: &str, rpc_port: u16) -> anyhow::Result<Self> {
use alloy::{primitives::FixedBytes, signers::local::PrivateKeySigner};
use alloy::{
primitives::FixedBytes,
providers::{Provider, ProviderBuilder},
signers::local::PrivateKeySigner,
};
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim());
let key_bytes = alloy::hex::decode(key_str)
@@ -153,13 +159,21 @@ impl SubstrateNode {
.map_err(|e| anyhow::anyhow!("Failed to create signer from private key: {}", e))?;
let wallet = Arc::new(EthereumWallet::new(signer));
let rpc_url = format!("http://localhost:{}", rpc_port);
// Query the chain ID from the RPC
let chain_id = ProviderBuilder::new()
.connect_http(rpc_url.parse()?)
.get_chain_id()
.await
.context("Failed to query chain ID from RPC")?;
Ok(Self {
id: 0,
node_binary: PathBuf::new(),
eth_proxy_binary: PathBuf::new(),
export_chainspec_command: String::new(),
rpc_url: format!("http://localhost:{}", rpc_port),
rpc_url,
base_directory: PathBuf::new(),
logs_directory: PathBuf::new(),
substrate_process: None,
@@ -167,6 +181,7 @@ impl SubstrateNode {
wallet,
nonce_manager: Default::default(),
provider: Default::default(),
chain_id,
})
}
@@ -383,7 +398,7 @@ impl SubstrateNode {
construct_concurrency_limited_provider::<ReviveNetwork, _>(
self.rpc_url.as_str(),
FallbackGasFiller::new(u64::MAX, 5_000_000_000, 1_000_000_000),
ChainIdFiller::new(Some(CHAIN_ID)),
ChainIdFiller::new(Some(self.chain_id)),
NonceFiller::new(self.nonce_manager.clone()),
self.wallet.clone(),
)