diff options
author | Fabio Berger <me@fabioberger.com> | 2018-09-24 22:53:34 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-09-24 22:53:34 +0800 |
commit | 5e1a2bd972cab09d7e487cf80fa9c913e5c0696d (patch) | |
tree | ccb43389b3551e410bec00e77acf40e9a1f6575c /packages/contract-wrappers/src | |
parent | 45dc2be0832eefbf6f009b07abb7b7a435b19279 (diff) | |
parent | fc33eacd2cbcc088d238f5e1f34b50b06ea8d58f (diff) | |
download | dexon-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/contract-wrappers/src')
-rw-r--r-- | packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts index 19de17c0a..19a882712 100644 --- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts @@ -2,6 +2,7 @@ import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { BlockParamLiteral, + BlockWithoutTransactionData, ContractAbi, ContractArtifact, FilterObject, @@ -174,7 +175,7 @@ export abstract class ContractWrapper { throw new Error(ContractWrappersError.SubscriptionAlreadyPresent); } this._blockAndLogStreamerIfExists = new BlockAndLogStreamer( - this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper), + this._getBlockOrNullAsync.bind(this), this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper), ContractWrapper._onBlockAndLogStreamerError.bind(this, isVerbose), ); @@ -194,6 +195,14 @@ export abstract class ContractWrapper { this._onLogStateChanged.bind(this, 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; + } // HACK: This should be a package-scoped method (which doesn't exist in TS) // We don't want this method available in the public interface for all classes // who inherit from ContractWrapper, and it is only used by the internal implementation @@ -212,11 +221,14 @@ export abstract class ContractWrapper { delete this._blockAndLogStreamerIfExists; } private async _reconcileBlockAsync(): Promise<void> { - const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest); + const latestBlockIfExists = await this._web3Wrapper.getBlockIfExistsAsync(BlockParamLiteral.Latest); + 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); } } } |