aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-09 00:13:54 +0800
committerFabio Berger <me@fabioberger.com>2017-06-09 00:13:54 +0800
commit23a4dcb729084c0e00c759da487ae3959f436b3a (patch)
tree17446623d60c9beecedab6248e4485082fe1ad5e /src
parent2b08c04d4d7b67592d3f846dc31d01892bdbeaeb (diff)
downloaddexon-0x-contracts-23a4dcb729084c0e00c759da487ae3959f436b3a.tar.gz
dexon-0x-contracts-23a4dcb729084c0e00c759da487ae3959f436b3a.tar.zst
dexon-0x-contracts-23a4dcb729084c0e00c759da487ae3959f436b3a.zip
Add orderFillOrKillRequestsSchema and validate using it instead of looping over the requests and validating them individually
Diffstat (limited to 'src')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts9
-rw-r--r--src/schemas/basic_type_schemas.ts11
-rw-r--r--src/schemas/order_fill_or_kill_requests_schema.ts12
-rw-r--r--src/schemas/order_schemas.ts12
-rw-r--r--src/utils/schema_validator.ts7
5 files changed, 33 insertions, 18 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 6ef87b7ed..cfbea43a5 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -28,6 +28,7 @@ import {utils} from '../utils/utils';
import {ContractWrapper} from './contract_wrapper';
import * as ExchangeArtifacts from '../artifacts/Exchange.json';
import {ecSignatureSchema} from '../schemas/ec_signature_schema';
+import {orderFillOrKillRequestsSchema} from '../schemas/order_fill_or_kill_requests_schema';
import {signedOrderSchema, orderSchema} from '../schemas/order_schemas';
import {SchemaValidator} from '../utils/schema_validator';
import {constants} from '../utils/constants';
@@ -276,12 +277,12 @@ export class ExchangeWrapper extends ContractWrapper {
public async batchFillOrKillAsync(orderFillOrKillRequests: OrderFillOrKillRequest[],
takerAddress: string) {
await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper);
+ assert.doesConformToSchema('orderFillOrKillRequests',
+ SchemaValidator.convertToJSONSchemaCompatibleObject(orderFillOrKillRequests),
+ orderFillOrKillRequestsSchema,
+ );
const exchangeInstance = await this.getExchangeContractAsync();
_.each(orderFillOrKillRequests, request => {
- assert.doesConformToSchema('signedOrder',
- SchemaValidator.convertToJSONSchemaCompatibleObject(request.signedOrder as object),
- signedOrderSchema);
- assert.isBigNumber('fillTakerAmount', request.fillTakerAmount);
this.validateFillOrKillOrderAndThrowIfInvalidAsync(request.signedOrder,
exchangeInstance.address,
request.fillTakerAmount);
diff --git a/src/schemas/basic_type_schemas.ts b/src/schemas/basic_type_schemas.ts
new file mode 100644
index 000000000..c3b81185d
--- /dev/null
+++ b/src/schemas/basic_type_schemas.ts
@@ -0,0 +1,11 @@
+export const addressSchema = {
+ id: '/addressSchema',
+ type: 'string',
+ pattern: '^0[xX][0-9A-Fa-f]{40}$',
+};
+
+export const numberSchema = {
+ id: '/numberSchema',
+ type: 'string',
+ pattern: '^\\d+(\\.\\d+)?$',
+};
diff --git a/src/schemas/order_fill_or_kill_requests_schema.ts b/src/schemas/order_fill_or_kill_requests_schema.ts
new file mode 100644
index 000000000..4db7113de
--- /dev/null
+++ b/src/schemas/order_fill_or_kill_requests_schema.ts
@@ -0,0 +1,12 @@
+export const orderFillOrKillRequestsSchema = {
+ id: '/OrderFillOrKillRequests',
+ type: 'array',
+ items: {
+ properties: {
+ signedOrder: {$ref: '/signedOrderSchema'},
+ fillTakerAmount: {type: '/numberSchema'},
+ },
+ required: ['signedOrder', 'fillTakerAmount'],
+ type: 'object',
+ },
+};
diff --git a/src/schemas/order_schemas.ts b/src/schemas/order_schemas.ts
index 4999f3e9d..133736b3d 100644
--- a/src/schemas/order_schemas.ts
+++ b/src/schemas/order_schemas.ts
@@ -1,15 +1,3 @@
-export const addressSchema = {
- id: '/addressSchema',
- type: 'string',
- pattern: '^0[xX][0-9A-Fa-f]{40}$',
-};
-
-export const numberSchema = {
- id: '/numberSchema',
- type: 'string',
- pattern: '^\\d+(\\.\\d+)?$',
-};
-
export const orderSchema = {
id: '/orderSchema',
properties: {
diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts
index 932ddf62a..72f6afffa 100644
--- a/src/utils/schema_validator.ts
+++ b/src/utils/schema_validator.ts
@@ -1,7 +1,9 @@
import {Validator, ValidatorResult} from 'jsonschema';
import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema';
-import {addressSchema, numberSchema, orderSchema, signedOrderSchema} from '../schemas/order_schemas';
+import {orderSchema, signedOrderSchema} from '../schemas/order_schemas';
+import {addressSchema, numberSchema} from '../schemas/basic_type_schemas';
import {tokenSchema} from '../schemas/token_schema';
+import {orderFillOrKillRequestsSchema} from '../schemas/order_fill_or_kill_requests_schema';
export class SchemaValidator {
private validator: Validator;
@@ -9,7 +11,7 @@ export class SchemaValidator {
// sub-types (e.g BigNumber) with a simpler string representation. Since BigNumber and other
// complex types implement the `toString` method, we can stringify the object and
// then parse it. The resultant object can then be checked using jsonschema.
- public static convertToJSONSchemaCompatibleObject(obj: object): object {
+ public static convertToJSONSchemaCompatibleObject(obj: any): any {
return JSON.parse(JSON.stringify(obj));
}
constructor() {
@@ -21,6 +23,7 @@ export class SchemaValidator {
this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id);
this.validator.addSchema(signedOrderSchema, signedOrderSchema.id);
this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id);
+ this.validator.addSchema(orderFillOrKillRequestsSchema, orderFillOrKillRequestsSchema.id);
}
public validate(instance: object, schema: Schema): ValidatorResult {
return this.validator.validate(instance, schema);