From 5b6c91bb3f0b5a1d0586b7e772ad96f3eab1f911 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 13 Sep 2018 14:04:13 +0200 Subject: Fixes for the breaking changes in ethers --- packages/base-contract/src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/base-contract/src/index.ts') diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 12f974445..35c830a46 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -87,10 +87,10 @@ export class BaseContract { // if it overflows the corresponding Solidity type, there is a bug in the // encoder, or the encoder performs unsafe type coercion. public static strictArgumentEncodingCheck(inputAbi: DataItem[], args: any[]): void { - const coder = ethers.utils.AbiCoder.defaultCoder; + const coder = new ethers.AbiCoder(); const params = abiUtils.parseEthersParams(inputAbi); - const rawEncoded = coder.encode(params.names, params.types, args); - const rawDecoded = coder.decode(params.names, params.types, rawEncoded); + const rawEncoded = coder.encode(inputAbi, args); + const rawDecoded = coder.decode(inputAbi, rawEncoded); for (let i = 0; i < rawDecoded.length; i++) { const original = args[i]; const decoded = rawDecoded[i]; -- cgit v1.2.3 From 393f9e5a293511ede662907861cf72e4f8add098 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 21 Sep 2018 12:05:13 +0200 Subject: Fix the way we detect BN's --- packages/base-contract/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/base-contract/src/index.ts') diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 35c830a46..90e576c24 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -61,7 +61,7 @@ export class BaseContract { } } protected static _bnToBigNumber(_type: string, value: any): any { - return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value; + return _.isObject(value) && value._hex ? new BigNumber(value.toString()) : value; } protected static async _applyDefaultsToTxDataAsync>( txData: T, -- cgit v1.2.3 From cb99ebf78aad869e61ec2ca7c48bb25178274ec5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 27 Sep 2018 11:21:39 +0200 Subject: Throw revert reasons from contract wrappers --- packages/base-contract/src/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'packages/base-contract/src/index.ts') diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 90e576c24..538c87431 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -20,6 +20,10 @@ export interface EthersInterfaceByFunctionSignature { [key: string]: ethers.Interface; } +const REVERT_ERROR_SELECTOR = '08c379a0'; +const REVERT_ERROR_SELECTOR_OFFSET = 2; +const REVERT_ERROR_SELECTOR_END = 10; + export class BaseContract { protected _ethersInterfacesByFunctionSignature: EthersInterfaceByFunctionSignature; protected _web3Wrapper: Web3Wrapper; @@ -82,6 +86,15 @@ export class BaseContract { } return txDataWithDefaults; } + 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, 4), + ); + throw new Error(revertReason); + } + } // Throws if the given arguments cannot be safely/correctly encoded based on // the given inputAbi. An argument may not be considered safely encodeable // if it overflows the corresponding Solidity type, there is a bug in the -- cgit v1.2.3 From 63d79faa85df1cc090837fc49befb5076b50203b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 27 Sep 2018 11:51:11 +0200 Subject: Fix linter errors --- packages/base-contract/src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/base-contract/src/index.ts') diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 538c87431..981e6fca6 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -22,7 +22,8 @@ export interface EthersInterfaceByFunctionSignature { const REVERT_ERROR_SELECTOR = '08c379a0'; const REVERT_ERROR_SELECTOR_OFFSET = 2; -const REVERT_ERROR_SELECTOR_END = 10; +const REVERT_ERROR_SELECTOR_BYTES_LENGTH = 4; +const REVERT_ERROR_SELECTOR_END = REVERT_ERROR_SELECTOR_OFFSET + REVERT_ERROR_SELECTOR_BYTES_LENGTH * 2; export class BaseContract { protected _ethersInterfacesByFunctionSignature: EthersInterfaceByFunctionSignature; @@ -90,7 +91,7 @@ export class BaseContract { 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, 4), + ethers.utils.hexDataSlice(rawCallResult, REVERT_ERROR_SELECTOR_BYTES_LENGTH), ); throw new Error(revertReason); } -- cgit v1.2.3