Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni authored and PhilippeR26 committed Jul 11, 2023
1 parent 92b2be5 commit ff35d5f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/utils/calldata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion src/utils/calldata/parser/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions src/utils/calldata/parser/parser-0-1.1.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 12 additions & 3 deletions src/utils/calldata/parser/parser-2.0.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ export class AbiParser2 implements AbiParserInterface {
}

/**
* abi method inputs length without
* abi method inputs length
* @param abiMethod FunctionAbi
* @returns number
*/
public methodInputsLength(abiMethod: FunctionAbi) {
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;
Expand Down

0 comments on commit ff35d5f

Please sign in to comment.