diff options
author | Fabio Berger <me@fabioberger.com> | 2018-12-19 21:21:16 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-12-19 21:21:16 +0800 |
commit | 040b402b6d558d13f2f4e032297b6723cdf2aafe (patch) | |
tree | c973d3f5dc7f45ff6ede9f1736315af3ed902828 /packages/order-watcher/src/types.ts | |
parent | 5c24596d812a80011f9e92a13bf91923fbcc2a64 (diff) | |
parent | 552007cafbb577c92b89cedd7d83f5b6d00998e1 (diff) | |
download | dexon-sol-tools-040b402b6d558d13f2f4e032297b6723cdf2aafe.tar dexon-sol-tools-040b402b6d558d13f2f4e032297b6723cdf2aafe.tar.gz dexon-sol-tools-040b402b6d558d13f2f4e032297b6723cdf2aafe.tar.bz2 dexon-sol-tools-040b402b6d558d13f2f4e032297b6723cdf2aafe.tar.lz dexon-sol-tools-040b402b6d558d13f2f4e032297b6723cdf2aafe.tar.xz dexon-sol-tools-040b402b6d558d13f2f4e032297b6723cdf2aafe.tar.zst dexon-sol-tools-040b402b6d558d13f2f4e032297b6723cdf2aafe.zip |
Merge branch 'development' of github.com:0xProject/0x-monorepo into development
* 'development' of github.com:0xProject/0x-monorepo:
Move onMessageAsync outside of tests and add comments
Fix WS tests to remove race-condition and be more specific about the message expected
Add temporary console.log to test failing on CI
Remove unused file
Fix file name
Consolidate use of isVerbose in orderWatcherConfig
Add isVerbose option to enable/disable logging
Fix schemas and tests
Move OrderWatcher Websocket schemas to json-schemas and convert to JSON so that they are language agnostic
Improve our compliance to the JSON RPC spec
remove unused instance variable
Ensure fileName matches class name, fix broadcast
Respond to CR
Respond to CR
WIP: OrderWatcher WebSocket
Diffstat (limited to 'packages/order-watcher/src/types.ts')
-rw-r--r-- | packages/order-watcher/src/types.ts | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/packages/order-watcher/src/types.ts b/packages/order-watcher/src/types.ts index 8078dd971..2b529a939 100644 --- a/packages/order-watcher/src/types.ts +++ b/packages/order-watcher/src/types.ts @@ -1,4 +1,4 @@ -import { OrderState } from '@0x/types'; +import { OrderState, SignedOrder } from '@0x/types'; import { LogEntryEvent } from 'ethereum-types'; export enum OrderWatcherError { @@ -31,3 +31,67 @@ export enum InternalOrderWatcherError { ZrxNotInTokenRegistry = 'ZRX_NOT_IN_TOKEN_REGISTRY', WethNotInTokenRegistry = 'WETH_NOT_IN_TOKEN_REGISTRY', } + +export enum OrderWatcherMethod { + // Methods initiated by the user. + GetStats = 'GET_STATS', + AddOrder = 'ADD_ORDER', + RemoveOrder = 'REMOVE_ORDER', + // These are spontaneous; they are primarily orderstate changes. + Update = 'UPDATE', + // `subscribe` and `unsubscribe` are methods of OrderWatcher, but we don't + // need to expose them to the WebSocket server user because the user implicitly + // subscribes and unsubscribes by connecting and disconnecting from the server. +} + +// Users have to create a json object of this format and attach it to +// the data field of their WebSocket message to interact with the server. +export type WebSocketRequest = AddOrderRequest | RemoveOrderRequest | GetStatsRequest; + +export interface AddOrderRequest { + id: number; + jsonrpc: string; + method: OrderWatcherMethod.AddOrder; + params: { signedOrder: SignedOrder }; +} + +export interface RemoveOrderRequest { + id: number; + jsonrpc: string; + method: OrderWatcherMethod.RemoveOrder; + params: { orderHash: string }; +} + +export interface GetStatsRequest { + id: number; + jsonrpc: string; + method: OrderWatcherMethod.GetStats; +} + +// Users should expect a json object of this format in the data field +// of the WebSocket messages that the server sends out. +export type WebSocketResponse = SuccessfulWebSocketResponse | ErrorWebSocketResponse; + +export interface SuccessfulWebSocketResponse { + id: number; + jsonrpc: string; + method: OrderWatcherMethod; + result: OrderState | GetStatsResult | undefined; // result is undefined for ADD_ORDER and REMOVE_ORDER +} + +export interface ErrorWebSocketResponse { + id: number | null; + jsonrpc: string; + method: null; + error: JSONRPCError; +} + +export interface JSONRPCError { + code: number; + message: string; + data?: string | object; +} + +export interface GetStatsResult { + orderCount: number; +} |