diff --git a/src/utils/calldata/index.ts b/src/utils/calldata/index.ts index 02cea47b3..93a29671a 100644 --- a/src/utils/calldata/index.ts +++ b/src/utils/calldata/index.ts @@ -1,7 +1,6 @@ /* eslint-disable no-plusplus */ import { Abi, - AbiEntry, AbiStructs, Args, ArgsOrCalldata, @@ -19,6 +18,7 @@ import { getSelectorFromName } from '../selector'; import { isLongText, splitLongString } from '../shortString'; import { felt, isLen } from './cairo'; import formatter from './formatter'; +import { AbiParser } from './parser'; import orderPropsByAbi from './propertyOrder'; import { parseCalldataField } from './requestParser'; import responseParser from './responseParser'; @@ -29,11 +29,14 @@ export * as cairo from './cairo'; export class CallData { abi: Abi; + parser: AbiParser; + protected readonly structs: AbiStructs; constructor(abi: Abi) { this.abi = abi; this.structs = CallData.getAbiStruct(abi); + this.parser = new AbiParser(abi); } /** @@ -66,7 +69,7 @@ export class CallData { ) as FunctionAbi; // validate arguments length - const inputsLength = CallData.abiInputsLength(abiMethod.inputs); + const inputsLength = this.parser.methodInputsLength(abiMethod); if (args.length !== inputsLength) { throw Error( `Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}` @@ -194,15 +197,6 @@ export class CallData { return formatter(parsed, format); } - /** - * Helper to calculate inputs from abi - * @param inputs AbiEntry - * @returns number - */ - static abiInputsLength(inputs: AbiEntry[]) { - return inputs.reduce((acc, input) => (!isLen(input.name) ? acc + 1 : acc), 0); - } - /** * Helper to extract structs from abi * @param abi Abi