aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher/src/order_watcher/event_watcher.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-09-24 22:53:34 +0800
committerFabio Berger <me@fabioberger.com>2018-09-24 22:53:34 +0800
commit5e1a2bd972cab09d7e487cf80fa9c913e5c0696d (patch)
treeccb43389b3551e410bec00e77acf40e9a1f6575c /packages/order-watcher/src/order_watcher/event_watcher.ts
parent45dc2be0832eefbf6f009b07abb7b7a435b19279 (diff)
parentfc33eacd2cbcc088d238f5e1f34b50b06ea8d58f (diff)
downloaddexon-sol-tools-5e1a2bd972cab09d7e487cf80fa9c913e5c0696d.tar
dexon-sol-tools-5e1a2bd972cab09d7e487cf80fa9c913e5c0696d.tar.gz
dexon-sol-tools-5e1a2bd972cab09d7e487cf80fa9c913e5c0696d.tar.bz2
dexon-sol-tools-5e1a2bd972cab09d7e487cf80fa9c913e5c0696d.tar.lz
dexon-sol-tools-5e1a2bd972cab09d7e487cf80fa9c913e5c0696d.tar.xz
dexon-sol-tools-5e1a2bd972cab09d7e487cf80fa9c913e5c0696d.tar.zst
dexon-sol-tools-5e1a2bd972cab09d7e487cf80fa9c913e5c0696d.zip
Merge development
Diffstat (limited to 'packages/order-watcher/src/order_watcher/event_watcher.ts')
-rw-r--r--packages/order-watcher/src/order_watcher/event_watcher.ts19
1 files changed, 15 insertions, 4 deletions
diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts
index 9509c75de..eca235e26 100644
--- a/packages/order-watcher/src/order_watcher/event_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/event_watcher.ts
@@ -1,6 +1,6 @@
import { intervalUtils, logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
-import { BlockParamLiteral, LogEntry, Provider } from 'ethereum-types';
+import { BlockParamLiteral, BlockWithoutTransactionData, LogEntry, Provider } from 'ethereum-types';
import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream';
import * as _ from 'lodash';
@@ -62,7 +62,7 @@ export class EventWatcher {
throw new Error(OrderWatcherError.SubscriptionAlreadyPresent);
}
this._blockAndLogStreamerIfExists = new BlockAndLogStreamer(
- this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper),
+ this._getBlockOrNullAsync.bind(this),
this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper),
this._onBlockAndLogStreamerError.bind(this),
);
@@ -82,6 +82,14 @@ export class EventWatcher {
this._onLogStateChangedAsync.bind(this, callback, isRemoved),
);
}
+ // This method only exists in order to comply with the expected interface of Blockstream's constructor
+ private async _getBlockOrNullAsync(): Promise<BlockWithoutTransactionData | null> {
+ const blockIfExists = await this._web3Wrapper.getBlockIfExistsAsync.bind(this._web3Wrapper);
+ if (_.isUndefined(blockIfExists)) {
+ return null;
+ }
+ return blockIfExists;
+ }
private _stopBlockAndLogStream(): void {
if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
throw new Error(OrderWatcherError.SubscriptionNotFound);
@@ -100,11 +108,14 @@ export class EventWatcher {
await this._emitDifferencesAsync(log, isRemoved ? LogEventState.Removed : LogEventState.Added, callback);
}
private async _reconcileBlockAsync(): Promise<void> {
- const latestBlock = await this._web3Wrapper.getBlockAsync(this._stateLayer);
+ const latestBlockIfExists = await this._web3Wrapper.getBlockIfExistsAsync(this._stateLayer);
+ if (_.isUndefined(latestBlockIfExists)) {
+ return; // noop
+ }
// We need to coerce to Block type cause Web3.Block includes types for mempool blocks
if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
// If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
- await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block);
+ await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlockIfExists as any) as Block);
}
}
private async _emitDifferencesAsync(