aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-06 18:34:03 +0800
committerFabio Berger <me@fabioberger.com>2018-07-06 18:34:03 +0800
commit1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd (patch)
tree0d5f199ea9ed019f130487397a37d07f2bb8830d /packages/order-watcher/src
parent32ad34d2241c8e23002a4a7fc267a8a2e92fb304 (diff)
downloaddexon-sol-tools-1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd.tar
dexon-sol-tools-1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd.tar.gz
dexon-sol-tools-1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd.tar.bz2
dexon-sol-tools-1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd.tar.lz
dexon-sol-tools-1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd.tar.xz
dexon-sol-tools-1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd.tar.zst
dexon-sol-tools-1e0fa776c1b3a1c471c3ce12ced4a29f6d6a40dd.zip
Add isVerbose flag and log blockstream recoverable errors rather then bubbling them up
Diffstat (limited to 'packages/order-watcher/src')
-rw-r--r--packages/order-watcher/src/order_watcher/event_watcher.ts21
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts3
-rw-r--r--packages/order-watcher/src/types.ts3
3 files changed, 17 insertions, 10 deletions
diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts
index d439d9e5b..08ecf81cb 100644
--- a/packages/order-watcher/src/order_watcher/event_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/event_watcher.ts
@@ -1,5 +1,5 @@
import { BlockParamLiteral, LogEntry } from '@0xproject/types';
-import { intervalUtils } from '@0xproject/utils';
+import { intervalUtils, logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream';
import * as _ from 'lodash';
@@ -26,16 +26,14 @@ export class EventWatcher {
private _onLogRemovedSubscriptionToken: string | undefined;
private _pollingIntervalMs: number;
private _stateLayer: BlockParamLiteral;
- private static _onBlockAndLogStreamerError(callback: EventWatcherCallback, err: Error): void {
- // Propogate all Blockstream subscriber errors to
- // top-level subscription
- callback(err);
- }
+ private _isVerbose: boolean;
constructor(
web3Wrapper: Web3Wrapper,
pollingIntervalIfExistsMs: undefined | number,
stateLayer: BlockParamLiteral = BlockParamLiteral.Latest,
+ isVerbose: boolean,
) {
+ this._isVerbose = isVerbose;
this._web3Wrapper = web3Wrapper;
this._stateLayer = stateLayer;
this._pollingIntervalMs = _.isUndefined(pollingIntervalIfExistsMs)
@@ -70,14 +68,14 @@ export class EventWatcher {
this._blockAndLogStreamerIfExists = new BlockAndLogStreamer(
this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper, this._stateLayer),
this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper, eventFilter),
- EventWatcher._onBlockAndLogStreamerError.bind(this, callback),
+ this._onBlockAndLogStreamerError.bind(this),
);
const catchAllLogFilter = {};
this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter);
this._blockAndLogStreamIntervalIfExists = intervalUtils.setAsyncExcludingInterval(
this._reconcileBlockAsync.bind(this),
this._pollingIntervalMs,
- EventWatcher._onBlockAndLogStreamerError.bind(this, callback),
+ this._onBlockAndLogStreamerError.bind(this),
);
let isRemoved = false;
this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded(
@@ -126,4 +124,11 @@ export class EventWatcher {
callback(null, logEvent);
}
}
+ private _onBlockAndLogStreamerError(err: Error): void {
+ // Since Blockstream errors are all recoverable, we simply log them if the verbose
+ // config is passed in.
+ if (this._isVerbose) {
+ logUtils.warn(err);
+ }
+ }
}
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index b28e9bc37..a822e9f56 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -90,7 +90,8 @@ export class OrderWatcher {
const pollingIntervalIfExistsMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs;
const stateLayer =
_.isUndefined(config) || _.isUndefined(config.stateLayer) ? BlockParamLiteral.Latest : config.stateLayer;
- this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer);
+ const isVerbose = !_.isUndefined(config) && !_.isUndefined(config.isVerbose) ? config.isVerbose : false;
+ this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, isVerbose);
this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
this._contractWrappers.token,
stateLayer,
diff --git a/packages/order-watcher/src/types.ts b/packages/order-watcher/src/types.ts
index f5b189c5a..63e4e7848 100644
--- a/packages/order-watcher/src/types.ts
+++ b/packages/order-watcher/src/types.ts
@@ -16,11 +16,12 @@ export type EventWatcherCallback = (err: null | Error, log?: LogEntryEvent) => v
* stateLayer: Optional blockchain state layer OrderWatcher will monitor for new events. Default=latest.
*/
export interface OrderWatcherConfig {
+ stateLayer: BlockParamLiteral;
orderExpirationCheckingIntervalMs?: number;
eventPollingIntervalMs?: number;
expirationMarginMs?: number;
cleanupJobIntervalMs?: number;
- stateLayer: BlockParamLiteral;
+ isVerbose?: boolean;
}
export type OnOrderStateChangeCallback = (err: Error | null, orderState?: OrderState) => void;