Minor updates #1

Closed
tornadocontrib wants to merge 67 commits from tornadocontrib/tornado-core:main into main
6 changed files with 22 additions and 82 deletions
Showing only changes of commit 0bd87f9b67 - Show all commits

View File

@ -82,7 +82,7 @@ export declare class BaseEventsService<EventType extends MinimalEvents> {
*/
updateEvents(): Promise<{
events: EventType[];
lastBlock: number | null;
lastBlock: number;
}>;
}
export type BaseTornadoServiceConstructor = {

22
dist/index.js vendored
View File

@ -2907,12 +2907,6 @@ class BaseEventsService {
const events = yield this.formatEvents(
yield this.batchEventsService.getBatchEvents({ fromBlock, toBlock, type: this.getType() })
);
if (!events.length) {
return {
events,
lastBlock: toBlock
};
}
return {
events,
lastBlock: toBlock
@ -2928,16 +2922,12 @@ class BaseEventsService {
}
getLatestEvents(_0) {
return __async$8(this, arguments, function* ({ fromBlock }) {
const allEvents = [];
const graphEvents = yield this.getEventsFromGraph({ fromBlock });
const lastSyncBlock = graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock;
const rpcEvents = yield this.getEventsFromRpc({ fromBlock: lastSyncBlock });
allEvents.push(...graphEvents.events);
allEvents.push(...rpcEvents.events);
const lastBlock = rpcEvents ? rpcEvents.lastBlock : allEvents[allEvents.length - 1] ? allEvents[allEvents.length - 1].blockNumber : fromBlock;
return {
events: allEvents,
lastBlock
events: [...graphEvents.events, ...rpcEvents.events],
lastBlock: rpcEvents.lastBlock
};
});
}
@ -2957,6 +2947,7 @@ class BaseEventsService {
*/
updateEvents() {
return __async$8(this, null, function* () {
var _a;
const savedEvents = yield this.getSavedEvents();
let fromBlock = this.deployedBlock;
if (savedEvents && savedEvents.lastBlock) {
@ -2964,10 +2955,7 @@ class BaseEventsService {
}
const newEvents = yield this.getLatestEvents({ fromBlock });
const eventSet = /* @__PURE__ */ new Set();
let allEvents = [];
allEvents.push(...savedEvents.events);
allEvents.push(...newEvents.events);
allEvents = allEvents.sort((a, b) => {
const allEvents = [...savedEvents.events, ...newEvents.events].sort((a, b) => {
if (a.blockNumber === b.blockNumber) {
return a.logIndex - b.logIndex;
}
@ -2978,7 +2966,7 @@ class BaseEventsService {
eventSet.add(eventKey);
return !hasEvent;
});
const lastBlock = newEvents ? newEvents.lastBlock : allEvents[allEvents.length - 1] ? allEvents[allEvents.length - 1].blockNumber : null;
const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber);
this.validateEvents({ events: allEvents, lastBlock });
if (savedEvents.fromCache || newEvents.events.length) {
yield this.saveEvents({ events: allEvents, lastBlock });

22
dist/index.mjs vendored
View File

@ -2886,12 +2886,6 @@ class BaseEventsService {
const events = yield this.formatEvents(
yield this.batchEventsService.getBatchEvents({ fromBlock, toBlock, type: this.getType() })
);
if (!events.length) {
return {
events,
lastBlock: toBlock
};
}
return {
events,
lastBlock: toBlock
@ -2907,16 +2901,12 @@ class BaseEventsService {
}
getLatestEvents(_0) {
return __async$8(this, arguments, function* ({ fromBlock }) {
const allEvents = [];
const graphEvents = yield this.getEventsFromGraph({ fromBlock });
const lastSyncBlock = graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock;
const rpcEvents = yield this.getEventsFromRpc({ fromBlock: lastSyncBlock });
allEvents.push(...graphEvents.events);
allEvents.push(...rpcEvents.events);
const lastBlock = rpcEvents ? rpcEvents.lastBlock : allEvents[allEvents.length - 1] ? allEvents[allEvents.length - 1].blockNumber : fromBlock;
return {
events: allEvents,
lastBlock
events: [...graphEvents.events, ...rpcEvents.events],
lastBlock: rpcEvents.lastBlock
};
});
}
@ -2936,6 +2926,7 @@ class BaseEventsService {
*/
updateEvents() {
return __async$8(this, null, function* () {
var _a;
const savedEvents = yield this.getSavedEvents();
let fromBlock = this.deployedBlock;
if (savedEvents && savedEvents.lastBlock) {
@ -2943,10 +2934,7 @@ class BaseEventsService {
}
const newEvents = yield this.getLatestEvents({ fromBlock });
const eventSet = /* @__PURE__ */ new Set();
let allEvents = [];
allEvents.push(...savedEvents.events);
allEvents.push(...newEvents.events);
allEvents = allEvents.sort((a, b) => {
const allEvents = [...savedEvents.events, ...newEvents.events].sort((a, b) => {
if (a.blockNumber === b.blockNumber) {
return a.logIndex - b.logIndex;
}
@ -2957,7 +2945,7 @@ class BaseEventsService {
eventSet.add(eventKey);
return !hasEvent;
});
const lastBlock = newEvents ? newEvents.lastBlock : allEvents[allEvents.length - 1] ? allEvents[allEvents.length - 1].blockNumber : null;
const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber);
this.validateEvents({ events: allEvents, lastBlock });
if (savedEvents.fromCache || newEvents.events.length) {
yield this.saveEvents({ events: allEvents, lastBlock });

22
dist/index.umd.js vendored
View File

@ -59255,12 +59255,6 @@ class BaseEventsService {
const events = yield this.formatEvents(
yield this.batchEventsService.getBatchEvents({ fromBlock, toBlock, type: this.getType() })
);
if (!events.length) {
return {
events,
lastBlock: toBlock
};
}
return {
events,
lastBlock: toBlock
@ -59276,16 +59270,12 @@ class BaseEventsService {
}
getLatestEvents(_0) {
return __async(this, arguments, function* ({ fromBlock }) {
const allEvents = [];
const graphEvents = yield this.getEventsFromGraph({ fromBlock });
const lastSyncBlock = graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock;
const rpcEvents = yield this.getEventsFromRpc({ fromBlock: lastSyncBlock });
allEvents.push(...graphEvents.events);
allEvents.push(...rpcEvents.events);
const lastBlock = rpcEvents ? rpcEvents.lastBlock : allEvents[allEvents.length - 1] ? allEvents[allEvents.length - 1].blockNumber : fromBlock;
return {
events: allEvents,
lastBlock
events: [...graphEvents.events, ...rpcEvents.events],
lastBlock: rpcEvents.lastBlock
};
});
}
@ -59305,6 +59295,7 @@ class BaseEventsService {
*/
updateEvents() {
return __async(this, null, function* () {
var _a;
const savedEvents = yield this.getSavedEvents();
let fromBlock = this.deployedBlock;
if (savedEvents && savedEvents.lastBlock) {
@ -59312,10 +59303,7 @@ class BaseEventsService {
}
const newEvents = yield this.getLatestEvents({ fromBlock });
const eventSet = /* @__PURE__ */ new Set();
let allEvents = [];
allEvents.push(...savedEvents.events);
allEvents.push(...newEvents.events);
allEvents = allEvents.sort((a, b) => {
const allEvents = [...savedEvents.events, ...newEvents.events].sort((a, b) => {
if (a.blockNumber === b.blockNumber) {
return a.logIndex - b.logIndex;
}
@ -59326,7 +59314,7 @@ class BaseEventsService {
eventSet.add(eventKey);
return !hasEvent;
});
const lastBlock = newEvents ? newEvents.lastBlock : allEvents[allEvents.length - 1] ? allEvents[allEvents.length - 1].blockNumber : null;
const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber);
this.validateEvents({ events: allEvents, lastBlock });
if (savedEvents.fromCache || newEvents.events.length) {
yield this.saveEvents({ events: allEvents, lastBlock });

View File

@ -1,6 +1,6 @@
{
"name": "@tornado/core",
"version": "1.0.8",
"version": "1.0.9",
"description": "An SDK for building applications on top of Privacy Pools",
"main": "./dist/index.js",
"module": "./dist/index.mjs",

View File

@ -244,13 +244,6 @@ export class BaseEventsService<EventType extends MinimalEvents> {
await this.batchEventsService.getBatchEvents({ fromBlock, toBlock, type: this.getType() }),
);
if (!events.length) {
return {
events,
lastBlock: toBlock,
};
}
return {
events,
lastBlock: toBlock,
@ -265,22 +258,13 @@ export class BaseEventsService<EventType extends MinimalEvents> {
}
async getLatestEvents({ fromBlock }: { fromBlock: number }): Promise<BaseEvents<EventType>> {
const allEvents = [];
const graphEvents = await this.getEventsFromGraph({ fromBlock });
const lastSyncBlock =
graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock;
const rpcEvents = await this.getEventsFromRpc({ fromBlock: lastSyncBlock });
allEvents.push(...graphEvents.events);
allEvents.push(...rpcEvents.events);
const lastBlock = rpcEvents
? rpcEvents.lastBlock
: allEvents[allEvents.length - 1]
? allEvents[allEvents.length - 1].blockNumber
: fromBlock;
return {
events: allEvents,
lastBlock,
events: [...graphEvents.events, ...rpcEvents.events],
lastBlock: rpcEvents.lastBlock,
};
}
@ -311,12 +295,7 @@ export class BaseEventsService<EventType extends MinimalEvents> {
const eventSet = new Set();
let allEvents: EventType[] = [];
allEvents.push(...savedEvents.events);
allEvents.push(...newEvents.events);
allEvents = allEvents
const allEvents: EventType[] = [...savedEvents.events, ...newEvents.events]
.sort((a, b) => {
if (a.blockNumber === b.blockNumber) {
return a.logIndex - b.logIndex;
@ -329,11 +308,8 @@ export class BaseEventsService<EventType extends MinimalEvents> {
eventSet.add(eventKey);
return !hasEvent;
});
const lastBlock = newEvents
? newEvents.lastBlock
: allEvents[allEvents.length - 1]
? allEvents[allEvents.length - 1].blockNumber
: null;
const lastBlock = newEvents.lastBlock || allEvents[allEvents.length - 1]?.blockNumber;
this.validateEvents({ events: allEvents, lastBlock });