Fixed loadLastBlock
This commit is contained in:
parent
0b5adaa9c3
commit
1f9889c8f0
10
lib/services/data.js
vendored
10
lib/services/data.js
vendored
@ -87,18 +87,18 @@ async function loadLastBlock({ name, directory }) {
|
||||
}
|
||||
async function loadSavedEvents({ name, userDirectory, }) {
|
||||
const filePath = path_1.default.join(userDirectory, `${name}.json`.toLowerCase());
|
||||
const loadedBlock = await loadLastBlock({
|
||||
name,
|
||||
directory: userDirectory,
|
||||
});
|
||||
if (!(await existsAsync(filePath))) {
|
||||
return {
|
||||
events: [],
|
||||
lastBlock: 0,
|
||||
lastBlock: loadedBlock || 0,
|
||||
};
|
||||
}
|
||||
try {
|
||||
const events = JSON.parse(await (0, promises_1.readFile)(filePath, { encoding: 'utf8' }));
|
||||
const loadedBlock = await loadLastBlock({
|
||||
name,
|
||||
directory: userDirectory,
|
||||
});
|
||||
return {
|
||||
events,
|
||||
lastBlock: loadedBlock || events[events.length - 1]?.blockNumber || 0,
|
||||
|
@ -114,21 +114,21 @@ export async function loadSavedEvents<T extends MinimalEvents>({
|
||||
}): Promise<BaseEvents<T>> {
|
||||
const filePath = path.join(userDirectory, `${name}.json`.toLowerCase());
|
||||
|
||||
const loadedBlock = await loadLastBlock({
|
||||
name,
|
||||
directory: userDirectory,
|
||||
});
|
||||
|
||||
if (!(await existsAsync(filePath))) {
|
||||
return {
|
||||
events: [] as T[],
|
||||
lastBlock: 0,
|
||||
lastBlock: loadedBlock || 0,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const events = JSON.parse(await readFile(filePath, { encoding: 'utf8' })) as T[];
|
||||
|
||||
const loadedBlock = await loadLastBlock({
|
||||
name,
|
||||
directory: userDirectory,
|
||||
});
|
||||
|
||||
return {
|
||||
events,
|
||||
lastBlock: loadedBlock || events[events.length - 1]?.blockNumber || 0,
|
||||
|
Loading…
Reference in New Issue
Block a user