aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-05-30 18:00:23 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-05-30 18:00:23 +0800
commit699e588d1fda7f7e8190a4b3347905964cef2d95 (patch)
treec7edff2789db3d6a86a2672c61951487561425b2 /src
parent603a88872d07cb7a380be4eee3111b024bfed886 (diff)
downloaddexon-sol-tools-699e588d1fda7f7e8190a4b3347905964cef2d95.tar
dexon-sol-tools-699e588d1fda7f7e8190a4b3347905964cef2d95.tar.gz
dexon-sol-tools-699e588d1fda7f7e8190a4b3347905964cef2d95.tar.bz2
dexon-sol-tools-699e588d1fda7f7e8190a4b3347905964cef2d95.tar.lz
dexon-sol-tools-699e588d1fda7f7e8190a4b3347905964cef2d95.tar.xz
dexon-sol-tools-699e588d1fda7f7e8190a4b3347905964cef2d95.tar.zst
dexon-sol-tools-699e588d1fda7f7e8190a4b3347905964cef2d95.zip
Add signedOrderSchema and all subschemas
Diffstat (limited to 'src')
-rw-r--r--src/schemas/signed_order_schema.ts50
-rw-r--r--src/utils/schema_validator.ts7
2 files changed, 56 insertions, 1 deletions
diff --git a/src/schemas/signed_order_schema.ts b/src/schemas/signed_order_schema.ts
new file mode 100644
index 000000000..b9321cad1
--- /dev/null
+++ b/src/schemas/signed_order_schema.ts
@@ -0,0 +1,50 @@
+export const addressSchema = {
+ id: '/addressSchema',
+ type: 'string',
+ pattern: '^0[xX][0-9A-Fa-f]{40}$',
+};
+
+export const bigNumberSchema = {
+ id: '/bigNumberSchema',
+ type: 'string',
+ pattern: '^\d*$',
+};
+
+export const orderSchema = {
+ id: '/orderSchema',
+ properties: {
+ maker: {$ref: '/addressSchema'},
+ taker: {$ref: '/addressSchema'},
+
+ makerFee: {$ref: '/bigNumberSchema'},
+ takerFee: {$ref: '/bigNumberSchema'},
+
+ makerTokenAmount: {$ref: '/bigNumberSchema'},
+ takerTokenAmount: {$ref: '/bigNumberSchema'},
+
+ makerTokenAddress: {$ref: '/addressSchema'},
+ takerTokenAddress: {$ref: '/addressSchema'},
+
+ salt: {$ref: '/bigNumberSchema'},
+ fillAmount: {$ref: '/bigNumberSchema'},
+ feeRecipient: {$ref: '/addressSchema'},
+ expirationUnixTimestampSec: {$ref: '/bigNumberSchema'},
+ },
+ required: [
+ 'maker', /*'taker',*/ 'makerFee', 'takerFee', 'makerTokenAmount', 'takerTokenAmount',
+ 'salt', 'fillAmount', 'feeRecipient', 'expirationUnixTimestampSec',
+ ],
+ type: 'object',
+};
+
+export const signedOrderSchema = {
+ allOf: [
+ { $ref: '/orderSchema' },
+ {
+ properties: {
+ ecSignature: {$ref: '/addressSchema'},
+ },
+ required: ['ecSignature'],
+ },
+ ],
+};
diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts
index 61f4c09c8..0159b6b0b 100644
--- a/src/utils/schema_validator.ts
+++ b/src/utils/schema_validator.ts
@@ -1,12 +1,17 @@
import {Validator, ValidatorResult} from 'jsonschema';
import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema';
+import {addressSchema, bigNumberSchema, orderSchema, signedOrderSchema} from '../schemas/signed_order_schema';
export class SchemaValidator {
private validator: Validator;
constructor() {
this.validator = new Validator();
- this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id);
+ this.validator.addSchema(orderSchema, orderSchema.id);
+ this.validator.addSchema(addressSchema, addressSchema.id);
+ this.validator.addSchema(bigNumberSchema, bigNumberSchema.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);