Skip to content

Commit e61b87c

Browse files
authored
Merge pull request #51 from embark-framework/fix/net-id
fix: take netId in account when tracking
2 parents 355deae + 737d189 commit e61b87c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/eventSyncer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class EventSyncer {
1010
this.subscriptions = [];
1111
}
1212

13-
track(contractInstance, eventName, filterConditionsOrCb, gteBlockNum) {
13+
track(contractInstance, eventName, filterConditionsOrCb, gteBlockNum, networkId) {
1414
const isFilterFunction = typeof filterConditionsOrCb === 'function';
15-
const eventKey = hash(Object.assign({address: contractInstance.options.address}, (isFilterFunction ? {filterConditionsOrCb} : (filterConditionsOrCb || {}))));
15+
const eventKey = hash(Object.assign({address: contractInstance.options.address, networkId}, (isFilterFunction ? {filterConditionsOrCb} : (filterConditionsOrCb || {}))));
1616

1717
this.db.deleteNewestBlocks(eventKey, gteBlockNum);
1818

src/logSyncer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class LogSyncer {
1010
this.subscriptions = [];
1111
}
1212

13-
track(options, inputsABI, gteBlockNum){
14-
const eventKey = 'logs-' + hash(options || {});
13+
track(options, inputsABI, gteBlockNum, networkId){
14+
const eventKey = 'logs-' + hash(Object.assign({networkId}, options || {}));
1515
const filterConditions = Object.assign({fromBlock: 0, toBlock: "latest"}, options || {});
1616

1717
this.db.deleteNewestBlocks(eventKey, gteBlockNum);

src/subspace.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class Subspace {
2727
this.options.dbFilename = options.dbFilename || 'subspace.db';
2828
this.latestBlockNumber = undefined;
2929
this.disableDatabase = options.disableDatabase;
30+
this.networkId = undefined;
3031

3132
this.newBlocksSubscription = null;
3233
this.intervalTracker = null;
@@ -43,6 +44,10 @@ export default class Subspace {
4344
this.eventSyncer = new EventSyncer(this.web3, this.events, this._db);
4445
this.logSyncer = new LogSyncer(this.web3, this.events, this._db);
4546

47+
this.web3.net.getId().then(netId => {
48+
this.networkId = netId;
49+
});
50+
4651
this.web3.getBlock('latest').then(block => {
4752
this.latestBlockNumber = block.number;
4853

@@ -109,7 +114,7 @@ export default class Subspace {
109114

110115
// TODO: get contract abi/address instead
111116
trackEvent(contractInstance, eventName, filterConditionsOrCb) {
112-
let returnSub = this.eventSyncer.track(contractInstance, eventName, filterConditionsOrCb, this.latestBlockNumber - this.options.refreshLastNBlocks);
117+
let returnSub = this.eventSyncer.track(contractInstance, eventName, filterConditionsOrCb, this.latestBlockNumber - this.options.refreshLastNBlocks, this.networkId);
113118

114119
returnSub.map = (prop) => {
115120
return returnSub.pipe(map((x) => {
@@ -138,7 +143,7 @@ export default class Subspace {
138143
}
139144

140145
trackLogs(options, inputsABI) {
141-
return this.logSyncer.track(options, inputsABI, this.latestBlockNumber - this.options.refreshLastNBlocks);
146+
return this.logSyncer.track(options, inputsABI, this.latestBlockNumber - this.options.refreshLastNBlocks, this.networkId);
142147
}
143148

144149
_initNewBlocksSubscription() {

0 commit comments

Comments
 (0)