Merge pull request #51 from embark-framework/fix/net-id

fix: take netId in account when tracking
This commit is contained in:
Iuri Matias 2019-10-22 13:31:05 -04:00 committed by GitHub
commit e61b87c1b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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() {