Fix for Bisq blocks data watchers stopps working randomly. Restaring watcher when block height has diverged.

This commit is contained in:
softsimon
2020-09-27 17:21:18 +07:00
parent f4a78a0e78
commit 3450de774f
3 changed files with 14 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ class Blocks {
private blocks: Block[] = [];
private currentBlockHeight = 0;
private lastDifficultyAdjustmentTime = 0;
private newBlockCallback: ((block: Block, txIds: string[], transactions: TransactionExtended[]) => void) | undefined;
private newBlockCallbacks: ((block: Block, txIds: string[], transactions: TransactionExtended[]) => void)[] = [];
constructor() { }
@@ -21,7 +21,7 @@ class Blocks {
}
public setNewBlockCallback(fn: (block: Block, txIds: string[], transactions: TransactionExtended[]) => void) {
this.newBlockCallback = fn;
this.newBlockCallbacks.push(fn);
}
public async updateBlocks() {
@@ -95,8 +95,8 @@ class Blocks {
this.blocks.shift();
}
if (this.newBlockCallback) {
this.newBlockCallback(block, txIds, transactions);
if (this.newBlockCallbacks.length) {
this.newBlockCallbacks.forEach((cb) => cb(block, txIds, transactions));
}
}