This commit is contained in:
aozhiwei 2022-04-21 14:58:30 +08:00
parent 567166587c
commit 0992a71b8f

View File

@ -14,6 +14,7 @@ class BlockChain {
this.currBlockNumber = 0;
this.refreshCond = new sync.Cond();
this.lastRefreshTime = utils.getUtcTime();
this.firstBlockNumber = -1;
this.netId = 0;
setTimeout(this.refreshBlockNumber.bind(this), 1000 * 0.01);
}
@ -73,6 +74,33 @@ class BlockChain {
return this.currBlockNumber;
}
async getFirstBlockNumber() {
while (this.firstBlockNumber < 0) {
const {err, conn} = await app.getDbConn('MarketDb0');
if (err) {
await utils.sleep(1000 + utils.randRange(500, 1500));
continue;
}
try {
const {err, row} = await conn.ormSelectOne(
't_parameter',
[
['name', 'first_block_number']
]
);
if (!err && row) {
this.firstBlockNumber = Number(row['value']);
}
} catch (e) {
} finally {
conn.release();
}
await utils.sleep(5000 + utils.randRange(500, 1500));
}
return this.firstBlockNumber;
}
}
module.exports = new BlockChain();