diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-11 22:54:27 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-11 22:54:27 +0800 |
commit | 12023073f43ad431a9acb5f28bb0a9abea4ab089 (patch) | |
tree | 36b2df8d69b38017c6aae8f15cd6f0280e5300b6 /src/order_watcher/event_watcher.ts | |
parent | 0db0694aad5396aad3bc295120d45da731c53911 (diff) | |
download | dexon-0x-contracts-12023073f43ad431a9acb5f28bb0a9abea4ab089.tar dexon-0x-contracts-12023073f43ad431a9acb5f28bb0a9abea4ab089.tar.gz dexon-0x-contracts-12023073f43ad431a9acb5f28bb0a9abea4ab089.tar.bz2 dexon-0x-contracts-12023073f43ad431a9acb5f28bb0a9abea4ab089.tar.lz dexon-0x-contracts-12023073f43ad431a9acb5f28bb0a9abea4ab089.tar.xz dexon-0x-contracts-12023073f43ad431a9acb5f28bb0a9abea4ab089.tar.zst dexon-0x-contracts-12023073f43ad431a9acb5f28bb0a9abea4ab089.zip |
Use enum instead of boolean to avoid potential bugs from isRemoved incorrectly being set to true
Diffstat (limited to 'src/order_watcher/event_watcher.ts')
-rw-r--r-- | src/order_watcher/event_watcher.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/order_watcher/event_watcher.ts b/src/order_watcher/event_watcher.ts index f86d1f59f..c9e72281c 100644 --- a/src/order_watcher/event_watcher.ts +++ b/src/order_watcher/event_watcher.ts @@ -10,9 +10,15 @@ import { import {AbiDecoder} from '../utils/abi_decoder'; import {intervalUtils} from '../utils/interval_utils'; import {assert} from '../utils/assert'; +import {utils} from '../utils/utils'; const DEFAULT_EVENT_POLLING_INTERVAL = 200; +enum LogEventState { + Removed, + Added, +} + /* * The EventWatcher watches for blockchain events at the specified block confirmation * depth. @@ -56,10 +62,8 @@ export class EventWatcher { } const removedEvents = _.differenceBy(this._lastEvents, pendingEvents, JSON.stringify); const newEvents = _.differenceBy(pendingEvents, this._lastEvents, JSON.stringify); - let isRemoved = true; - await this._emitDifferencesAsync(removedEvents, isRemoved, callback); - isRemoved = false; - await this._emitDifferencesAsync(newEvents, isRemoved, callback); + await this._emitDifferencesAsync(removedEvents, LogEventState.Removed, callback); + await this._emitDifferencesAsync(newEvents, LogEventState.Added, callback); this._lastEvents = pendingEvents; } private async _getEventsAsync(): Promise<Web3.LogEntry[]> { @@ -78,11 +82,11 @@ export class EventWatcher { return events; } private async _emitDifferencesAsync( - logs: Web3.LogEntry[], isRemoved: boolean, callback: EventWatcherCallback, + logs: Web3.LogEntry[], logEventState: LogEventState, callback: EventWatcherCallback, ): Promise<void> { for (const log of logs) { const logEvent = { - removed: isRemoved, + removed: logEventState === LogEventState.Removed, ...log, }; if (!_.isUndefined(this._intervalIdIfExists)) { |