| 54 | | ErrorType |
| 55 | |
| 56 | export function decodeFunctionData<const abi extends Abi | readonly unknown[]>( |
| 57 | parameters: DecodeFunctionDataParameters<abi>, |
| 58 | ) { |
| 59 | const { abi, data } = parameters as DecodeFunctionDataParameters |
| 60 | const signature = slice(data, 0, 4) |
| 61 | const description = abi.find( |
| 62 | (x) => |
| 63 | x.type === 'function' && |
| 64 | signature === toFunctionSelector(formatAbiItem(x)), |
| 65 | ) |
| 66 | if (!description) |
| 67 | throw new AbiFunctionSignatureNotFoundError(signature, { |
| 68 | docsPath: '/docs/contract/decodeFunctionData', |
| 69 | }) |
| 70 | return { |
| 71 | functionName: (description as { name: string }).name, |
| 72 | args: ('inputs' in description && |
| 73 | description.inputs && |
| 74 | description.inputs.length > 0 |
| 75 | ? decodeAbiParameters(description.inputs, slice(data, 4)) |
| 76 | : undefined) as readonly unknown[] | undefined, |
| 77 | } as DecodeFunctionDataReturnType<abi> |
| 78 | } |