Include events from cache to be audited and saved

This commit is contained in:
Tornado Contrib 2024-11-19 22:42:50 +00:00
parent 69f89ae597
commit 68fcf07c2a
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
5 changed files with 18 additions and 13 deletions

7
dist/index.js vendored

@ -2327,13 +2327,14 @@ class BaseEventsService {
return !hasEvent; return !hasEvent;
}); });
const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber; const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber;
const unknownEvents = savedEvents.fromCache ? allEvents : newEvents.events;
const validateResult = await this.validateEvents({ const validateResult = await this.validateEvents({
events: allEvents, events: allEvents,
newEvents: newEvents.events, newEvents: unknownEvents,
lastBlock lastBlock
}); });
if (savedEvents.fromCache || newEvents.events.length) { if (unknownEvents.length) {
await this.saveEvents({ events: allEvents, newEvents: newEvents.events, lastBlock }); await this.saveEvents({ events: allEvents, newEvents: unknownEvents, lastBlock });
} }
return { return {
events: allEvents, events: allEvents,

7
dist/index.mjs vendored

@ -2305,13 +2305,14 @@ class BaseEventsService {
return !hasEvent; return !hasEvent;
}); });
const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber; const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber;
const unknownEvents = savedEvents.fromCache ? allEvents : newEvents.events;
const validateResult = await this.validateEvents({ const validateResult = await this.validateEvents({
events: allEvents, events: allEvents,
newEvents: newEvents.events, newEvents: unknownEvents,
lastBlock lastBlock
}); });
if (savedEvents.fromCache || newEvents.events.length) { if (unknownEvents.length) {
await this.saveEvents({ events: allEvents, newEvents: newEvents.events, lastBlock }); await this.saveEvents({ events: allEvents, newEvents: unknownEvents, lastBlock });
} }
return { return {
events: allEvents, events: allEvents,

7
dist/tornado.umd.js vendored

@ -92334,13 +92334,14 @@ class BaseEventsService {
return !hasEvent; return !hasEvent;
}); });
const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber; const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber;
const unknownEvents = savedEvents.fromCache ? allEvents : newEvents.events;
const validateResult = await this.validateEvents({ const validateResult = await this.validateEvents({
events: allEvents, events: allEvents,
newEvents: newEvents.events, newEvents: unknownEvents,
lastBlock lastBlock
}); });
if (savedEvents.fromCache || newEvents.events.length) { if (unknownEvents.length) {
await this.saveEvents({ events: allEvents, newEvents: newEvents.events, lastBlock }); await this.saveEvents({ events: allEvents, newEvents: unknownEvents, lastBlock });
} }
return { return {
events: allEvents, events: allEvents,

File diff suppressed because one or more lines are too long

@ -276,15 +276,17 @@ export class BaseEventsService<EventType extends MinimalEvents> {
const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber; const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber;
const unknownEvents = (savedEvents as CachedEvents<EventType>).fromCache ? allEvents : newEvents.events;
const validateResult = await this.validateEvents<S>({ const validateResult = await this.validateEvents<S>({
events: allEvents, events: allEvents,
newEvents: newEvents.events, newEvents: unknownEvents,
lastBlock, lastBlock,
}); });
// If the events are loaded from cache or we have found new events, save them // If the events are loaded from cache or we have found new events, save them
if ((savedEvents as CachedEvents<EventType>).fromCache || newEvents.events.length) { if (unknownEvents.length) {
await this.saveEvents({ events: allEvents, newEvents: newEvents.events, lastBlock }); await this.saveEvents({ events: allEvents, newEvents: unknownEvents, lastBlock });
} }
return { return {