diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts index 454424f..ddf7f0f 100644 --- a/src/service/BlockService.ts +++ b/src/service/BlockService.ts @@ -1,6 +1,12 @@ import { Block } from 'crust-sdk' import Endpoint from 'crust-sdk/api/common/Endpoint'; +class NewSystemHealth { + peers: number + isSyncing: boolean + shouldHavePeers: boolean +} + export default class BlockService { block: Block @@ -13,12 +19,31 @@ export default class BlockService { return await this.block.head() } + sleep = (time : number) => { + return new Promise((resolve) => setTimeout(resolve, time)); + } + blockHash = async (blockNumber: number) => { return await this.block.blockHash(blockNumber) } systemHealth = async () => { - return await this.block.health() + let sh = await this.block.health() + let nsh = new NewSystemHealth + nsh.isSyncing = sh.isSyncing.isTrue + nsh.peers = sh.peers.toNumber() + nsh.shouldHavePeers = sh.shouldHavePeers.isTrue + + if (!nsh.isSyncing) { + let h1 = await this.head() + await this.sleep(3000) + let h2 = await this.head() + if (h1.number.toNumber() + 1 < h2.number.toNumber()) { + nsh.isSyncing = true + } + } + + return nsh } } \ No newline at end of file