aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-01 02:08:28 +0800
committerFabio Berger <me@fabioberger.com>2017-06-01 02:08:28 +0800
commit595656d3fc06a221274eb6bee89e7ba6e4e8ae61 (patch)
tree7fe822899556285ab9ea6dbde055aa4a927373ee /src
parent9364c5647ff5518aaa2b3fcd133a9e6c47ec0eda (diff)
downloaddexon-sol-tools-595656d3fc06a221274eb6bee89e7ba6e4e8ae61.tar
dexon-sol-tools-595656d3fc06a221274eb6bee89e7ba6e4e8ae61.tar.gz
dexon-sol-tools-595656d3fc06a221274eb6bee89e7ba6e4e8ae61.tar.bz2
dexon-sol-tools-595656d3fc06a221274eb6bee89e7ba6e4e8ae61.tar.lz
dexon-sol-tools-595656d3fc06a221274eb6bee89e7ba6e4e8ae61.tar.xz
dexon-sol-tools-595656d3fc06a221274eb6bee89e7ba6e4e8ae61.tar.zst
dexon-sol-tools-595656d3fc06a221274eb6bee89e7ba6e4e8ae61.zip
Move isValidOrderHash to utils and implement assert.isValidOrderHash
Diffstat (limited to 'src')
-rw-r--r--src/0x.js.ts8
-rw-r--r--src/utils/assert.ts4
-rw-r--r--src/utils/utils.ts4
3 files changed, 12 insertions, 4 deletions
diff --git a/src/0x.js.ts b/src/0x.js.ts
index d231c579e..ac00d3b42 100644
--- a/src/0x.js.ts
+++ b/src/0x.js.ts
@@ -102,10 +102,10 @@ export class ZeroEx {
return salt;
}
/** Checks if order hash is valid */
- public static isValidOrderHash(orderHash: string): boolean {
- assert.isString('orderHash', orderHash);
- const isValid = /^0x[0-9A-F]{64}$/i.test(orderHash);
- return isValid;
+ public static isValidOrderHash(orderHashHex: string): boolean {
+ assert.isString('orderHashHex', orderHashHex);
+ const isValidOrderHash = utils.isValidOrderHash(orderHashHex);
+ return isValidOrderHash;
}
/**
* A unit amount is defined as the amount of a token above the specified decimal places (integer part).
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 1baf572d1..0088b3b13 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -2,6 +2,7 @@ import * as _ from 'lodash';
import * as BigNumber from 'bignumber.js';
import * as Web3 from 'web3';
import {SchemaValidator} from './schema_validator';
+import {utils} from './utils';
const HEX_REGEX = /^0x[0-9A-F]*$/i;
@@ -27,6 +28,9 @@ export const assert = {
isNumber(variableName: string, value: number): void {
this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value));
},
+ isValidOrderHash(variableName: string, value: string): void {
+ this.assert(utils.isValidOrderHash(value), this.typeAssertionMessage(variableName, 'orderHash', value));
+ },
doesConformToSchema(variableName: string, value: object, schema: Schema): void {
const schemaValidator = new SchemaValidator();
const validationResult = schemaValidator.validate(value, schema);
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index 336eaf7bb..e6840a624 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -18,4 +18,8 @@ export const utils = {
isParityNode(nodeVersion: string): boolean {
return _.includes(nodeVersion, 'Parity');
},
+ isValidOrderHash(orderHashHex: string) {
+ const isValid = /^0x[0-9A-F]{64}$/i.test(orderHashHex);
+ return isValid;
+ },
};