Merge pull request #3 from status-im/event_filter

respect filter conditions even if they are not indexed in the events
This commit is contained in:
Iuri Matias 2019-08-19 13:02:40 -04:00 committed by GitHub
commit 0ca029dbb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

View File

@ -72,8 +72,22 @@ class EventSyncer {
// for e.g, it should start fromBlock, from the latest known block (which means it should store block info) // for e.g, it should start fromBlock, from the latest known block (which means it should store block info)
// it should be able to do events X at the time to avoid slow downs as well as the 10k limit // it should be able to do events X at the time to avoid slow downs as well as the 10k limit
contractInstance.events[eventName].apply(contractInstance.events[eventName], [(filterConditions || {fromBlock: 0}), (err, event) => { contractInstance.events[eventName].apply(contractInstance.events[eventName], [(filterConditions || {fromBlock: 0}), (err, event) => {
// let eventObject = event.returnValues; let propsToFilter = [];
// eventObject.id = event.id; for (let prop in filterConditions.filter) {
if (Object.keys(event.returnValues).indexOf(prop) >= 0) {
propsToFilter.push(prop)
}
}
if (propsToFilter.length === 0) {
return this.events.emit("event-" + eventName, event);
}
for (let prop of propsToFilter) {
if (filterConditions.filter[prop] !== event.returnValues[prop]) {
return;
}
}
this.events.emit("event-" + eventName, event); this.events.emit("event-" + eventName, event);
}]) }])