diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-12-23 09:23:02 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2019-01-15 02:49:44 +0800 |
commit | b06f8239e1fe75703f88d34c0d225701406e28c2 (patch) | |
tree | 9beb83b64b37fb6ad67d066f089b868a8ad25fcb /packages/base-contract | |
parent | 7991de9ed0b5f1e8a38097d902eae09cc6b5cf11 (diff) | |
download | dexon-sol-tools-b06f8239e1fe75703f88d34c0d225701406e28c2.tar dexon-sol-tools-b06f8239e1fe75703f88d34c0d225701406e28c2.tar.gz dexon-sol-tools-b06f8239e1fe75703f88d34c0d225701406e28c2.tar.bz2 dexon-sol-tools-b06f8239e1fe75703f88d34c0d225701406e28c2.tar.lz dexon-sol-tools-b06f8239e1fe75703f88d34c0d225701406e28c2.tar.xz dexon-sol-tools-b06f8239e1fe75703f88d34c0d225701406e28c2.tar.zst dexon-sol-tools-b06f8239e1fe75703f88d34c0d225701406e28c2.zip |
Finished porting new abi encoder to contracts
Diffstat (limited to 'packages/base-contract')
-rw-r--r-- | packages/base-contract/src/index.ts | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 2fd50b941..aeb90e6f7 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -91,10 +91,7 @@ export class BaseContract { } protected static _throwIfRevertWithReasonCallResult(rawCallResult: string): void { if (rawCallResult.slice(REVERT_ERROR_SELECTOR_OFFSET, REVERT_ERROR_SELECTOR_END) === REVERT_ERROR_SELECTOR) { - const revertReason = ethers.utils.defaultAbiCoder.decode( - ['string'], - ethers.utils.hexDataSlice(rawCallResult, REVERT_ERROR_SELECTOR_BYTES_LENGTH), - ); + const revertReason = AbiEncoder.create('(string)').decode(ethers.utils.hexDataSlice(rawCallResult, REVERT_ERROR_SELECTOR_BYTES_LENGTH)); throw new Error(revertReason); } } @@ -140,6 +137,28 @@ export class BaseContract { }) as MethodAbi; return methodAbi; } + protected _strictEncodeArguments(functionSignature: string, functionArguments: any): string { + const abiEncoder = this._lookupAbiEncoder(functionSignature); + const inputAbi = abiEncoder.getDataItem().components; + if (inputAbi === undefined) { + throw new Error(`Undefined Method Input ABI`); + } + const params = abiUtils.parseEthersParams(inputAbi); + const rawEncoded = abiEncoder.encode(functionArguments); + const rawDecoded = abiEncoder.decodeAsArray(rawEncoded); + for (let i = 0; i < rawDecoded.length; i++) { + const original = functionArguments[i]; + const decoded = rawDecoded[i]; + if (!abiUtils.isAbiDataEqual(params.names[i], params.types[i], original, decoded)) { + throw new Error( + `Cannot safely encode argument: ${params.names[i]} (${original}) of type ${ + params.types[i] + }. (Possible type overflow or other encoding error)`, + ); + } + } + return rawEncoded; + } constructor( contractName: string, abi: ContractAbi, |