Skip to content

Commit

Permalink
Get chain info from provider
Browse files Browse the repository at this point in the history
  • Loading branch information
pawurb committed Nov 11, 2024
1 parent 6f50c3c commit b3e4cd3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
11 changes: 6 additions & 5 deletions crates/cast/bin/cmd/artifact.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_primitives::Address;
use alloy_provider::Provider;
use clap::{command, Parser};
use eyre::Result;
use foundry_block_explorers::Client;
Expand Down Expand Up @@ -49,13 +50,13 @@ impl ArtifactArgs {
pub async fn run(self) -> Result<()> {
let Self { contract, etherscan, rpc, output: output_location, abi_path } = self;

let config = Config::from(&etherscan);
let chain = config.chain.unwrap_or_default();
let api_key = config.get_etherscan_api_key(Some(chain)).unwrap_or_default();
let client = Client::new(chain, api_key)?;

let mut etherscan = etherscan;
let config = Config::from(&rpc);
let provider = utils::get_provider(&config)?;
let api_key = etherscan.key().unwrap_or_default();
let chain = provider.get_chain_id().await?;
etherscan.chain = Some(chain.into());
let client = Client::new(chain.into(), api_key)?;

let abi = if let Some(ref abi_path) = abi_path {
load_abi_from_file(abi_path, None)?
Expand Down
11 changes: 6 additions & 5 deletions crates/cast/bin/cmd/constructor_args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloy_dyn_abi::DynSolType;
use alloy_primitives::{Address, Bytes};
use alloy_provider::Provider;
use clap::{command, Parser};
use eyre::{eyre, OptionExt, Result};
use foundry_block_explorers::Client;
Expand Down Expand Up @@ -36,13 +37,13 @@ impl ConstructorArgsArgs {
pub async fn run(self) -> Result<()> {
let Self { contract, etherscan, rpc, abi_path } = self;

let config = Config::from(&etherscan);
let chain = config.chain.unwrap_or_default();
let api_key = config.get_etherscan_api_key(Some(chain)).unwrap_or_default();
let client = Client::new(chain, api_key)?;

let mut etherscan = etherscan;
let config = Config::from(&rpc);
let provider = utils::get_provider(&config)?;
let api_key = etherscan.key().unwrap_or_default();
let chain = provider.get_chain_id().await?;
etherscan.chain = Some(chain.into());
let client = Client::new(chain.into(), api_key)?;

let bytecode = fetch_creation_code(contract, client, provider).await?;

Expand Down
10 changes: 5 additions & 5 deletions crates/cast/bin/cmd/creation_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ impl CreationCodeArgs {
let Self { contract, etherscan, rpc, disassemble, without_args, only_args, abi_path } =
self;

let config = Config::from(&etherscan);
let chain = config.chain.unwrap_or_default();
let api_key = config.get_etherscan_api_key(Some(chain)).unwrap_or_default();
let client = Client::new(chain, api_key)?;

let mut etherscan = etherscan;
let config = Config::from(&rpc);
let provider = utils::get_provider(&config)?;
let api_key = etherscan.key().unwrap_or_default();
let chain = provider.get_chain_id().await?;
etherscan.chain = Some(chain.into());
let client = Client::new(chain.into(), api_key)?;

let bytecode = fetch_creation_code(contract, client, provider).await?;

Expand Down

0 comments on commit b3e4cd3

Please sign in to comment.