From 737d18909294a3ec683df9fc5fcad5cd36cb26e4 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 22 Oct 2019 09:11:54 -0400 Subject: [PATCH] fix: take netid in account when tracking --- src/eventSyncer.js | 4 ++-- src/logSyncer.js | 4 ++-- src/subspace.js | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/eventSyncer.js b/src/eventSyncer.js index 741fe92..6cc797a 100644 --- a/src/eventSyncer.js +++ b/src/eventSyncer.js @@ -10,9 +10,9 @@ class EventSyncer { this.subscriptions = []; } - track(contractInstance, eventName, filterConditionsOrCb, gteBlockNum) { + track(contractInstance, eventName, filterConditionsOrCb, gteBlockNum, networkId) { const isFilterFunction = typeof filterConditionsOrCb === 'function'; - const eventKey = hash(Object.assign({address: contractInstance.options.address}, (isFilterFunction ? {filterConditionsOrCb} : (filterConditionsOrCb || {})))); + const eventKey = hash(Object.assign({address: contractInstance.options.address, networkId}, (isFilterFunction ? {filterConditionsOrCb} : (filterConditionsOrCb || {})))); this.db.deleteNewestBlocks(eventKey, gteBlockNum); diff --git a/src/logSyncer.js b/src/logSyncer.js index 853fe34..e97c494 100644 --- a/src/logSyncer.js +++ b/src/logSyncer.js @@ -10,8 +10,8 @@ class LogSyncer { this.subscriptions = []; } - track(options, inputsABI, gteBlockNum){ - const eventKey = 'logs-' + hash(options || {}); + track(options, inputsABI, gteBlockNum, networkId){ + const eventKey = 'logs-' + hash(Object.assign({networkId}, options || {})); const filterConditions = Object.assign({fromBlock: 0, toBlock: "latest"}, options || {}); this.db.deleteNewestBlocks(eventKey, gteBlockNum); diff --git a/src/subspace.js b/src/subspace.js index ff5d2bc..d1afd78 100644 --- a/src/subspace.js +++ b/src/subspace.js @@ -27,6 +27,7 @@ export default class Subspace { this.options.dbFilename = options.dbFilename || 'subspace.db'; this.latestBlockNumber = undefined; this.disableDatabase = options.disableDatabase; + this.networkId = undefined; this.newBlocksSubscription = null; this.intervalTracker = null; @@ -43,6 +44,10 @@ export default class Subspace { this.eventSyncer = new EventSyncer(this.web3, this.events, this._db); this.logSyncer = new LogSyncer(this.web3, this.events, this._db); + this.web3.net.getId().then(netId => { + this.networkId = netId; + }); + this.web3.getBlock('latest').then(block => { this.latestBlockNumber = block.number; @@ -109,7 +114,7 @@ export default class Subspace { // TODO: get contract abi/address instead trackEvent(contractInstance, eventName, filterConditionsOrCb) { - let returnSub = this.eventSyncer.track(contractInstance, eventName, filterConditionsOrCb, this.latestBlockNumber - this.options.refreshLastNBlocks); + let returnSub = this.eventSyncer.track(contractInstance, eventName, filterConditionsOrCb, this.latestBlockNumber - this.options.refreshLastNBlocks, this.networkId); returnSub.map = (prop) => { return returnSub.pipe(map((x) => { @@ -138,7 +143,7 @@ export default class Subspace { } trackLogs(options, inputsABI) { - return this.logSyncer.track(options, inputsABI, this.latestBlockNumber - this.options.refreshLastNBlocks); + return this.logSyncer.track(options, inputsABI, this.latestBlockNumber - this.options.refreshLastNBlocks, this.networkId); } _initNewBlocksSubscription() {