Skip to content

Commit

Permalink
add listener on fetch block
Browse files Browse the repository at this point in the history
  • Loading branch information
bz888 committed Apr 15, 2024
1 parent 44a5280 commit dd70d21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export class ApiService
this.nodeConfig.kyveChainId,
this.project.fileCacheDir,
);

this.eventEmitter.on('block_processing_height', (block) => {
console.log('block_processing_height', block);
});
}

return this;
Expand All @@ -129,7 +133,10 @@ export class ApiService
): Promise<IBlock<BlockContent>[]> {
try {
if (this.kyveApi) {
return this.kyveApi.fetchBlocksBatches(this.registry, heights);
const v = await this.kyveApi.fetchBlocksBatches(this.registry, heights);
// listen for processingblock, if it is

return v;
} else {
throw new Error('No kyve connection');
}
Expand Down
5 changes: 4 additions & 1 deletion packages/node/src/utils/kyve/kyve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ export class KyveApi {
.on('error', reject)
.pipe(writeStream)
.on('finish', resolve);
}).catch((e) => {
throw e; // to ensure an on stack error is thrown
});

await fs.promises.chmod(bundleFilePath, 0o444);
Expand All @@ -281,7 +283,8 @@ export class KyveApi {
}

// todo unsure when to clear the file cache
private async clearFileCache(height: number): Promise<void> {
async clearFileCache(height: number, clearBuffer: number): Promise<void> {
// add listener
const bundleToRemove = this.cachedBundleDetails.filter(
(b) => parseDecimal(b.from_key) > height,
);
Expand Down

0 comments on commit dd70d21

Please sign in to comment.