diff --git a/src/utils/calldata/index.ts b/src/utils/calldata/index.ts index 23338a77a..c32337f4e 100644 --- a/src/utils/calldata/index.ts +++ b/src/utils/calldata/index.ts @@ -35,7 +35,6 @@ export class CallData { protected readonly structs: AbiStructs; constructor(abi: Abi) { - // this.abi = abi; this.structs = CallData.getAbiStruct(abi); this.parser = createAbiParser(abi); this.abi = this.parser.getLegacyFormat(); diff --git a/src/utils/calldata/parser/interface.ts b/src/utils/calldata/parser/interface.ts index 6784c39d0..895b3a1b5 100644 --- a/src/utils/calldata/parser/interface.ts +++ b/src/utils/calldata/parser/interface.ts @@ -2,10 +2,22 @@ import { Abi, FunctionAbi } from '../../../types'; export abstract class AbiParserInterface { /** - * Helper to calculate inputs from abi + * Helper to calculate inputs length from abi * @param abiMethod FunctionAbi + * @return number */ public abstract methodInputsLength(abiMethod: FunctionAbi): number; + + /** + * + * @param name string + * @return FunctionAbi | undefined + */ public abstract getMethod(name: string): FunctionAbi | undefined; + + /** + * Return Abi in legacy format + * @return Abi + */ public abstract getLegacyFormat(): Abi; } diff --git a/src/utils/calldata/parser/parser-0-1.1.0.ts b/src/utils/calldata/parser/parser-0-1.1.0.ts index 8a845ca4d..632fcf902 100644 --- a/src/utils/calldata/parser/parser-0-1.1.0.ts +++ b/src/utils/calldata/parser/parser-0-1.1.0.ts @@ -19,10 +19,19 @@ export class AbiParser1 implements AbiParserInterface { return abiMethod.inputs.reduce((acc, input) => (!isLen(input.name) ? acc + 1 : acc), 0); } + /** + * get method definition from abi + * @param name string + * @returns FunctionAbi | undefined + */ public getMethod(name: string): FunctionAbi | undefined { return this.abi.find((it) => it.name === name); } + /** + * Get Abi in legacy format + * @returns Abi + */ public getLegacyFormat() { return this.abi; } diff --git a/src/utils/calldata/parser/parser-2.0.0.ts b/src/utils/calldata/parser/parser-2.0.0.ts index 911fc2929..6c9d7b2ba 100644 --- a/src/utils/calldata/parser/parser-2.0.0.ts +++ b/src/utils/calldata/parser/parser-2.0.0.ts @@ -9,7 +9,7 @@ export class AbiParser2 implements AbiParserInterface { } /** - * abi method inputs length without + * abi method inputs length * @param abiMethod FunctionAbi * @returns number */ @@ -17,12 +17,21 @@ export class AbiParser2 implements AbiParserInterface { return abiMethod.inputs.length; } + /** + * get method definition from abi + * @param name string + * @returns FunctionAbi | undefined + */ public getMethod(name: string): FunctionAbi | undefined { const intf = this.abi.find((it) => it.type === 'interface'); - return intf.items.find((it) => it.name === name); + return intf.items.find((it: any) => it.name === name); } - public getLegacyFormat() { + /** + * Get Abi in legacy format + * @returns Abi + */ + public getLegacyFormat(): Abi { return this.abi.flatMap((e) => { if (e.type === 'interface') { return e.items;