-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "new abi coder: @ethersproject/abi => web3-eth-abi"
- Loading branch information
Showing
21 changed files
with
486 additions
and
1,647 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
import { decodeParameters, encodeFunctionCall } from 'web3-eth-abi'; | ||
|
||
export const encodeFunction = ( | ||
method: string, | ||
params: any[], | ||
abi: any, | ||
): string => { | ||
const abiItem = abi?.find((item: any) => item.name === method); | ||
import { defaultAbiCoder as AbiCoder } from '@ethersproject/abi/lib/abi-coder'; | ||
import { Interface } from '@ethersproject/abi'; | ||
|
||
export const getAbiInputsOutputsType = (abi: any, method: string) => { | ||
const abiItem = abi.find((item: any) => item.name === method); | ||
if (!abiItem) { | ||
throw new Error('ABI item not found'); | ||
throw new Error('ABI not found'); | ||
} | ||
|
||
const paramStringAbi = encodeFunctionCall(abiItem, params).slice(2); | ||
return paramStringAbi; | ||
return { | ||
inputs: abiItem.inputs.map((input: any) => input.type), | ||
outputs: abiItem.outputs.map((output: any) => output.type), | ||
outputNames: abiItem.outputs | ||
.filter((output: any) => !!output.name) | ||
.map((output: any) => output.name), | ||
}; | ||
}; | ||
|
||
export const decodeReturnValue = ( | ||
method: string, | ||
returnValue: Buffer, | ||
abi: any, | ||
) => { | ||
const abiItem = abi?.find((item: any) => item.name === method); | ||
|
||
export const getAbiInputsOutputs = (abi: any, method: string) => { | ||
const abiItem = abi.find((item: any) => item.name === method); | ||
if (!abiItem) { | ||
throw new Error('ABI item not found'); | ||
throw new Error('ABI not found'); | ||
} | ||
|
||
const paramStringAbi: any = decodeParameters(abiItem.outputs, returnValue.toString('hex')); | ||
return paramStringAbi; | ||
return { | ||
inputs: abiItem.inputs, | ||
outputs: abiItem.outputs, | ||
}; | ||
}; | ||
|
||
export const encodeFunction = ( | ||
method: string, | ||
params: any[] = [], | ||
inputs: any[] = [], | ||
): string => { | ||
const methodWithParameters = `function ${method}(${inputs.join(',')})`; | ||
const signatureHash = new Interface([methodWithParameters]).getSighash(method); | ||
const paramStringAbi = (params.length ? AbiCoder.encode(inputs, params) : '').slice(2); | ||
return signatureHash.slice(2) + paramStringAbi; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/tssdk/src/libs/evm-api/exceptions/method-does-not-exist.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class MethodDoesNotExistException extends Error { | ||
public static MESSAGE = 'METHOD_DOES_NOT_EXIST_IN_ABI'; | ||
|
||
constructor() { | ||
super(MethodDoesNotExistException.MESSAGE); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/tssdk/src/libs/evm-api/exceptions/wrong-amount-of-arguments.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { formatString } from '../../../helpers/string'; | ||
|
||
export class WrongAmountOfArgumentsException extends Error { | ||
public static MESSAGE = 'The ?? method expected ?? arguments but received ?? arguments'; | ||
|
||
constructor(method: string, expectedAmountOfArgs: number, receivedAmountOfArgs: number) { | ||
super(formatString(WrongAmountOfArgumentsException.MESSAGE, method, expectedAmountOfArgs, receivedAmountOfArgs)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/tssdk/src/libs/evm-api/exceptions/wrong-param-type.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { formatString } from '../../../helpers/string'; | ||
|
||
export class WrongParamTypeException extends TypeError { | ||
public static MESSAGE = 'Wrong type of param (??) passed to method (??)'; | ||
|
||
public static CODE = 'WRONG_PARAM_TYPE'; | ||
|
||
constructor(method: string, paramName: string) { | ||
super(formatString(WrongParamTypeException.MESSAGE, paramName, method)); | ||
} | ||
} |
Oops, something went wrong.