1
This commit is contained in:
parent
b6f287e83b
commit
628e43225b
@ -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']],
|
||||
|
Loading…
x
Reference in New Issue
Block a user