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