aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-06-11 19:50:59 +0800
committerGitHub <noreply@github.com>2017-06-11 19:50:59 +0800
commitbbe9a811fb28417377ec3d089e0cdd3693480c35 (patch)
tree0813864d3920321e64acadebdacfd1525ea4e998 /src/utils
parent6b152edb985d836c91c6d816c03cc15e77be2c6e (diff)
parent4e56c299263cf6a3397a1d7b95fb92a8b61da3c0 (diff)
downloaddexon-sol-tools-bbe9a811fb28417377ec3d089e0cdd3693480c35.tar
dexon-sol-tools-bbe9a811fb28417377ec3d089e0cdd3693480c35.tar.gz
dexon-sol-tools-bbe9a811fb28417377ec3d089e0cdd3693480c35.tar.bz2
dexon-sol-tools-bbe9a811fb28417377ec3d089e0cdd3693480c35.tar.lz
dexon-sol-tools-bbe9a811fb28417377ec3d089e0cdd3693480c35.tar.xz
dexon-sol-tools-bbe9a811fb28417377ec3d089e0cdd3693480c35.tar.zst
dexon-sol-tools-bbe9a811fb28417377ec3d089e0cdd3693480c35.zip
Merge branch 'master' into private
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/constants.ts2
-rw-r--r--src/utils/decorators.ts35
2 files changed, 37 insertions, 0 deletions
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index fef0a91a0..d56ee16c5 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -2,4 +2,6 @@ export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
TESTRPC_NETWORK_ID: 50,
MAX_DIGITS_IN_UNSIGNED_256_INT: 78,
+ INVALID_JUMP_PATTERN: 'invalid JUMP at',
+ OUT_OF_GAS_PATTERN: 'out of gas',
};
diff --git a/src/utils/decorators.ts b/src/utils/decorators.ts
new file mode 100644
index 000000000..a25f2cff5
--- /dev/null
+++ b/src/utils/decorators.ts
@@ -0,0 +1,35 @@
+import * as _ from 'lodash';
+import {constants} from './constants';
+import {AsyncMethod, ZeroExError} from '../types';
+
+export const decorators = {
+ /**
+ * Source: https://stackoverflow.com/a/29837695/3546986
+ */
+ contractCallErrorHandler(target: object,
+ key: string|symbol,
+ descriptor: TypedPropertyDescriptor<AsyncMethod>,
+ ): TypedPropertyDescriptor<AsyncMethod> {
+ const originalMethod = (descriptor.value as AsyncMethod);
+
+ // Do not use arrow syntax here. Use a function expression in
+ // order to use the correct value of `this` in this method
+ // tslint:disable-next-line:only-arrow-functions
+ descriptor.value = async function(...args: any[]) {
+ try {
+ const result = await originalMethod.apply(this, args);
+ return result;
+ } catch (error) {
+ if (_.includes(error.message, constants.INVALID_JUMP_PATTERN)) {
+ throw new Error(ZeroExError.INVALID_JUMP);
+ }
+ if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) {
+ throw new Error(ZeroExError.OUT_OF_GAS);
+ }
+ throw error;
+ }
+ };
+
+ return descriptor;
+ },
+};