1
This commit is contained in:
parent
567166587c
commit
0992a71b8f
@ -14,6 +14,7 @@ class BlockChain {
|
|||||||
this.currBlockNumber = 0;
|
this.currBlockNumber = 0;
|
||||||
this.refreshCond = new sync.Cond();
|
this.refreshCond = new sync.Cond();
|
||||||
this.lastRefreshTime = utils.getUtcTime();
|
this.lastRefreshTime = utils.getUtcTime();
|
||||||
|
this.firstBlockNumber = -1;
|
||||||
this.netId = 0;
|
this.netId = 0;
|
||||||
setTimeout(this.refreshBlockNumber.bind(this), 1000 * 0.01);
|
setTimeout(this.refreshBlockNumber.bind(this), 1000 * 0.01);
|
||||||
}
|
}
|
||||||
@ -73,6 +74,33 @@ class BlockChain {
|
|||||||
return this.currBlockNumber;
|
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();
|
module.exports = new BlockChain();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user