@@ -12,7 +12,7 @@ use build::PreprocessedState;
1212use clap:: { Parser , ValueHint } ;
1313use dialoguer:: Confirm ;
1414use ethers_signers:: Signer ;
15- use eyre:: { ContextCompat , Result , WrapErr } ;
15+ use eyre:: { ContextCompat , Result } ;
1616use forge_verify:: RetryArgs ;
1717use foundry_cli:: { opts:: CoreBuildArgs , utils:: LoadConfig } ;
1818use foundry_common:: {
@@ -311,30 +311,38 @@ impl ScriptArgs {
311311 ///
312312 /// Note: We assume that the `sig` is already stripped of its prefix, See [`ScriptArgs`]
313313 fn get_method_and_calldata ( & self , abi : & JsonAbi ) -> Result < ( Function , Bytes ) > {
314- let ( func, data) = if let Ok ( func) = get_func ( & self . sig ) {
315- (
316- abi. functions ( ) . find ( |& abi_func| abi_func. selector ( ) == func. selector ( ) ) . wrap_err (
317- format ! ( "Function `{}` is not implemented in your script." , self . sig) ,
318- ) ?,
319- encode_function_args ( & func, & self . args ) ?. into ( ) ,
320- )
321- } else {
322- let decoded = hex:: decode ( & self . sig ) . wrap_err ( "Invalid hex calldata" ) ?;
314+ if let Ok ( decoded) = hex:: decode ( & self . sig ) {
323315 let selector = & decoded[ ..SELECTOR_LEN ] ;
324- (
325- abi. functions ( ) . find ( |& func| selector == & func. selector ( ) [ ..] ) . ok_or_else (
326- || {
327- eyre:: eyre!(
328- "Function selector `{}` not found in the ABI" ,
329- hex:: encode( selector)
330- )
331- } ,
332- ) ?,
333- decoded. into ( ) ,
334- )
316+ let func =
317+ abi. functions ( ) . find ( |func| selector == & func. selector ( ) [ ..] ) . ok_or_else ( || {
318+ eyre:: eyre!(
319+ "Function selector `{}` not found in the ABI" ,
320+ hex:: encode( selector)
321+ )
322+ } ) ?;
323+ return Ok ( ( func. clone ( ) , decoded. into ( ) ) ) ;
324+ }
325+
326+ let func = if self . sig . contains ( '(' ) {
327+ let func = get_func ( & self . sig ) ?;
328+ abi. functions ( )
329+ . find ( |& abi_func| abi_func. selector ( ) == func. selector ( ) )
330+ . wrap_err ( format ! ( "Function `{}` is not implemented in your script." , self . sig) ) ?
331+ } else {
332+ let matching_functions =
333+ abi. functions ( ) . filter ( |func| func. name == self . sig ) . collect :: < Vec < _ > > ( ) ;
334+ match matching_functions. len ( ) {
335+ 0 => eyre:: bail!( "Function `{}` not found in the ABI" , self . sig) ,
336+ 1 => matching_functions[ 0 ] ,
337+ 2 .. => eyre:: bail!(
338+ "Multiple functions with the same name `{}` found in the ABI" ,
339+ self . sig
340+ ) ,
341+ }
335342 } ;
343+ let data = encode_function_args ( func, & self . args ) ?;
336344
337- Ok ( ( func. clone ( ) , data) )
345+ Ok ( ( func. clone ( ) , data. into ( ) ) )
338346 }
339347
340348 /// Checks if the transaction is a deployment with either a size above the `CONTRACT_MAX_SIZE`
0 commit comments