From 62b8a2690b20a7fde83144a2205d5927ac0a55d1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 18:50:39 +0200 Subject: Add orderCancelrequestsSchema and orderFillRequestsSchema --- src/contract_wrappers/exchange_wrapper.ts | 28 ++++++++++++---------------- src/schemas/order_cancel_schema.ts | 12 ++++++++++++ src/schemas/order_fill_requests_schema.ts | 12 ++++++++++++ 3 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/schemas/order_cancel_schema.ts create mode 100644 src/schemas/order_fill_requests_schema.ts (limited to 'src') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 73ec0886c..ed0438372 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -28,6 +28,8 @@ 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 {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 {SchemaValidator} from '../utils/schema_validator'; @@ -170,12 +172,10 @@ export class ExchangeWrapper extends ContractWrapper { shouldCheckTransfer: boolean, takerAddress: string): Promise { assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); - _.forEach(orderFillRequests, - async (orderFillRequest: OrderFillRequest, i: number) => { - assert.doesConformToSchema(`orderFillRequests[${i}].signedOrder`, - SchemaValidator.convertToJSONSchemaCompatibleObject(orderFillRequest.signedOrder as object), - signedOrderSchema); - assert.isBigNumber(`orderFillRequests[${i}].takerTokenFillAmount`, orderFillRequest.takerTokenFillAmount); + assert.doesConformToSchema('orderFillRequests', + SchemaValidator.convertToJSONSchemaCompatibleObject(orderFillRequests as object), + orderFillRequestsSchema); + _.forEach(orderFillRequests, async (orderFillRequest: OrderFillRequest) => { await this.validateFillOrderAndThrowIfInvalidAsync( orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress); }); @@ -333,8 +333,8 @@ export class ExchangeWrapper extends ContractWrapper { public async cancelOrderAsync( order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise { assert.doesConformToSchema('order', - SchemaValidator.convertToJSONSchemaCompatibleObject(order as object), - orderSchema); + SchemaValidator.convertToJSONSchemaCompatibleObject(order), + orderSchema); assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount); await assert.isSenderAddressAsync('order.maker', order.maker, this.web3Wrapper); @@ -373,14 +373,10 @@ export class ExchangeWrapper extends ContractWrapper { assert.assert(_.uniq(makers).length === 1, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH); const maker = makers[0]; await assert.isSenderAddressAsync('maker', maker, this.web3Wrapper); - _.forEach(orderCancellationRequests, - async (cancellationRequest: OrderCancellationRequest, i: number) => { - assert.doesConformToSchema(`orderCancellationRequests[${i}].order`, - SchemaValidator.convertToJSONSchemaCompatibleObject(cancellationRequest.order as object), orderSchema, - ); - assert.isBigNumber(`orderCancellationRequests[${i}].takerTokenCancelAmount`, - cancellationRequest.takerTokenCancelAmount, - ); + assert.doesConformToSchema('orderCancellationRequests', + SchemaValidator.convertToJSONSchemaCompatibleObject(orderCancellationRequests), + orderCancellationRequestsSchema); + _.forEach(orderCancellationRequests, async (cancellationRequest: OrderCancellationRequest) => { await this.validateCancelOrderAndThrowIfInvalidAsync( cancellationRequest.order, cancellationRequest.takerTokenCancelAmount, ); diff --git a/src/schemas/order_cancel_schema.ts b/src/schemas/order_cancel_schema.ts new file mode 100644 index 000000000..d64df08f1 --- /dev/null +++ b/src/schemas/order_cancel_schema.ts @@ -0,0 +1,12 @@ +export const orderCancellationRequestsSchema = { + id: '/OrderCancellationRequests', + type: 'array', + items: { + properties: { + order: {$ref: '/orderSchema'}, + takerTokenFillAmount: {type: '/numberSchema'}, + }, + required: ['order', 'takerTokenFillAmount'], + type: 'object', + }, +}; diff --git a/src/schemas/order_fill_requests_schema.ts b/src/schemas/order_fill_requests_schema.ts new file mode 100644 index 000000000..44f4e33e2 --- /dev/null +++ b/src/schemas/order_fill_requests_schema.ts @@ -0,0 +1,12 @@ +export const orderFillRequestsSchema = { + id: '/OrderFillRequests', + type: 'array', + items: { + properties: { + signedOrder: {$ref: '/signedOrderSchema'}, + takerTokenFillAmount: {type: '/numberSchema'}, + }, + required: ['signedOrder', 'takerTokenFillAmount'], + type: 'object', + }, +}; -- cgit From dbec2fecf639ff1b31ef4ba3025fde835358ece4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Jun 2017 19:09:41 +0200 Subject: Fix schema error --- src/schemas/order_cancel_schema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/schemas/order_cancel_schema.ts b/src/schemas/order_cancel_schema.ts index d64df08f1..fc6401063 100644 --- a/src/schemas/order_cancel_schema.ts +++ b/src/schemas/order_cancel_schema.ts @@ -4,9 +4,9 @@ export const orderCancellationRequestsSchema = { items: { properties: { order: {$ref: '/orderSchema'}, - takerTokenFillAmount: {type: '/numberSchema'}, + takerTokenCancellAmount: {type: '/numberSchema'}, }, - required: ['order', 'takerTokenFillAmount'], + required: ['order', 'takerTokenCancellAmount'], type: 'object', }, }; -- cgit From 862685aa41b7ba0a107c20a524dc0769cd353409 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 10:25:51 +0200 Subject: Fix the other schema bug --- src/schemas/order_cancel_schema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/schemas/order_cancel_schema.ts b/src/schemas/order_cancel_schema.ts index fc6401063..5cc8f745c 100644 --- a/src/schemas/order_cancel_schema.ts +++ b/src/schemas/order_cancel_schema.ts @@ -4,9 +4,9 @@ export const orderCancellationRequestsSchema = { items: { properties: { order: {$ref: '/orderSchema'}, - takerTokenCancellAmount: {type: '/numberSchema'}, + takerTokenCancelAmount: {type: '/numberSchema'}, }, - required: ['order', 'takerTokenCancellAmount'], + required: ['order', 'takerTokenCancelAmount'], type: 'object', }, }; -- cgit