aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-10 05:59:41 +0800
committerFabio Berger <me@fabioberger.com>2017-11-10 05:59:41 +0800
commit126a165f558326625d892c4a379c0ebd66088c9a (patch)
treeac7b872b3cd84e0fcb650845eae08bf40c841f50
parent6f5a55b5fe4c6f0f56303b6ac5dcbd99129ee7bd (diff)
downloaddexon-sol-tools-126a165f558326625d892c4a379c0ebd66088c9a.tar
dexon-sol-tools-126a165f558326625d892c4a379c0ebd66088c9a.tar.gz
dexon-sol-tools-126a165f558326625d892c4a379c0ebd66088c9a.tar.bz2
dexon-sol-tools-126a165f558326625d892c4a379c0ebd66088c9a.tar.lz
dexon-sol-tools-126a165f558326625d892c4a379c0ebd66088c9a.tar.xz
dexon-sol-tools-126a165f558326625d892c4a379c0ebd66088c9a.tar.zst
dexon-sol-tools-126a165f558326625d892c4a379c0ebd66088c9a.zip
Add nested config for orderWatcher
-rw-r--r--src/0x.ts5
-rw-r--r--src/order_watcher/order_state_watcher.ts4
-rw-r--r--src/schemas/zero_ex_config_schema.ts11
-rw-r--r--src/types.ts11
-rw-r--r--test/event_watcher_test.ts6
-rw-r--r--test/order_state_watcher_test.ts2
6 files changed, 27 insertions, 12 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 75a154930..dfe64f2df 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -26,6 +26,7 @@ import {
SignedOrder,
Web3Provider,
ZeroExConfig,
+ OrderStateWatcherConfig,
TransactionReceiptWithDecodedLogs,
} from './types';
import {zeroExConfigSchema} from './schemas/zero_ex_config_schema';
@@ -213,10 +214,10 @@ export class ZeroEx {
this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, 'tokenRegistryContractAddressIfExists');
const etherTokenContractAddressIfExists = _.get(config, 'etherTokenContractAddress');
this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, 'etherTokenContractAddressIfExists');
- const mempoolPollingIntervalMs: number|undefined = _.get(config, 'mempoolPollingIntervalMs');
+ const orderWatcherConfig: OrderStateWatcherConfig|undefined = _.get(config, 'orderWatcherConfig');
const orderStateUtils = new OrderStateUtils(this.token, this.exchange);
this.orderStateWatcher = new OrderStateWatcher(
- this._web3Wrapper, this._abiDecoder, orderStateUtils, mempoolPollingIntervalMs,
+ this._web3Wrapper, this._abiDecoder, orderStateUtils, orderWatcherConfig,
);
}
/**
diff --git a/src/order_watcher/order_state_watcher.ts b/src/order_watcher/order_state_watcher.ts
index e31fc962d..14b5b6cf9 100644
--- a/src/order_watcher/order_state_watcher.ts
+++ b/src/order_watcher/order_state_watcher.ts
@@ -15,6 +15,7 @@ import {
BlockParamLiteral,
LogWithDecodedArgs,
OnOrderStateChangeCallback,
+ OrderStateWatcherConfig,
ExchangeEvents,
TokenEvents,
ZeroExError,
@@ -41,10 +42,11 @@ export class OrderStateWatcher {
private _orderStateUtils: OrderStateUtils;
constructor(
web3Wrapper: Web3Wrapper, abiDecoder: AbiDecoder, orderStateUtils: OrderStateUtils,
- eventPollingIntervalMs?: number) {
+ config?: OrderStateWatcherConfig) {
this._web3Wrapper = web3Wrapper;
this._orders = {};
this._dependentOrderHashes = {};
+ const eventPollingIntervalMs = _.isUndefined(config) ? undefined : config.pollingIntervalMs;
this._eventWatcher = new EventWatcher(
this._web3Wrapper, eventPollingIntervalMs,
);
diff --git a/src/schemas/zero_ex_config_schema.ts b/src/schemas/zero_ex_config_schema.ts
index 5be651a9a..5a2afeaa2 100644
--- a/src/schemas/zero_ex_config_schema.ts
+++ b/src/schemas/zero_ex_config_schema.ts
@@ -5,9 +5,14 @@ export const zeroExConfigSchema = {
exchangeContractAddress: {$ref: '/Address'},
tokenRegistryContractAddress: {$ref: '/Address'},
etherTokenContractAddress: {$ref: '/Address'},
- mempoolPollingIntervalMs: {
- type: 'number',
- min: 0,
+ orderWatcherConfig: {
+ type: 'object',
+ properties: {
+ pollingIntervalMs: {
+ type: 'number',
+ minimum: 0,
+ },
+ },
},
},
type: 'object',
diff --git a/src/types.ts b/src/types.ts
index 4a0a74826..704c0b866 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -396,18 +396,25 @@ export interface JSONRPCPayload {
}
/*
+ * pollingIntervalMs: How often to check for new mempool events
+ */
+export interface OrderStateWatcherConfig {
+ pollingIntervalMs?: number;
+}
+
+/*
* gasPrice: Gas price to use with every transaction
* exchangeContractAddress: The address of an exchange contract to use
* tokenRegistryContractAddress: The address of a token registry contract to use
* etherTokenContractAddress: The address of an ether token contract to use
- * mempoolPollingIntervalMs: How often to check for new mempool events
+ * orderWatcherConfig: All the configs related to the orderWatcher
*/
export interface ZeroExConfig {
gasPrice?: BigNumber; // Gas price to use with every transaction
exchangeContractAddress?: string;
tokenRegistryContractAddress?: string;
etherTokenContractAddress?: string;
- mempoolPollingIntervalMs?: number;
+ orderWatcherConfig?: OrderStateWatcherConfig;
}
export type TransactionReceipt = Web3.TransactionReceipt;
diff --git a/test/event_watcher_test.ts b/test/event_watcher_test.ts
index a246805a0..8f3898287 100644
--- a/test/event_watcher_test.ts
+++ b/test/event_watcher_test.ts
@@ -7,7 +7,7 @@ import BigNumber from 'bignumber.js';
import {chaiSetup} from './utils/chai_setup';
import {web3Factory} from './utils/web3_factory';
import {Web3Wrapper} from '../src/web3_wrapper';
-import {EventWatcher} from '../src/mempool/event_watcher';
+import {EventWatcher} from '../src/order_watcher/event_watcher';
import {
ZeroEx,
LogEvent,
@@ -56,9 +56,9 @@ describe('EventWatcher', () => {
};
before(async () => {
web3 = web3Factory.create();
- const mempoolPollingIntervalMs = 10;
+ const pollingIntervalMs = 10;
web3Wrapper = new Web3Wrapper(web3.currentProvider);
- eventWatcher = new EventWatcher(web3Wrapper, mempoolPollingIntervalMs);
+ eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs);
});
afterEach(() => {
// clean up any stubs after the test has completed
diff --git a/test/order_state_watcher_test.ts b/test/order_state_watcher_test.ts
index 938e1be4c..6060d64c5 100644
--- a/test/order_state_watcher_test.ts
+++ b/test/order_state_watcher_test.ts
@@ -6,7 +6,7 @@ import BigNumber from 'bignumber.js';
import { chaiSetup } from './utils/chai_setup';
import { web3Factory } from './utils/web3_factory';
import { Web3Wrapper } from '../src/web3_wrapper';
-import { OrderStateWatcher } from '../src/mempool/order_state_watcher';
+import { OrderStateWatcher } from '../src/order_watcher/order_state_watcher';
import {
Token,
ZeroEx,