diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-06 18:01:08 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-06 18:01:08 +0800 |
commit | 44e2929a4c3cec6666a2e3ad340028aff2884f69 (patch) | |
tree | 9f271fe69dbf874d26653e60b524ddd03c6a2eee /src | |
parent | 1043def46c137c9d308b3201eddc0d08afa34b10 (diff) | |
download | dexon-sol-tools-44e2929a4c3cec6666a2e3ad340028aff2884f69.tar dexon-sol-tools-44e2929a4c3cec6666a2e3ad340028aff2884f69.tar.gz dexon-sol-tools-44e2929a4c3cec6666a2e3ad340028aff2884f69.tar.bz2 dexon-sol-tools-44e2929a4c3cec6666a2e3ad340028aff2884f69.tar.lz dexon-sol-tools-44e2929a4c3cec6666a2e3ad340028aff2884f69.tar.xz dexon-sol-tools-44e2929a4c3cec6666a2e3ad340028aff2884f69.tar.zst dexon-sol-tools-44e2929a4c3cec6666a2e3ad340028aff2884f69.zip |
Check for blockAndLogStreamer to be undefined instead of th filters object to be empty
Diffstat (limited to 'src')
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 0bd7cc8b1..925537173 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -21,7 +21,7 @@ import {filterUtils} from '../utils/filter_utils'; export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; private _abiDecoder?: AbiDecoder; - private _blockAndLogStreamer: BlockAndLogStreamer; + private _blockAndLogStreamer: BlockAndLogStreamer|undefined; private _blockAndLogStreamInterval: NodeJS.Timer; private _filters: {[filterToken: string]: Web3.FilterObject}; private _filterCallbacks: {[filterToken: string]: EventCallback}; @@ -32,6 +32,7 @@ export class ContractWrapper { this._abiDecoder = abiDecoder; this._filters = {}; this._filterCallbacks = {}; + this._blockAndLogStreamer = undefined; this._onLogAddedSubscriptionToken = undefined; this._onLogRemovedSubscriptionToken = undefined; } @@ -39,7 +40,7 @@ export class ContractWrapper { indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi, callback: EventCallback): string { const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi); - if (_.isEmpty(this._filters)) { + if (_.isUndefined(this._blockAndLogStreamer)) { this._startBlockAndLogStream(); } const filterToken = filterUtils.generateUUID(); @@ -111,14 +112,16 @@ export class ContractWrapper { ); } private _stopBlockAndLogStream(): void { - this._blockAndLogStreamer.unsubscribeFromOnLogAdded(this._onLogAddedSubscriptionToken as string); - this._blockAndLogStreamer.unsubscribeFromOnLogRemoved(this._onLogRemovedSubscriptionToken as string); + (this._blockAndLogStreamer as BlockAndLogStreamer).unsubscribeFromOnLogAdded( + this._onLogAddedSubscriptionToken as string); + (this._blockAndLogStreamer as BlockAndLogStreamer).unsubscribeFromOnLogRemoved( + this._onLogRemovedSubscriptionToken as string); intervalUtils.clearAsyncExcludingInterval(this._blockAndLogStreamInterval); delete this._blockAndLogStreamer; } private async _reconcileBlockAsync(): Promise<void> { const latestBlock = await this._web3Wrapper.getBlockAsync('latest'); // We need to coerce to Block type cause Web3.Block includes types for mempool bloks - this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block); + (this._blockAndLogStreamer as BlockAndLogStreamer).reconcileNewBlock(latestBlock as any as Block); } } |