1
- use super :: interface:: { fetch_abi_from_etherscan , load_abi_from_file} ;
1
+ use super :: interface:: load_abi_from_file;
2
2
use crate :: SimpleCast ;
3
3
use alloy_consensus:: Transaction ;
4
4
use alloy_primitives:: { Address , Bytes } ;
@@ -11,7 +11,10 @@ use foundry_cli::{
11
11
opts:: { EtherscanOpts , RpcOpts } ,
12
12
utils:: { self , LoadConfig } ,
13
13
} ;
14
- use foundry_common:: provider:: RetryProvider ;
14
+ use foundry_common:: { abi:: fetch_abi_from_etherscan, provider:: RetryProvider } ;
15
+ use foundry_config:: Config ;
16
+
17
+ foundry_config:: impl_figment_convert!( CreationCodeArgs , etherscan, rpc) ;
15
18
16
19
/// CLI arguments for `cast creation-code`.
17
20
#[ derive( Parser ) ]
@@ -45,20 +48,21 @@ pub struct CreationCodeArgs {
45
48
46
49
impl CreationCodeArgs {
47
50
pub async fn run ( self ) -> Result < ( ) > {
48
- let Self { contract, mut etherscan, rpc, disassemble, without_args, only_args, abi_path } =
51
+ let mut config = self . load_config ( ) ?;
52
+
53
+ let Self { contract, disassemble, without_args, only_args, abi_path, etherscan : _, rpc : _ } =
49
54
self ;
50
55
51
- let config = rpc. load_config ( ) ?;
52
56
let provider = utils:: get_provider ( & config) ?;
53
57
let chain = provider. get_chain_id ( ) . await ?;
54
- etherscan . chain = Some ( chain. into ( ) ) ;
58
+ config . chain = Some ( chain. into ( ) ) ;
55
59
56
- let bytecode = fetch_creation_code_from_etherscan ( contract, & etherscan , provider) . await ?;
60
+ let bytecode = fetch_creation_code_from_etherscan ( contract, & config , provider) . await ?;
57
61
58
62
let bytecode = parse_code_output (
59
63
bytecode,
60
64
contract,
61
- & etherscan ,
65
+ & config ,
62
66
abi_path. as_deref ( ) ,
63
67
without_args,
64
68
only_args,
@@ -82,7 +86,7 @@ impl CreationCodeArgs {
82
86
pub async fn parse_code_output (
83
87
bytecode : Bytes ,
84
88
contract : Address ,
85
- etherscan : & EtherscanOpts ,
89
+ config : & Config ,
86
90
abi_path : Option < & str > ,
87
91
without_args : bool ,
88
92
only_args : bool ,
@@ -94,7 +98,7 @@ pub async fn parse_code_output(
94
98
let abi = if let Some ( abi_path) = abi_path {
95
99
load_abi_from_file ( abi_path, None ) ?
96
100
} else {
97
- fetch_abi_from_etherscan ( contract, etherscan ) . await ?
101
+ fetch_abi_from_etherscan ( contract, config ) . await ?
98
102
} ;
99
103
100
104
let abi = abi. into_iter ( ) . next ( ) . ok_or_eyre ( "No ABI found." ) ?;
@@ -131,10 +135,9 @@ pub async fn parse_code_output(
131
135
/// Fetches the creation code of a contract from Etherscan and RPC.
132
136
pub async fn fetch_creation_code_from_etherscan (
133
137
contract : Address ,
134
- etherscan : & EtherscanOpts ,
138
+ config : & Config ,
135
139
provider : RetryProvider ,
136
140
) -> Result < Bytes > {
137
- let config = etherscan. load_config ( ) ?;
138
141
let chain = config. chain . unwrap_or_default ( ) ;
139
142
let api_version = config. get_etherscan_api_version ( Some ( chain) ) ;
140
143
let api_key = config. get_etherscan_api_key ( Some ( chain) ) . unwrap_or_default ( ) ;
0 commit comments