From 628e43225b5a4a6b3e80abbda27a72d3bf20d12b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 3 Jul 2023 18:02:08 +0800 Subject: [PATCH] 1 --- server/web3bcspider/services/pull_bcevent.js | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/server/web3bcspider/services/pull_bcevent.js b/server/web3bcspider/services/pull_bcevent.js index b13b223..a35f26e 100644 --- a/server/web3bcspider/services/pull_bcevent.js +++ b/server/web3bcspider/services/pull_bcevent.js @@ -8,13 +8,13 @@ class PullBcEvent extends BaseService { async init(bc, net, event) { this.conn = conn; - this.instance = instance; this.cb = cb; this.lastBlockNumber = 0; this.bc = bc; this.net = net; this.event = event; this.eventConf = this.event['eventConf']; + this.progInfo = this.event['progressInfo']; await this.start(); } @@ -34,23 +34,16 @@ class PullBcEvent extends BaseService { const toBlock = await this.calcToBlock(fromBlock); if (toBlock > fromBlock) { const events = await bc[this.getInstanceName()].getPastEvents( - this.instance['eventName'], + this.getEventName(), { fromBlock: fromBlock, toBlock: toBlock, }, ); - this.instance['fromBlock'] = fromBlock; - this.instance['toBlock'] = toBlock; - this.instance['currBlock'] = this.bc.getCurrBlockNumber(); - this.instance['eventCount'] += events.length; - if (events.length > 0) { - console.log(events); - } - await this.processEvents(events, toBlock); + await this.processEvents(events, fromBlock, toBlock); await this.saveLastBlockNumber(toBlock); } - ++this.instance['pullCount']; + ++this.progInfo['pullCount']; return; } catch (err) { log.error(logClass + err); @@ -66,7 +59,15 @@ class PullBcEvent extends BaseService { return instName; } - async processEvents(events, toBlock) { + async processEvents(events, fromBlock, toBlock) { + this.progInfo['fromBlock'] = fromBlock; + this.progInfo['toBlock'] = toBlock; + this.progInfo['currBlock'] = this.bc.getCurrBlockNumber(); + this.progInfo['eventCount'] += events.length; + if (events.length <= 0) { + return; + } + console.log(events); for (let i in events) { while (true) { try { @@ -168,8 +169,8 @@ class PullBcEvent extends BaseService { [ ], [ - ['instance_name', this.instance['name']], - ['event_name', this.instance['eventName']], + ['instance_name', this.getContractName()], + ['event_name', this.getEventName()], ['txhash', event['transactionHash']], ['log_index', event['logIndex']], ['block_number', event['blockNumber']],