1+ use crate :: errors:: FunctionSignatureError ;
12use ethers_core:: {
23 abi:: Function ,
34 types:: {
@@ -6,7 +7,7 @@ use ethers_core::{
67 } ,
78} ;
89use ethers_providers:: Middleware ;
9- use eyre:: { eyre, Result , WrapErr } ;
10+ use eyre:: { eyre, Result } ;
1011use foundry_common:: abi:: { encode_args, get_func, get_func_etherscan} ;
1112use foundry_config:: Chain ;
1213use futures:: future:: join_all;
@@ -172,19 +173,24 @@ impl<'a, M: Middleware> TxBuilder<'a, M> {
172173 let args = resolve_name_args ( & args, self . provider ) . await ;
173174
174175 let func = if sig. contains ( '(' ) {
176+ // a regular function signature with parentheses
175177 get_func ( sig) ?
176178 } else if sig. starts_with ( "0x" ) {
177179 // if only calldata is provided, returning a dummy function
178180 get_func ( "x()" ) ?
179181 } else {
180- let chain =
181- self . chain . try_into ( ) . wrap_err ( "resolving via etherscan requires a known chain" ) ?;
182+ let chain = self
183+ . chain
184+ . try_into ( )
185+ . map_err ( |_| FunctionSignatureError :: UnknownChain ( self . chain ) ) ?;
182186 get_func_etherscan (
183187 sig,
184- self . to . ok_or_else ( || eyre :: eyre! ( "to value must be set" ) ) ?,
188+ self . to . ok_or ( FunctionSignatureError :: MissingToAddress ) ?,
185189 & args,
186190 chain,
187- self . etherscan_api_key . as_ref ( ) . unwrap_or_else ( || panic ! ( r#"Unable to determine the function signature from `{}`. To find the function signature from the deployed contract via its name instead, a valid ETHERSCAN_API_KEY must be set."# , sig) ) ,
191+ self . etherscan_api_key . as_ref ( ) . ok_or_else ( || {
192+ FunctionSignatureError :: MissingEtherscan { sig : sig. to_string ( ) }
193+ } ) ?,
188194 )
189195 . await ?
190196 } ;
@@ -263,16 +269,12 @@ async fn resolve_name_args<M: Middleware>(args: &[String], provider: &M) -> Vec<
263269#[ cfg( test) ]
264270mod tests {
265271 use crate :: TxBuilder ;
266-
272+ use async_trait :: async_trait ;
267273 use ethers_core:: types:: {
268274 transaction:: eip2718:: TypedTransaction , Address , Chain , NameOrAddress , H160 , U256 ,
269275 } ;
270276 use ethers_providers:: { JsonRpcClient , Middleware , ProviderError } ;
271-
272277 use serde:: { de:: DeserializeOwned , Serialize } ;
273-
274- use async_trait:: async_trait;
275-
276278 use std:: str:: FromStr ;
277279
278280 const ADDR_1 : & str = "0000000000000000000000000000000000000001" ;
0 commit comments