aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher
diff options
context:
space:
mode:
authorAra Kevonian <=>2018-03-30 20:45:24 +0800
committerAra Kevonian <=>2018-03-30 20:59:09 +0800
commit57ca611e12d2e40c3f0f33023544a890be7ccb87 (patch)
treea5ca930194d4295a25b5af7aa683d34a36b5b273 /packages/0x.js/src/order_watcher
parent6122840241a47119b046b639e326cfead1ea3e10 (diff)
downloaddexon-0x-contracts-57ca611e12d2e40c3f0f33023544a890be7ccb87.tar.gz
dexon-0x-contracts-57ca611e12d2e40c3f0f33023544a890be7ccb87.tar.zst
dexon-0x-contracts-57ca611e12d2e40c3f0f33023544a890be7ccb87.zip
Monitor different state layers with OrderWatcher
Allow instantiation of stand-alone OrderWatchers that can monitor different blockchain state layers (e.g. pending or latest)
Diffstat (limited to 'packages/0x.js/src/order_watcher')
-rw-r--r--packages/0x.js/src/order_watcher/event_watcher.ts8
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts8
2 files changed, 11 insertions, 5 deletions
diff --git a/packages/0x.js/src/order_watcher/event_watcher.ts b/packages/0x.js/src/order_watcher/event_watcher.ts
index 246ab8292..deb1ffbff 100644
--- a/packages/0x.js/src/order_watcher/event_watcher.ts
+++ b/packages/0x.js/src/order_watcher/event_watcher.ts
@@ -22,8 +22,10 @@ export class EventWatcher {
private _pollingIntervalMs: number;
private _intervalIdIfExists?: NodeJS.Timer;
private _lastEvents: LogEntry[] = [];
- constructor(web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined | number) {
+ private _stateLayer: BlockParamLiteral;
+ constructor(web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined | number, stateLayer: BlockParamLiteral = BlockParamLiteral.Pending) {
this._web3Wrapper = web3Wrapper;
+ this._stateLayer = stateLayer;
this._pollingIntervalMs = _.isUndefined(pollingIntervalIfExistsMs)
? DEFAULT_EVENT_POLLING_INTERVAL_MS
: pollingIntervalIfExistsMs;
@@ -69,8 +71,8 @@ export class EventWatcher {
}
private async _getEventsAsync(): Promise<LogEntry[]> {
const eventFilter = {
- fromBlock: BlockParamLiteral.Pending,
- toBlock: BlockParamLiteral.Pending,
+ fromBlock: this._stateLayer,
+ toBlock: this._stateLayer,
};
const events = await this._web3Wrapper.getLogsAsync(eventFilter);
return events;
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts
index 9cccadb7f..fcf3c351d 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -76,6 +76,7 @@ export class OrderStateWatcher {
private _balanceAndProxyAllowanceLazyStore: BalanceAndProxyAllowanceLazyStore;
private _cleanupJobInterval: number;
private _cleanupJobIntervalIdIfExists?: NodeJS.Timer;
+ private _stateLayer: BlockParamLiteral;
constructor(
web3Wrapper: Web3Wrapper,
abiDecoder: AbiDecoder,
@@ -86,10 +87,13 @@ export class OrderStateWatcher {
this._abiDecoder = abiDecoder;
this._web3Wrapper = web3Wrapper;
const pollingIntervalIfExistsMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs;
- this._eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalIfExistsMs);
+ this._stateLayer = _.isUndefined(config) || _.isUndefined(config.stateLayer)
+ ? BlockParamLiteral.Pending
+ : config.stateLayer;
+ this._eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalIfExistsMs, this._stateLayer);
this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
token,
- BlockParamLiteral.Pending,
+ this._stateLayer,
);
this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(exchange);
this._orderStateUtils = new OrderStateUtils(