From ced68e4e022eb1020a4d15ab9a64552b4f92744a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 19:44:21 +0200 Subject: Expose Blockstreams blockRetention config as an OrderWatcher config --- packages/order-watcher/src/order_watcher/event_watcher.ts | 6 ++++++ packages/order-watcher/src/order_watcher/order_watcher.ts | 4 +++- packages/order-watcher/src/types.ts | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts index 08ecf81cb..38ba8101e 100644 --- a/packages/order-watcher/src/order_watcher/event_watcher.ts +++ b/packages/order-watcher/src/order_watcher/event_watcher.ts @@ -27,13 +27,16 @@ export class EventWatcher { private _pollingIntervalMs: number; private _stateLayer: BlockParamLiteral; private _isVerbose: boolean; + private _blockRetention: number; constructor( web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined | number, stateLayer: BlockParamLiteral = BlockParamLiteral.Latest, + blockRetention: number, isVerbose: boolean, ) { this._isVerbose = isVerbose; + this._blockRetention = blockRetention; this._web3Wrapper = web3Wrapper; this._stateLayer = stateLayer; this._pollingIntervalMs = _.isUndefined(pollingIntervalIfExistsMs) @@ -69,6 +72,9 @@ export class EventWatcher { this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper, this._stateLayer), this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper, eventFilter), this._onBlockAndLogStreamerError.bind(this), + { + blockRetention: this._blockRetention, + }, ); const catchAllLogFilter = {}; this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter); diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index b09ba8d9d..2fe012593 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -61,6 +61,7 @@ interface OrderStateByOrderHash { // tslint:disable-next-line:custom-no-magic-numbers const DEFAULT_CLEANUP_JOB_INTERVAL_MS = 1000 * 60 * 60; // 1h +const DEFAULT_BLOCK_RETENTION = 100; /** * This class includes all the functionality related to watching a set of orders @@ -94,7 +95,8 @@ export class OrderWatcher { const stateLayer = _.isUndefined(config) || _.isUndefined(config.stateLayer) ? BlockParamLiteral.Latest : config.stateLayer; const isVerbose = !_.isUndefined(config) && !_.isUndefined(config.isVerbose) ? config.isVerbose : false; - this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, isVerbose); + const blockRetention = !_.isUndefined(config) && !_.isUndefined(config.blockRetention) ? config.blockRetention : DEFAULT_BLOCK_RETENTION; + this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, blockRetention, 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 63e4e7848..e9b8626b6 100644 --- a/packages/order-watcher/src/types.ts +++ b/packages/order-watcher/src/types.ts @@ -14,6 +14,7 @@ export type EventWatcherCallback = (err: null | Error, log?: LogEntryEvent) => v * of an orders expiration. Default=0. * cleanupJobIntervalMs: How often to run a cleanup job which revalidates all the orders. Default=1hr. * stateLayer: Optional blockchain state layer OrderWatcher will monitor for new events. Default=latest. + * blockRetention: The numbers of blocks to retain in-memory, in order to handle block-reorgs. Default=100. */ export interface OrderWatcherConfig { stateLayer: BlockParamLiteral; @@ -22,6 +23,7 @@ export interface OrderWatcherConfig { expirationMarginMs?: number; cleanupJobIntervalMs?: number; isVerbose?: boolean; + blockRetention?: number; } export type OnOrderStateChangeCallback = (err: Error | null, orderState?: OrderState) => void; -- cgit v1.2.3 From 5fc7d9a6032b816156f6c2b39002936649bcbabd Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 19:44:56 +0200 Subject: Fix bug that make all getBlock and getLog requests go to latest block --- packages/order-watcher/src/order_watcher/event_watcher.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts index 38ba8101e..0d3652012 100644 --- a/packages/order-watcher/src/order_watcher/event_watcher.ts +++ b/packages/order-watcher/src/order_watcher/event_watcher.ts @@ -64,13 +64,9 @@ export class EventWatcher { if (!_.isUndefined(this._blockAndLogStreamerIfExists)) { throw new Error(OrderWatcherError.SubscriptionAlreadyPresent); } - const eventFilter = { - fromBlock: this._stateLayer, - toBlock: this._stateLayer, - }; this._blockAndLogStreamerIfExists = new BlockAndLogStreamer( - this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper, this._stateLayer), - this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper, eventFilter), + this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper), + this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper), this._onBlockAndLogStreamerError.bind(this), { blockRetention: this._blockRetention, -- cgit v1.2.3 From 7ac4fa50b55821fe0faa19fa88cdc483a8b53d52 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 19:55:45 +0200 Subject: Update yarn.lock --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index a8a897511..d3886197f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4481,9 +4481,9 @@ ethereumjs-wallet@~0.6.0: utf8 "^2.1.1" uuid "^2.0.1" -ethers@3.0.22: - version "3.0.22" - resolved "https://registry.yarnpkg.com/ethers/-/ethers-3.0.22.tgz#7fab1ea16521705837aa43c15831877b2716b436" +ethers@0xproject/ethers.js#eip-838-reasons, ethers@3.0.22: + version "3.0.18" + resolved "https://codeload.github.com/0xproject/ethers.js/tar.gz/b91342bd200d142af0165d6befddf783c8ae8447" dependencies: aes-js "3.0.0" bn.js "^4.4.0" -- cgit v1.2.3 From f3477ff28c49629acaec3837e414939de8d32c3c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 20:03:22 +0200 Subject: Add changelog entries --- packages/order-watcher/CHANGELOG.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index a66db6eec..1e118ca3b 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -9,6 +9,13 @@ { "note": "Do not stop subscription if error is encountered", "pr": 825 + }, + { + "note": + "Add blockRetention config to OrderWatcher, so user can define how many blocks and they corresp. logs to store in-memory" + }, + { + "note": "Fixed a bug that caused the incorrect block to be fetched via JSON-RPC within Blockstream" } ], "timestamp": 1531149657 -- cgit v1.2.3 From 345f3c07a51a17728f13d954839dcb7047ff6401 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 20:04:21 +0200 Subject: Add PR numbers --- packages/order-watcher/CHANGELOG.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 1e118ca3b..1ce730d19 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -12,10 +12,12 @@ }, { "note": - "Add blockRetention config to OrderWatcher, so user can define how many blocks and they corresp. logs to store in-memory" + "Add blockRetention config to OrderWatcher, so user can define how many blocks and they corresp. logs to store in-memory", + "pr": 875 }, { - "note": "Fixed a bug that caused the incorrect block to be fetched via JSON-RPC within Blockstream" + "note": "Fixed a bug that caused the incorrect block to be fetched via JSON-RPC within Blockstream", + "pr": 875 } ], "timestamp": 1531149657 -- cgit v1.2.3 From 151ce6e3c77e43659899ce299ac9f1b37cf6a042 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 16 Jul 2018 10:24:34 +0200 Subject: Pass stateLater into getBlockAsync call --- packages/order-watcher/src/order_watcher/event_watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts index 0d3652012..d52c6a21e 100644 --- a/packages/order-watcher/src/order_watcher/event_watcher.ts +++ b/packages/order-watcher/src/order_watcher/event_watcher.ts @@ -106,7 +106,7 @@ export class EventWatcher { await this._emitDifferencesAsync(log, isRemoved ? LogEventState.Removed : LogEventState.Added, callback); } private async _reconcileBlockAsync(): Promise { - const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest); + const latestBlock = await this._web3Wrapper.getBlockAsync(this._stateLayer); // 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 -- cgit v1.2.3 From 766ac3f1febcb6f6e4f6c20198283f01b278f671 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 17 Jul 2018 11:57:52 +0200 Subject: Remove blockRetention config --- packages/order-watcher/CHANGELOG.json | 5 ----- packages/order-watcher/src/order_watcher/event_watcher.ts | 6 ------ packages/order-watcher/src/order_watcher/order_watcher.ts | 4 +--- packages/order-watcher/src/types.ts | 2 -- 4 files changed, 1 insertion(+), 16 deletions(-) diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 1ce730d19..d80231dae 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -10,11 +10,6 @@ "note": "Do not stop subscription if error is encountered", "pr": 825 }, - { - "note": - "Add blockRetention config to OrderWatcher, so user can define how many blocks and they corresp. logs to store in-memory", - "pr": 875 - }, { "note": "Fixed a bug that caused the incorrect block to be fetched via JSON-RPC within Blockstream", "pr": 875 diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts index d52c6a21e..1cd198a62 100644 --- a/packages/order-watcher/src/order_watcher/event_watcher.ts +++ b/packages/order-watcher/src/order_watcher/event_watcher.ts @@ -27,16 +27,13 @@ export class EventWatcher { private _pollingIntervalMs: number; private _stateLayer: BlockParamLiteral; private _isVerbose: boolean; - private _blockRetention: number; constructor( web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined | number, stateLayer: BlockParamLiteral = BlockParamLiteral.Latest, - blockRetention: number, isVerbose: boolean, ) { this._isVerbose = isVerbose; - this._blockRetention = blockRetention; this._web3Wrapper = web3Wrapper; this._stateLayer = stateLayer; this._pollingIntervalMs = _.isUndefined(pollingIntervalIfExistsMs) @@ -68,9 +65,6 @@ export class EventWatcher { this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper), this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper), this._onBlockAndLogStreamerError.bind(this), - { - blockRetention: this._blockRetention, - }, ); const catchAllLogFilter = {}; this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter); diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 2fe012593..b09ba8d9d 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -61,7 +61,6 @@ interface OrderStateByOrderHash { // tslint:disable-next-line:custom-no-magic-numbers const DEFAULT_CLEANUP_JOB_INTERVAL_MS = 1000 * 60 * 60; // 1h -const DEFAULT_BLOCK_RETENTION = 100; /** * This class includes all the functionality related to watching a set of orders @@ -95,8 +94,7 @@ export class OrderWatcher { const stateLayer = _.isUndefined(config) || _.isUndefined(config.stateLayer) ? BlockParamLiteral.Latest : config.stateLayer; const isVerbose = !_.isUndefined(config) && !_.isUndefined(config.isVerbose) ? config.isVerbose : false; - const blockRetention = !_.isUndefined(config) && !_.isUndefined(config.blockRetention) ? config.blockRetention : DEFAULT_BLOCK_RETENTION; - this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, blockRetention, isVerbose); + 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 e9b8626b6..63e4e7848 100644 --- a/packages/order-watcher/src/types.ts +++ b/packages/order-watcher/src/types.ts @@ -14,7 +14,6 @@ export type EventWatcherCallback = (err: null | Error, log?: LogEntryEvent) => v * of an orders expiration. Default=0. * cleanupJobIntervalMs: How often to run a cleanup job which revalidates all the orders. Default=1hr. * stateLayer: Optional blockchain state layer OrderWatcher will monitor for new events. Default=latest. - * blockRetention: The numbers of blocks to retain in-memory, in order to handle block-reorgs. Default=100. */ export interface OrderWatcherConfig { stateLayer: BlockParamLiteral; @@ -23,7 +22,6 @@ export interface OrderWatcherConfig { expirationMarginMs?: number; cleanupJobIntervalMs?: number; isVerbose?: boolean; - blockRetention?: number; } export type OnOrderStateChangeCallback = (err: Error | null, orderState?: OrderState) => void; -- cgit v1.2.3 From 1e787a764615bd3df839f2cb117b711be297b9d5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 17 Jul 2018 12:04:29 +0200 Subject: Remove stateLayer OrderWatcher config and instead temporarily hard-code until we get pending block to work with Blockstream --- packages/0x.js/CHANGELOG.json | 4 ++++ packages/order-watcher/CHANGELOG.json | 4 ++++ packages/order-watcher/src/order_watcher/event_watcher.ts | 2 +- packages/order-watcher/src/order_watcher/order_watcher.ts | 9 ++++----- packages/order-watcher/src/types.ts | 2 -- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json index 3ec09cd7e..9419311dd 100644 --- a/packages/0x.js/CHANGELOG.json +++ b/packages/0x.js/CHANGELOG.json @@ -32,6 +32,10 @@ { "note": "0x.js exports renamed contract events and event arg types", "pr": 863 + }, + { + "note": "Remove stateLayer config from OrderWatcher. It now always operates on the latest block", + "pr": 875 } ] }, diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index d80231dae..e747a2129 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -13,6 +13,10 @@ { "note": "Fixed a bug that caused the incorrect block to be fetched via JSON-RPC within Blockstream", "pr": 875 + }, + { + "note": "Remove stateLayer config from OrderWatcher. It now always operates on the latest block", + "pr": 875 } ], "timestamp": 1531149657 diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts index 1cd198a62..60a3c6297 100644 --- a/packages/order-watcher/src/order_watcher/event_watcher.ts +++ b/packages/order-watcher/src/order_watcher/event_watcher.ts @@ -30,7 +30,7 @@ export class EventWatcher { constructor( web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined | number, - stateLayer: BlockParamLiteral = BlockParamLiteral.Latest, + stateLayer: BlockParamLiteral, isVerbose: boolean, ) { this._isVerbose = isVerbose; diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index b09ba8d9d..95671684f 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -61,6 +61,7 @@ interface OrderStateByOrderHash { // tslint:disable-next-line:custom-no-magic-numbers const DEFAULT_CLEANUP_JOB_INTERVAL_MS = 1000 * 60 * 60; // 1h +const STATE_LAYER = BlockParamLiteral.Latest; /** * This class includes all the functionality related to watching a set of orders @@ -91,17 +92,15 @@ export class OrderWatcher { }); this._contractWrappers = new ContractWrappers(provider, { networkId }); const pollingIntervalIfExistsMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs; - const stateLayer = - _.isUndefined(config) || _.isUndefined(config.stateLayer) ? BlockParamLiteral.Latest : config.stateLayer; const isVerbose = !_.isUndefined(config) && !_.isUndefined(config.isVerbose) ? config.isVerbose : false; - this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, isVerbose); + this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, STATE_LAYER, isVerbose); this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore( this._contractWrappers.token, - stateLayer, + STATE_LAYER, ); this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore( this._contractWrappers.exchange, - stateLayer, + STATE_LAYER, ); this._orderStateUtils = new OrderStateUtils( this._balanceAndProxyAllowanceLazyStore, diff --git a/packages/order-watcher/src/types.ts b/packages/order-watcher/src/types.ts index 63e4e7848..f8ec91a51 100644 --- a/packages/order-watcher/src/types.ts +++ b/packages/order-watcher/src/types.ts @@ -13,10 +13,8 @@ export type EventWatcherCallback = (err: null | Error, log?: LogEntryEvent) => v * expirationMarginMs: Amount of time before order expiry that you'd like to be notified * of an orders expiration. Default=0. * cleanupJobIntervalMs: How often to run a cleanup job which revalidates all the orders. Default=1hr. - * stateLayer: Optional blockchain state layer OrderWatcher will monitor for new events. Default=latest. */ export interface OrderWatcherConfig { - stateLayer: BlockParamLiteral; orderExpirationCheckingIntervalMs?: number; eventPollingIntervalMs?: number; expirationMarginMs?: number; -- cgit v1.2.3 From b750ce8be641cd7fe8e7570a7cc49b51a90467cc Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 17 Jul 2018 12:33:43 +0200 Subject: Stop subscriptions from unsubscribing on recoverable network issues --- .../src/contract_wrappers/contract_wrapper.ts | 36 ++++++++++------------ .../src/contract_wrappers/erc20_token_wrapper.ts | 3 ++ .../src/contract_wrappers/erc721_token_wrapper.ts | 3 ++ .../src/contract_wrappers/ether_token_wrapper.ts | 3 ++ .../src/contract_wrappers/exchange_wrapper.ts | 3 ++ 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts index b8ca4d29b..daf70253a 100644 --- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts @@ -1,5 +1,5 @@ import { ContractArtifact } from '@0xproject/sol-compiler'; -import { AbiDecoder, intervalUtils } from '@0xproject/utils'; +import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { BlockParamLiteral, ContractAbi, FilterObject, LogEntry, LogWithDecodedArgs, RawLog } from 'ethereum-types'; import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream'; @@ -41,6 +41,13 @@ export abstract class ContractWrapper { }; private _onLogAddedSubscriptionToken: string | undefined; private _onLogRemovedSubscriptionToken: string | undefined; + private static _onBlockAndLogStreamerError(isVerbose: boolean, err: Error): void { + // Since Blockstream errors are all recoverable, we simply log them if the verbose + // config is passed in. + if (isVerbose) { + logUtils.warn(err); + } + } constructor(web3Wrapper: Web3Wrapper, networkId: number, blockPollingIntervalMs?: number) { this._web3Wrapper = web3Wrapper; this._networkId = networkId; @@ -79,10 +86,11 @@ export abstract class ContractWrapper { indexFilterValues: IndexedFilterValues, abi: ContractAbi, callback: EventCallback, + isVerbose: boolean = false, ): string { const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi); if (_.isUndefined(this._blockAndLogStreamerIfExists)) { - this._startBlockAndLogStream(); + this._startBlockAndLogStream(isVerbose); } const filterToken = filterUtils.generateUUID(); this._filters[filterToken] = filter; @@ -151,21 +159,21 @@ export abstract class ContractWrapper { } }); } - private _startBlockAndLogStream(): void { + private _startBlockAndLogStream(isVerbose: boolean): void { if (!_.isUndefined(this._blockAndLogStreamerIfExists)) { throw new Error(ContractWrappersError.SubscriptionAlreadyPresent); } this._blockAndLogStreamerIfExists = new BlockAndLogStreamer( this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper), this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper), - this._onBlockAndLogStreamerError.bind(this), + ContractWrapper._onBlockAndLogStreamerError.bind(this, isVerbose), ); const catchAllLogFilter = {}; this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter); this._blockAndLogStreamIntervalIfExists = intervalUtils.setAsyncExcludingInterval( this._reconcileBlockAsync.bind(this), this._blockPollingIntervalMs, - this._onReconcileBlockError.bind(this), + ContractWrapper._onBlockAndLogStreamerError.bind(this, isVerbose), ); let isRemoved = false; this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded( @@ -176,20 +184,10 @@ export abstract class ContractWrapper { this._onLogStateChanged.bind(this, isRemoved), ); } - private _onBlockAndLogStreamerError(err: Error): void { - // Propogate all Blockstream subscriber errors to all - // top-level subscriptions - const filterCallbacks = _.values(this._filterCallbacks); - _.each(filterCallbacks, filterCallback => { - filterCallback(err); - }); - } - private _onReconcileBlockError(err: Error): void { - const filterTokens = _.keys(this._filterCallbacks); - _.each(filterTokens, filterToken => { - this._unsubscribe(filterToken, err); - }); - } + // 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 + // of those higher classes. // tslint:disable-next-line:no-unused-variable private _setNetworkId(networkId: number): void { this._networkId = networkId; diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts index 29c63564e..17bda5085 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -347,6 +347,7 @@ export class ERC20TokenWrapper extends ContractWrapper { * @param indexFilterValues An object where the keys are indexed args returned by the event and * the value is the value you are interested in. E.g `{maker: aUserAddressHex}` * @param callback Callback that gets called when a log is added/removed + * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ public subscribe( @@ -354,6 +355,7 @@ export class ERC20TokenWrapper extends ContractWrapper { eventName: ERC20TokenEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback, + isVerbose: boolean = false, ): string { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents); @@ -366,6 +368,7 @@ export class ERC20TokenWrapper extends ContractWrapper { indexFilterValues, artifacts.ERC20Token.compilerOutput.abi, callback, + isVerbose, ); return subscriptionToken; } diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts index b7e5519c4..3d24702b3 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts @@ -372,6 +372,7 @@ export class ERC721TokenWrapper extends ContractWrapper { * @param indexFilterValues An object where the keys are indexed args returned by the event and * the value is the value you are interested in. E.g `{maker: aUserAddressHex}` * @param callback Callback that gets called when a log is added/removed + * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ public subscribe( @@ -379,6 +380,7 @@ export class ERC721TokenWrapper extends ContractWrapper { eventName: ERC721TokenEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback, + isVerbose: boolean = false, ): string { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.doesBelongToStringEnum('eventName', eventName, ERC721TokenEvents); @@ -391,6 +393,7 @@ export class ERC721TokenWrapper extends ContractWrapper { indexFilterValues, artifacts.ERC721Token.compilerOutput.abi, callback, + isVerbose, ); return subscriptionToken; } diff --git a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts index 01440a5e1..5046d3667 100644 --- a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts @@ -146,6 +146,7 @@ export class EtherTokenWrapper extends ContractWrapper { * @param indexFilterValues An object where the keys are indexed args returned by the event and * the value is the value you are interested in. E.g `{_owner: aUserAddressHex}` * @param callback Callback that gets called when a log is added/removed + * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ public subscribe( @@ -153,6 +154,7 @@ export class EtherTokenWrapper extends ContractWrapper { eventName: WETH9Events, indexFilterValues: IndexedFilterValues, callback: EventCallback, + isVerbose: boolean = false, ): string { assert.isETHAddressHex('etherTokenAddress', etherTokenAddress); const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase(); @@ -165,6 +167,7 @@ export class EtherTokenWrapper extends ContractWrapper { indexFilterValues, artifacts.EtherToken.compilerOutput.abi, callback, + isVerbose, ); return subscriptionToken; } diff --git a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts index 8b7148aed..0791c62f5 100644 --- a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts @@ -988,12 +988,14 @@ export class ExchangeWrapper extends ContractWrapper { * @param indexFilterValues An object where the keys are indexed args returned by the event and * the value is the value you are interested in. E.g `{maker: aUserAddressHex}` * @param callback Callback that gets called when a log is added/removed + * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ public subscribe( eventName: ExchangeEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback, + isVerbose: boolean = false, ): string { assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); @@ -1005,6 +1007,7 @@ export class ExchangeWrapper extends ContractWrapper { indexFilterValues, artifacts.Exchange.compilerOutput.abi, callback, + isVerbose, ); return subscriptionToken; } -- cgit v1.2.3 From 59fd5c69c0279194a631462afb0b5241d08bbb72 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 17 Jul 2018 13:27:41 +0200 Subject: Remove no-longer needed tests --- .../contract-wrappers/test/subscription_test.ts | 38 ---------------------- 1 file changed, 38 deletions(-) diff --git a/packages/contract-wrappers/test/subscription_test.ts b/packages/contract-wrappers/test/subscription_test.ts index adda4ab78..80d17576f 100644 --- a/packages/contract-wrappers/test/subscription_test.ts +++ b/packages/contract-wrappers/test/subscription_test.ts @@ -49,44 +49,6 @@ describe('SubscriptionTest', () => { _.each(stubs, s => s.restore()); stubs = []; }); - it('Should receive the Error when an error occurs while fetching the block', (done: DoneCallback) => { - (async () => { - const errMsg = 'Error fetching block'; - const callback = callbackErrorReporter.assertNodeCallbackError(done, errMsg); - stubs = [Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockAsync').throws(new Error(errMsg))]; - contractWrappers.erc20Token.subscribe( - tokenAddress, - ERC20TokenEvents.Approval, - indexFilterValues, - callback, - ); - await contractWrappers.erc20Token.setAllowanceAsync( - tokenAddress, - coinbase, - addressWithoutFunds, - allowanceAmount, - ); - })().catch(done); - }); - it('Should receive the Error when an error occurs while reconciling the new block', (done: DoneCallback) => { - (async () => { - const errMsg = 'Error fetching logs'; - const callback = callbackErrorReporter.assertNodeCallbackError(done, errMsg); - stubs = [Sinon.stub((contractWrappers as any)._web3Wrapper, 'getLogsAsync').throws(new Error(errMsg))]; - contractWrappers.erc20Token.subscribe( - tokenAddress, - ERC20TokenEvents.Approval, - indexFilterValues, - callback, - ); - await contractWrappers.erc20Token.setAllowanceAsync( - tokenAddress, - coinbase, - addressWithoutFunds, - allowanceAmount, - ); - })().catch(done); - }); it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => { (async () => { const callback = (err: Error | null, _logEvent?: DecodedLogEvent) => -- cgit v1.2.3 From f56a7d0cb2bbe8ba9b6c4fb18151ff068165793b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 17 Jul 2018 13:29:36 +0200 Subject: Fix linter --- packages/order-watcher/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/order-watcher/src/types.ts b/packages/order-watcher/src/types.ts index f8ec91a51..fd71267a2 100644 --- a/packages/order-watcher/src/types.ts +++ b/packages/order-watcher/src/types.ts @@ -1,4 +1,4 @@ -import { BlockParamLiteral, LogEntryEvent, OrderState } from '@0xproject/types'; +import { LogEntryEvent, OrderState } from '@0xproject/types'; export enum OrderWatcherError { SubscriptionAlreadyPresent = 'SUBSCRIPTION_ALREADY_PRESENT', -- cgit v1.2.3