From ee4185ab465c76b64b65efefb92e11b0ca4ecad4 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 16 Dec 2018 16:52:37 -0800 Subject: Move OrderWatcher Websocket schemas to json-schemas and convert to JSON so that they are language agnostic --- .../order_watcher_websocket_server.ts | 6 +-- .../order-watcher/src/schemas/websocket_schemas.ts | 61 ---------------------- 2 files changed, 3 insertions(+), 64 deletions(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts b/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts index eac48f849..f90961cc8 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts @@ -1,11 +1,11 @@ import { ContractAddresses } from '@0x/contract-addresses'; +import { schemas } from '@0x/json-schemas'; import { OrderStateInvalid, OrderStateValid, SignedOrder } from '@0x/types'; import { BigNumber, logUtils } from '@0x/utils'; import { Provider } from 'ethereum-types'; import * as http from 'http'; import * as WebSocket from 'websocket'; -import { webSocketRequestSchema, webSocketUtf8MessageSchema } from '../schemas/websocket_schemas'; import { GetStatsResult, OrderWatcherConfig, OrderWatcherMethod, WebSocketRequest, WebSocketResponse } from '../types'; import { assert } from '../utils/assert'; @@ -105,9 +105,9 @@ export class OrderWatcherWebSocketServer { private async _onMessageCallbackAsync(connection: WebSocket.connection, message: any): Promise { let response: WebSocketResponse; - assert.doesConformToSchema('message', message, webSocketUtf8MessageSchema); + assert.doesConformToSchema('message', message, schemas.orderWatcherWebSocketUtf8MessageSchema); const request: WebSocketRequest = JSON.parse(message.utf8Data); - assert.doesConformToSchema('request', request, webSocketRequestSchema); + assert.doesConformToSchema('request', request, schemas.orderWatcherWebSocketRequestSchema); assert.isString(request.jsonrpc, JSON_RPC_VERSION); try { response = { diff --git a/packages/order-watcher/src/schemas/websocket_schemas.ts b/packages/order-watcher/src/schemas/websocket_schemas.ts index 263dd45b3..df54a38e1 100644 --- a/packages/order-watcher/src/schemas/websocket_schemas.ts +++ b/packages/order-watcher/src/schemas/websocket_schemas.ts @@ -1,63 +1,2 @@ // TODO: Move these schemas to the `json-schemas` package and convert to JSON // Rename to `OrderWatcherWebSocketRequestSchema`, etc... -export const webSocketUtf8MessageSchema = { - id: '/webSocketUtf8MessageSchema', - properties: { - utf8Data: { type: 'string' }, - }, - type: 'object', - required: ['utf8Data'], -}; - -export const webSocketRequestSchema = { - id: '/webSocketRequestSchema', - type: 'object', - definitions: { - signedOrderParam: { - type: 'object', - properties: { - signedOrder: { $ref: '/signedOrderSchema' }, - }, - required: ['signedOrder'], - }, - orderHashParam: { - type: 'object', - properties: { - orderHash: { $ref: '/hexSchema' }, - }, - required: ['orderHash'], - }, - }, - oneOf: [ - { - type: 'object', - properties: { - id: { type: 'string' }, - jsonrpc: { type: 'string' }, - method: { enum: ['ADD_ORDER'] }, - params: { $ref: '#/definitions/signedOrderParam' }, - }, - required: ['id', 'jsonrpc', 'method', 'params'], - }, - { - type: 'object', - properties: { - id: { type: 'string' }, - jsonrpc: { type: 'string' }, - method: { enum: ['REMOVE_ORDER'] }, - params: { $ref: '#/definitions/orderHashParam' }, - }, - required: ['id', 'jsonrpc', 'method', 'params'], - }, - { - type: 'object', - properties: { - id: { type: 'string' }, - jsonrpc: { type: 'string' }, - method: { enum: ['GET_STATS'] }, - params: {}, - }, - required: ['id', 'jsonrpc', 'method'], - }, - ], -}; -- cgit