aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-12-17 09:31:38 +0800
committerFabio Berger <me@fabioberger.com>2018-12-17 09:31:38 +0800
commit896c8d17c16c4f1e9670ab0747ae8934ce5400a5 (patch)
tree84cffb83e3d5e13d3bba68835fdfd96bd58a5182 /packages/order-watcher/src
parentee4185ab465c76b64b65efefb92e11b0ca4ecad4 (diff)
downloaddexon-sol-tools-896c8d17c16c4f1e9670ab0747ae8934ce5400a5.tar
dexon-sol-tools-896c8d17c16c4f1e9670ab0747ae8934ce5400a5.tar.gz
dexon-sol-tools-896c8d17c16c4f1e9670ab0747ae8934ce5400a5.tar.bz2
dexon-sol-tools-896c8d17c16c4f1e9670ab0747ae8934ce5400a5.tar.lz
dexon-sol-tools-896c8d17c16c4f1e9670ab0747ae8934ce5400a5.tar.xz
dexon-sol-tools-896c8d17c16c4f1e9670ab0747ae8934ce5400a5.tar.zst
dexon-sol-tools-896c8d17c16c4f1e9670ab0747ae8934ce5400a5.zip
Fix schemas and tests
Diffstat (limited to 'packages/order-watcher/src')
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts14
-rw-r--r--packages/order-watcher/src/types.ts14
2 files changed, 15 insertions, 13 deletions
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 f90961cc8..da5667db3 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
@@ -105,20 +105,22 @@ export class OrderWatcherWebSocketServer {
private async _onMessageCallbackAsync(connection: WebSocket.connection, message: any): Promise<void> {
let response: WebSocketResponse;
- assert.doesConformToSchema('message', message, schemas.orderWatcherWebSocketUtf8MessageSchema);
- const request: WebSocketRequest = JSON.parse(message.utf8Data);
- assert.doesConformToSchema('request', request, schemas.orderWatcherWebSocketRequestSchema);
- assert.isString(request.jsonrpc, JSON_RPC_VERSION);
+ let id: number | null = null;
try {
+ assert.doesConformToSchema('message', message, schemas.orderWatcherWebSocketUtf8MessageSchema);
+ const request: WebSocketRequest = JSON.parse(message.utf8Data);
+ id = request.id;
+ assert.doesConformToSchema('request', request, schemas.orderWatcherWebSocketRequestSchema);
+ assert.isString(request.jsonrpc, JSON_RPC_VERSION);
response = {
- id: request.id,
+ id,
jsonrpc: JSON_RPC_VERSION,
method: request.method,
result: await this._routeRequestAsync(request),
};
} catch (err) {
response = {
- id: request.id,
+ id,
jsonrpc: JSON_RPC_VERSION,
method: null,
error: err.toString(),
diff --git a/packages/order-watcher/src/types.ts b/packages/order-watcher/src/types.ts
index 536363d8a..2b529a939 100644
--- a/packages/order-watcher/src/types.ts
+++ b/packages/order-watcher/src/types.ts
@@ -48,21 +48,21 @@ export enum OrderWatcherMethod {
// the data field of their WebSocket message to interact with the server.
export type WebSocketRequest = AddOrderRequest | RemoveOrderRequest | GetStatsRequest;
-interface AddOrderRequest {
+export interface AddOrderRequest {
id: number;
jsonrpc: string;
method: OrderWatcherMethod.AddOrder;
params: { signedOrder: SignedOrder };
}
-interface RemoveOrderRequest {
+export interface RemoveOrderRequest {
id: number;
jsonrpc: string;
method: OrderWatcherMethod.RemoveOrder;
params: { orderHash: string };
}
-interface GetStatsRequest {
+export interface GetStatsRequest {
id: number;
jsonrpc: string;
method: OrderWatcherMethod.GetStats;
@@ -72,21 +72,21 @@ interface GetStatsRequest {
// of the WebSocket messages that the server sends out.
export type WebSocketResponse = SuccessfulWebSocketResponse | ErrorWebSocketResponse;
-interface SuccessfulWebSocketResponse {
+export interface SuccessfulWebSocketResponse {
id: number;
jsonrpc: string;
method: OrderWatcherMethod;
result: OrderState | GetStatsResult | undefined; // result is undefined for ADD_ORDER and REMOVE_ORDER
}
-interface ErrorWebSocketResponse {
- id: number;
+export interface ErrorWebSocketResponse {
+ id: number | null;
jsonrpc: string;
method: null;
error: JSONRPCError;
}
-interface JSONRPCError {
+export interface JSONRPCError {
code: number;
message: string;
data?: string | object;