Move OrderWatcher Websocket schemas to json-schemas and convert to JSON so that they are language agnostic
This commit is contained in:
parent
7661cfc85e
commit
ee4185ab46
@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"id": "/orderWatcherWebSocketRequestSchema",
|
||||||
|
"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"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"id": "/orderWatcherWebSocketUtf8MessageSchema",
|
||||||
|
"properties": {
|
||||||
|
"utf8Data": { "type": "string" }
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"utf8Data"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
}
|
@ -16,6 +16,8 @@ import * as orderFillOrKillRequestsSchema from '../schemas/order_fill_or_kill_re
|
|||||||
import * as orderFillRequestsSchema from '../schemas/order_fill_requests_schema.json';
|
import * as orderFillRequestsSchema from '../schemas/order_fill_requests_schema.json';
|
||||||
import * as orderHashSchema from '../schemas/order_hash_schema.json';
|
import * as orderHashSchema from '../schemas/order_hash_schema.json';
|
||||||
import * as orderSchema from '../schemas/order_schema.json';
|
import * as orderSchema from '../schemas/order_schema.json';
|
||||||
|
import * as orderWatcherWebSocketRequestSchema from '../schemas/order_watcher_web_socket_request_schema.json';
|
||||||
|
import * as orderWatcherWebSocketUtf8MessageSchema from '../schemas/order_watcher_web_socket_utf8_message_schema.json';
|
||||||
import * as orderBookRequestSchema from '../schemas/orderbook_request_schema.json';
|
import * as orderBookRequestSchema from '../schemas/orderbook_request_schema.json';
|
||||||
import * as ordersRequestOptsSchema from '../schemas/orders_request_opts_schema.json';
|
import * as ordersRequestOptsSchema from '../schemas/orders_request_opts_schema.json';
|
||||||
import * as ordersSchema from '../schemas/orders_schema.json';
|
import * as ordersSchema from '../schemas/orders_schema.json';
|
||||||
@ -66,6 +68,8 @@ export const schemas = {
|
|||||||
jsNumber,
|
jsNumber,
|
||||||
requestOptsSchema,
|
requestOptsSchema,
|
||||||
pagedRequestOptsSchema,
|
pagedRequestOptsSchema,
|
||||||
|
orderWatcherWebSocketRequestSchema,
|
||||||
|
orderWatcherWebSocketUtf8MessageSchema,
|
||||||
ordersRequestOptsSchema,
|
ordersRequestOptsSchema,
|
||||||
orderBookRequestSchema,
|
orderBookRequestSchema,
|
||||||
orderConfigRequestSchema,
|
orderConfigRequestSchema,
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
"./schemas/order_schema.json",
|
"./schemas/order_schema.json",
|
||||||
"./schemas/signed_order_schema.json",
|
"./schemas/signed_order_schema.json",
|
||||||
"./schemas/orders_schema.json",
|
"./schemas/orders_schema.json",
|
||||||
|
"./schemas/order_watcher_web_socket_request_schema.json",
|
||||||
|
"./schemas/order_watcher_web_socket_utf8_message_schema.json",
|
||||||
"./schemas/paginated_collection_schema.json",
|
"./schemas/paginated_collection_schema.json",
|
||||||
"./schemas/relayer_api_asset_data_pairs_response_schema.json",
|
"./schemas/relayer_api_asset_data_pairs_response_schema.json",
|
||||||
"./schemas/relayer_api_asset_data_pairs_schema.json",
|
"./schemas/relayer_api_asset_data_pairs_schema.json",
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ContractAddresses } from '@0x/contract-addresses';
|
import { ContractAddresses } from '@0x/contract-addresses';
|
||||||
|
import { schemas } from '@0x/json-schemas';
|
||||||
import { OrderStateInvalid, OrderStateValid, SignedOrder } from '@0x/types';
|
import { OrderStateInvalid, OrderStateValid, SignedOrder } from '@0x/types';
|
||||||
import { BigNumber, logUtils } from '@0x/utils';
|
import { BigNumber, logUtils } from '@0x/utils';
|
||||||
import { Provider } from 'ethereum-types';
|
import { Provider } from 'ethereum-types';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import * as WebSocket from 'websocket';
|
import * as WebSocket from 'websocket';
|
||||||
|
|
||||||
import { webSocketRequestSchema, webSocketUtf8MessageSchema } from '../schemas/websocket_schemas';
|
|
||||||
import { GetStatsResult, OrderWatcherConfig, OrderWatcherMethod, WebSocketRequest, WebSocketResponse } from '../types';
|
import { GetStatsResult, OrderWatcherConfig, OrderWatcherMethod, WebSocketRequest, WebSocketResponse } from '../types';
|
||||||
import { assert } from '../utils/assert';
|
import { assert } from '../utils/assert';
|
||||||
|
|
||||||
@ -105,9 +105,9 @@ export class OrderWatcherWebSocketServer {
|
|||||||
|
|
||||||
private async _onMessageCallbackAsync(connection: WebSocket.connection, message: any): Promise<void> {
|
private async _onMessageCallbackAsync(connection: WebSocket.connection, message: any): Promise<void> {
|
||||||
let response: WebSocketResponse;
|
let response: WebSocketResponse;
|
||||||
assert.doesConformToSchema('message', message, webSocketUtf8MessageSchema);
|
assert.doesConformToSchema('message', message, schemas.orderWatcherWebSocketUtf8MessageSchema);
|
||||||
const request: WebSocketRequest = JSON.parse(message.utf8Data);
|
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);
|
assert.isString(request.jsonrpc, JSON_RPC_VERSION);
|
||||||
try {
|
try {
|
||||||
response = {
|
response = {
|
||||||
|
@ -1,63 +1,2 @@
|
|||||||
// TODO: Move these schemas to the `json-schemas` package and convert to JSON
|
// TODO: Move these schemas to the `json-schemas` package and convert to JSON
|
||||||
// Rename to `OrderWatcherWebSocketRequestSchema`, etc...
|
// 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'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user