aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-06-03 00:53:21 +0800
committerGitHub <noreply@github.com>2017-06-03 00:53:21 +0800
commitc83587a16d016d1efafaf31abb9b39eb54128568 (patch)
treeac53dfb35344c644096f574802eb64eab5955f90 /src/utils
parentb8ff2468776e1c784ff50e5ada1c633ee0d3aeda (diff)
parent3fad55d118b6a2f8f44ba5dec7fdae276c806eb3 (diff)
downloaddexon-sol-tools-c83587a16d016d1efafaf31abb9b39eb54128568.tar
dexon-sol-tools-c83587a16d016d1efafaf31abb9b39eb54128568.tar.gz
dexon-sol-tools-c83587a16d016d1efafaf31abb9b39eb54128568.tar.bz2
dexon-sol-tools-c83587a16d016d1efafaf31abb9b39eb54128568.tar.lz
dexon-sol-tools-c83587a16d016d1efafaf31abb9b39eb54128568.tar.xz
dexon-sol-tools-c83587a16d016d1efafaf31abb9b39eb54128568.tar.zst
dexon-sol-tools-c83587a16d016d1efafaf31abb9b39eb54128568.zip
Merge pull request #30 from 0xProject/fillOrderAsync
fillOrderAsync
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/assert.ts3
-rw-r--r--src/utils/schema_validator.ts16
2 files changed, 17 insertions, 2 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 1baf572d1..aeed1c6dc 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -27,6 +27,9 @@ export const assert = {
isNumber(variableName: string, value: number): void {
this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value));
},
+ isBoolean(variableName: string, value: boolean): void {
+ this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value));
+ },
doesConformToSchema(variableName: string, value: object, schema: Schema): void {
const schemaValidator = new SchemaValidator();
const validationResult = schemaValidator.validate(value, schema);
diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts
index 8132f7414..932ddf62a 100644
--- a/src/utils/schema_validator.ts
+++ b/src/utils/schema_validator.ts
@@ -1,14 +1,26 @@
import {Validator, ValidatorResult} from 'jsonschema';
import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema';
+import {addressSchema, numberSchema, orderSchema, signedOrderSchema} from '../schemas/order_schemas';
import {tokenSchema} from '../schemas/token_schema';
export class SchemaValidator {
private validator: Validator;
+ // In order to validate a complex JS object using jsonschema, we must replace any complex
+ // 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 {
+ return JSON.parse(JSON.stringify(obj));
+ }
constructor() {
this.validator = new Validator();
- this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id);
- this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id);
this.validator.addSchema(tokenSchema, tokenSchema.id);
+ this.validator.addSchema(orderSchema, orderSchema.id);
+ this.validator.addSchema(numberSchema, numberSchema.id);
+ this.validator.addSchema(addressSchema, addressSchema.id);
+ this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id);
+ this.validator.addSchema(signedOrderSchema, signedOrderSchema.id);
+ this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id);
}
public validate(instance: object, schema: Schema): ValidatorResult {
return this.validator.validate(instance, schema);