This commit is contained in:
aozhiwei 2023-07-03 18:02:08 +08:00
parent b6f287e83b
commit 628e43225b

View File

@ -8,13 +8,13 @@ class PullBcEvent extends BaseService {
async init(bc, net, event) { async init(bc, net, event) {
this.conn = conn; this.conn = conn;
this.instance = instance;
this.cb = cb; this.cb = cb;
this.lastBlockNumber = 0; this.lastBlockNumber = 0;
this.bc = bc; this.bc = bc;
this.net = net; this.net = net;
this.event = event; this.event = event;
this.eventConf = this.event['eventConf']; this.eventConf = this.event['eventConf'];
this.progInfo = this.event['progressInfo'];
await this.start(); await this.start();
} }
@ -34,23 +34,16 @@ class PullBcEvent extends BaseService {
const toBlock = await this.calcToBlock(fromBlock); const toBlock = await this.calcToBlock(fromBlock);
if (toBlock > fromBlock) { if (toBlock > fromBlock) {
const events = await bc[this.getInstanceName()].getPastEvents( const events = await bc[this.getInstanceName()].getPastEvents(
this.instance['eventName'], this.getEventName(),
{ {
fromBlock: fromBlock, fromBlock: fromBlock,
toBlock: toBlock, toBlock: toBlock,
}, },
); );
this.instance['fromBlock'] = fromBlock; await this.processEvents(events, fromBlock, toBlock);
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.saveLastBlockNumber(toBlock); await this.saveLastBlockNumber(toBlock);
} }
++this.instance['pullCount']; ++this.progInfo['pullCount'];
return; return;
} catch (err) { } catch (err) {
log.error(logClass + err); log.error(logClass + err);
@ -66,7 +59,15 @@ class PullBcEvent extends BaseService {
return instName; 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) { for (let i in events) {
while (true) { while (true) {
try { try {
@ -168,8 +169,8 @@ class PullBcEvent extends BaseService {
[ [
], ],
[ [
['instance_name', this.instance['name']], ['instance_name', this.getContractName()],
['event_name', this.instance['eventName']], ['event_name', this.getEventName()],
['txhash', event['transactionHash']], ['txhash', event['transactionHash']],
['log_index', event['logIndex']], ['log_index', event['logIndex']],
['block_number', event['blockNumber']], ['block_number', event['blockNumber']],