import { utils as ethersUtils } from 'ethers' ; import { Abi } from '../types' ; export function findMethodAbiFragment ( abi , methodSignature ) { if ( methodSignature === 'fallback' ) { return abi . find ( ( method ) => method . type === 'fallback' ) ; } const fullMethodSignature = Boolean ( methodSignature ) && methodSignature . includes ( '(' ) && methodSignature . includes ( ')' ) ; const methodAbiFragment = abi . filter ( ( method ) => method . type === 'function' ) . find ( ( method ) => { if ( ! fullMethodSignature ) { return method . name === methodSignature ; } const currentParameterTypes = method . inputs . map ( ( { type } ) => type ) ; const currentMethodSignature = `${ method . name }(${ currentParameterTypes . join ( ',' ) })` ; return currentMethodSignature === methodSignature ; } ) ; return methodAbiFragment ; }