Skip to content

Commit

Permalink
fix: allow block height only if database is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
metmirr committed Jul 17, 2020
1 parent 3c26d43 commit 19b50a0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions substrate-query-framework/index-builder/src/IndexBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ export default class IndexBuilder {

const lastProcessedEvent = await getRepository(SavedEntityEvent).findOne({ where: { id: 1 } });

// Priority is belongs to `startAt` parameter, if parameter is provided then ignore the saved event start
// block producer from `startAt` block number.
if (!atBlock && lastProcessedEvent) {
if (atBlock && lastProcessedEvent) {
throw new Error(
`Existing processed history detected on the database!
Last processed block is ${lastProcessedEvent.blockNumber.toString()}`
);
}

if (lastProcessedEvent) {
this.lastProcessedEvent = lastProcessedEvent;
await this._producer.start(this.lastProcessedEvent.blockNumber, this.lastProcessedEvent.index);
} else {
Expand Down

0 comments on commit 19b50a0

Please sign in to comment.