Create server entry point and Dockerfile for OrderWatcher

This commit is contained in:
Fabio Berger 2019-01-08 14:29:45 +01:00
parent 040b402b6d
commit 0bcb81d3a9
3 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,13 @@
FROM node
WORKDIR /order-watcher
COPY package.json .
RUN npm i
RUN npm install forever -g
COPY . .
EXPOSE 8080
CMD ["forever", "./lib/src/server.js"]

View File

@ -36,6 +36,7 @@
"@0x/dev-utils": "^1.0.21",
"@0x/migrations": "^2.2.2",
"@0x/tslint-config": "^2.0.0",
"@0x/subproviders": "^2.1.8",
"@types/bintrees": "^1.0.2",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",

View File

@ -0,0 +1,44 @@
import { getContractAddressesForNetworkOrThrow } from '@0x/contract-addresses';
import { RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import * as _ from 'lodash';
import { OrderWatcherWebSocketServer } from './order_watcher/order_watcher_web_socket_server';
const GANACHE_NETWORK_ID = 50;
const DEFAULT_RPC_URL = 'http://localhost:8545';
const provider = new Web3ProviderEngine();
const jsonRpcUrl = process.env.JSON_RPC_URL || DEFAULT_RPC_URL;
const rpcSubprovider = new RPCSubprovider(jsonRpcUrl);
provider.addProvider(rpcSubprovider);
provider.start();
const networkId = process.env.NETWORK_ID !== undefined ? _.parseInt(process.env.NETWORK_ID) : GANACHE_NETWORK_ID;
const contractAddressesString = process.env.contractAddresses;
const contractAddressesIfExists =
contractAddressesString === undefined
? getContractAddressesForNetworkOrThrow(networkId)
: JSON.parse(contractAddressesString);
const orderWatcherConfig: any = {
isVerbose: process.env.IS_VERBOSE === 'true',
};
const orderExpirationCheckingIntervalMs = process.env.ORDER_EXPIRATION_CHECKING_INTERVAL_MS;
if (orderExpirationCheckingIntervalMs !== undefined) {
orderWatcherConfig.orderExpirationCheckingIntervalMs = _.parseInt(orderExpirationCheckingIntervalMs);
}
const eventPollingIntervalMs = process.env.EVENT_POLLING_INTERVAL_MS;
if (eventPollingIntervalMs !== undefined) {
orderWatcherConfig.eventPollingIntervalMs = _.parseInt(eventPollingIntervalMs);
}
const expirationMarginMs = process.env.EXPIRATION_MARGIN_MS;
if (expirationMarginMs !== undefined) {
orderWatcherConfig.expirationMarginMs = _.parseInt(expirationMarginMs);
}
const cleanupJobIntervalMs = process.env.CLEANUP_JOB_INTERVAL_MS;
if (cleanupJobIntervalMs !== undefined) {
orderWatcherConfig.cleanupJobIntervalMs = _.parseInt(cleanupJobIntervalMs);
}
const wsServer = new OrderWatcherWebSocketServer(provider, networkId, contractAddressesIfExists, orderWatcherConfig);
wsServer.start();