diff options
author | Fabio B <kandinsky454@protonmail.ch> | 2019-01-09 18:27:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-09 18:27:22 +0800 |
commit | 5dd55491b86bf8577405e37d0f2d668aa1273b10 (patch) | |
tree | dbcc96a20935ca97b24bc6a6066d72796b806ea1 /packages/order-watcher/src | |
parent | c1bf2754a8638d568685e09269155464cb216a90 (diff) | |
parent | 28aa12691e00344fe80bd022188a1e7657397aa5 (diff) | |
download | dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.gz dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.bz2 dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.lz dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.xz dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.zst dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.zip |
Merge pull request #1494 from 0xProject/feature/order-watcher/dockerize
Dockerize OrderWatcher WS Server
Diffstat (limited to 'packages/order-watcher/src')
-rw-r--r-- | packages/order-watcher/src/server.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/order-watcher/src/server.ts b/packages/order-watcher/src/server.ts new file mode 100644 index 000000000..1d31e87ab --- /dev/null +++ b/packages/order-watcher/src/server.ts @@ -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(); |