aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-05 01:27:31 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-05 01:27:31 +0800
commitb1c7291d3cfffb11a13c50a518f2b895bcdc9fc5 (patch)
tree72fe9bb7fc42e4dc3ec6c55483d7acb1406da8eb /src
parent5611df82f9f276fb161fa268f7ab468a6c1d7784 (diff)
downloaddexon-sol-tools-b1c7291d3cfffb11a13c50a518f2b895bcdc9fc5.tar
dexon-sol-tools-b1c7291d3cfffb11a13c50a518f2b895bcdc9fc5.tar.gz
dexon-sol-tools-b1c7291d3cfffb11a13c50a518f2b895bcdc9fc5.tar.bz2
dexon-sol-tools-b1c7291d3cfffb11a13c50a518f2b895bcdc9fc5.tar.lz
dexon-sol-tools-b1c7291d3cfffb11a13c50a518f2b895bcdc9fc5.tar.xz
dexon-sol-tools-b1c7291d3cfffb11a13c50a518f2b895bcdc9fc5.tar.zst
dexon-sol-tools-b1c7291d3cfffb11a13c50a518f2b895bcdc9fc5.zip
Use orderHashSchema to validate order hash
Diffstat (limited to 'src')
-rw-r--r--src/0x.ts6
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts8
-rw-r--r--src/utils/assert.ts5
-rw-r--r--src/utils/utils.ts4
4 files changed, 9 insertions, 14 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 1b9334942..d42c16ca6 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -17,7 +17,8 @@ import {ecSignatureSchema} from './schemas/ec_signature_schema';
import {TokenWrapper} from './contract_wrappers/token_wrapper';
import {ProxyWrapper} from './contract_wrappers/proxy_wrapper';
import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider} from './types';
-import {orderSchema} from './schemas/order_schemas';
+import {orderSchema, orderHashSchema} from './schemas/order_schemas';
+import {SchemaValidator} from './utils/schema_validator';
// Customize our BigNumber instances
bigNumberConfigs.configure();
@@ -110,7 +111,8 @@ export class ZeroEx {
// Since this method can be called to check if any arbitrary string conforms to an orderHash's
// format, we only assert that we were indeed passed a string.
assert.isString('orderHash', orderHash);
- const isValidOrderHash = utils.isValidOrderHash(orderHash);
+ const schemaValidator = new SchemaValidator();
+ const isValidOrderHash = schemaValidator.validate(orderHash, orderHashSchema).valid;
return isValidOrderHash;
}
/**
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index c249248f6..6a85e2592 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -43,7 +43,7 @@ import {signedOrdersSchema} from '../schemas/signed_orders_schema';
import {orderFillRequestsSchema} from '../schemas/order_fill_requests_schema';
import {orderCancellationRequestsSchema} from '../schemas/order_cancel_schema';
import {orderFillOrKillRequestsSchema} from '../schemas/order_fill_or_kill_requests_schema';
-import {signedOrderSchema, orderSchema} from '../schemas/order_schemas';
+import {signedOrderSchema, orderSchema, orderHashSchema} from '../schemas/order_schemas';
import {constants} from '../utils/constants';
import {TokenWrapper} from './token_wrapper';
import {decorators} from '../utils/decorators';
@@ -105,7 +105,7 @@ export class ExchangeWrapper extends ContractWrapper {
*/
public async getUnavailableTakerAmountAsync(orderHash: string,
exchangeContractAddress: string): Promise<BigNumber.BigNumber> {
- assert.isValidOrderHash('orderHash', orderHash);
+ assert.doesConformToSchema('orderHash', orderHash, orderHashSchema);
const exchangeContract = await this._getExchangeContractAsync(exchangeContractAddress);
let unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHash);
@@ -121,7 +121,7 @@ export class ExchangeWrapper extends ContractWrapper {
*/
public async getFilledTakerAmountAsync(orderHash: string,
exchangeContractAddress: string): Promise<BigNumber.BigNumber> {
- assert.isValidOrderHash('orderHash', orderHash);
+ assert.doesConformToSchema('orderHash', orderHash, orderHashSchema);
const exchangeContract = await this._getExchangeContractAsync(exchangeContractAddress);
let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHash);
@@ -138,7 +138,7 @@ export class ExchangeWrapper extends ContractWrapper {
*/
public async getCanceledTakerAmountAsync(orderHash: string,
exchangeContractAddress: string): Promise<BigNumber.BigNumber> {
- assert.isValidOrderHash('orderHash', orderHash);
+ assert.doesConformToSchema('orderHash', orderHash, orderHashSchema);
const exchangeContract = await this._getExchangeContractAsync(exchangeContractAddress);
let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHash);
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 38c1d4aae..ec3790870 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -45,13 +45,10 @@ 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));
- },
isBoolean(variableName: string, value: boolean): void {
this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value));
},
- doesConformToSchema(variableName: string, value: object, schema: Schema): void {
+ doesConformToSchema(variableName: string, value: any, schema: Schema): void {
const schemaValidator = new SchemaValidator();
const validationResult = schemaValidator.validate(value, schema);
const hasValidationErrors = validationResult.errors.length > 0;
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index 061e9f99a..ecc171bfe 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -25,10 +25,6 @@ export const utils = {
isTestRpc(nodeVersion: string): boolean {
return _.includes(nodeVersion, 'TestRPC');
},
- isValidOrderHash(orderHashHex: string): boolean {
- const isValid = /^0x[0-9A-F]{64}$/i.test(orderHashHex);
- return isValid;
- },
spawnSwitchErr(name: string, value: any): Error {
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
},