mirror of
https://github.com/embarklabs/subspace.git
synced 2025-01-13 15:55:53 +00:00
Merge pull request #51 from embark-framework/fix/net-id
fix: take netId in account when tracking
This commit is contained in:
commit
e61b87c1b9
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user