diff --git a/packages/core/src/eventSyncer.js b/packages/core/src/eventSyncer.js index e936ec7..16b68b4 100644 --- a/packages/core/src/eventSyncer.js +++ b/packages/core/src/eventSyncer.js @@ -22,7 +22,7 @@ class EventSyncer { const observable = new Observable(subscriber => { const cb = this.callbackFactory(subscriber, filters, eventKey, eventName); - const fnDBEvents = this.serveDBEvents(cb, eventKey); + const fnDBEvents = this.serveDBEvents(cb, eventKey, !filterConditions.saveToDb); const fnPastEvents = this.getPastEvents(cb, eventKey, contractInstance, eventName, filters); const fnSubscribe = this.isWebsocketProvider ? this.subscribeToEvent(cb, contractInstance, eventName) : null; @@ -58,7 +58,9 @@ class EventSyncer { return false; }; - serveDBEvents = (cb, eventKey) => (toBlock, lastCachedBlock) => { + serveDBEvents = (cb, eventKey, fromDB) => (toBlock, lastCachedBlock) => { + if(!fromDB) return false; + const events = this.db.getEventsFor(eventKey); events.forEach(ev => cb(null, ev)); @@ -116,7 +118,9 @@ class EventSyncer { subscriber.next(eventData.returnValues); - this.events.emit("updateDB", {eventKey, eventData}); + if (filterConditions && !!filterConditions.saveToDb) { + this.events.emit("updateDB", {eventKey, eventData}); + } }; close() { diff --git a/packages/core/src/subspace.js b/packages/core/src/subspace.js index f1ef647..399ee87 100644 --- a/packages/core/src/subspace.js +++ b/packages/core/src/subspace.js @@ -104,14 +104,14 @@ export default class Subspace { }, 100); } - SubspaceContract.trackEvent = (eventName, filterConditionsOrCb) => { - return this.trackEvent(SubspaceContract, eventName, filterConditionsOrCb); + SubspaceContract.trackEvent = (eventName, filterConditions) => { + return this.trackEvent(SubspaceContract, eventName, filterConditions); }; Object.keys(SubspaceContract.events).forEach(ev => { if (!SubspaceContract.options.jsonInterface.find(x => x.type === "event" && x.name == ev)) return; - SubspaceContract.events[ev].track = filterConditionsOrCb => - this.trackEvent(SubspaceContract, ev, filterConditionsOrCb); + SubspaceContract.events[ev].track = filterConditions => + this.trackEvent(SubspaceContract, ev, filterConditions); }); SubspaceContract.trackProperty = (propName, methodArgs, callArgs) => {