aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base-contract/src
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-10 03:15:30 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-10 03:15:30 +0800
commit3f610d4865d0f901320f0334d4441ae181e4521c (patch)
tree11aacc9f9f1a7e1198d7bf83b6ff594e2f7be8b3 /packages/base-contract/src
parent8404e0e73f2758c1b0a406f0aa63d43a44fe4dd3 (diff)
parentb60a74c8bc4de5c897cefc2fbf9a247d8422d560 (diff)
downloaddexon-sol-tools-3f610d4865d0f901320f0334d4441ae181e4521c.tar
dexon-sol-tools-3f610d4865d0f901320f0334d4441ae181e4521c.tar.gz
dexon-sol-tools-3f610d4865d0f901320f0334d4441ae181e4521c.tar.bz2
dexon-sol-tools-3f610d4865d0f901320f0334d4441ae181e4521c.tar.lz
dexon-sol-tools-3f610d4865d0f901320f0334d4441ae181e4521c.tar.xz
dexon-sol-tools-3f610d4865d0f901320f0334d4441ae181e4521c.tar.zst
dexon-sol-tools-3f610d4865d0f901320f0334d4441ae181e4521c.zip
Merge https://github.com/0xProject/0x-monorepo into development
Diffstat (limited to 'packages/base-contract/src')
-rw-r--r--packages/base-contract/src/index.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
index a240fb8b6..12f974445 100644
--- a/packages/base-contract/src/index.ts
+++ b/packages/base-contract/src/index.ts
@@ -82,6 +82,27 @@ export class BaseContract {
}
return txDataWithDefaults;
}
+ // 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
+ // encoder, or the encoder performs unsafe type coercion.
+ public static strictArgumentEncodingCheck(inputAbi: DataItem[], args: any[]): void {
+ const coder = ethers.utils.AbiCoder.defaultCoder;
+ const params = abiUtils.parseEthersParams(inputAbi);
+ const rawEncoded = coder.encode(params.names, params.types, args);
+ const rawDecoded = coder.decode(params.names, params.types, rawEncoded);
+ for (let i = 0; i < rawDecoded.length; i++) {
+ const original = args[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)`,
+ );
+ }
+ }
+ }
protected _lookupEthersInterface(functionSignature: string): ethers.Interface {
const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature];
if (_.isUndefined(ethersInterface)) {