( parameters: EncodeErrorResultParameters<abi, errorName>, )
| 66 | | ErrorType |
| 67 | |
| 68 | export function encodeErrorResult< |
| 69 | const abi extends Abi | readonly unknown[], |
| 70 | errorName extends ContractErrorName<abi> | undefined = undefined, |
| 71 | >( |
| 72 | parameters: EncodeErrorResultParameters<abi, errorName>, |
| 73 | ): EncodeErrorResultReturnType { |
| 74 | const { abi, errorName, args } = parameters as EncodeErrorResultParameters |
| 75 | |
| 76 | let abiItem = abi[0] |
| 77 | if (errorName) { |
| 78 | const item = getAbiItem({ abi, args, name: errorName }) |
| 79 | if (!item) throw new AbiErrorNotFoundError(errorName, { docsPath }) |
| 80 | abiItem = item |
| 81 | } |
| 82 | |
| 83 | if (abiItem.type !== 'error') |
| 84 | throw new AbiErrorNotFoundError(undefined, { docsPath }) |
| 85 | |
| 86 | const definition = formatAbiItem(abiItem) |
| 87 | const signature = toFunctionSelector(definition) |
| 88 | |
| 89 | let data: Hex = '0x' |
| 90 | if (args && args.length > 0) { |
| 91 | if (!abiItem.inputs) |
| 92 | throw new AbiErrorInputsNotFoundError(abiItem.name, { docsPath }) |
| 93 | data = encodeAbiParameters(abiItem.inputs, args) |
| 94 | } |
| 95 | return concatHex([signature, data]) |
| 96 | } |
no test coverage detected