diff --git a/server/web3bcspider/blockchain.js b/server/web3bcspider/blockchain.js index ca6ba05..4dca630 100644 --- a/server/web3bcspider/blockchain.js +++ b/server/web3bcspider/blockchain.js @@ -12,6 +12,7 @@ const metaFactory = require('./metadata/factory'); class BlockChain { constructor(netId) { + this.actived = false; this.netId = netId; this.lastQueryTime = utils.getUtcTime(); this.queryLockTimes = 0; @@ -53,6 +54,18 @@ class BlockChain { this.netId, chainId )); + { + await this.mustBeActive(); + const netId = this.getNetId(); + console.log('net_id:', netId, ' blockNumber:', this.getCurrBlockNumber(), + ' handleRevert:', this.web3.eth.handleRevert, ' isOnlineEnv:', utils.isOnlineEnv()); + } + } + + async mustBeActive() { + while (!this.actived) { + await utils.sleep(1000); + } } getNetId() { @@ -99,17 +112,13 @@ class BlockChain { } async refreshBlockNumber() { - const logHead = 'refreshBlockNumber'; + const logHead = ' refreshBlockNumber:'; while (true) { try { this.currBlockNumber = await this.web3.eth.getBlockNumber(); this.actived = true; this.lastRefreshTime = utils.getUtcTime(); console.log('currBlockNumber', this.currBlockNumber); - if (!this.initedBlockNumber) { - this.initedBlockNumber = true; - this.initBlockNumber = this.currBlockNumber; - } } catch (e) { this.actived = false; log.warning(util.format('%s err:%s',