87 lines
1.9 KiB
JavaScript
87 lines
1.9 KiB
JavaScript
const app = require('j7/app');
|
|
const utils = require('j7/utils');
|
|
const bcutils = require('j7/bcutils');
|
|
const log = require('j7/log');
|
|
const BaseService = require('./baseservice');
|
|
|
|
const LIMIT_COUNT = 100;
|
|
|
|
class PullDbEvent extends BaseService {
|
|
|
|
async init(net, event) {
|
|
const {err, conn} = await app.getDbConn('BcEventDb0');
|
|
this.conn = conn;
|
|
this.net = net;
|
|
this.event = event;
|
|
this.lastIdx = BigInt(0);
|
|
this.eventConf = this.event['eventConf'];
|
|
this.progInfo = this.event['progressInfo'];
|
|
await this.start();
|
|
}
|
|
|
|
async start() {
|
|
while (true) {
|
|
await this.pullEvent();
|
|
await utils.sleep(500 + utils.randRange(500, 1500));
|
|
}
|
|
}
|
|
|
|
async pullEvent() {
|
|
const logHead = this.getInstanceName() + ' pullDbEvent: ';
|
|
try {
|
|
const startIdx = this.getStartIdx();
|
|
const endIdx = this.getEndIdx();
|
|
const {err, rows} = await this.conn.execQuery(
|
|
'SELECT * FROM t_blockchain_event WHERE `idx` > ? AND `idx` < ? ' +
|
|
'AND net_id = ? AND event_name = ? AND contract_address = ? ' +
|
|
'LIMIT ' + LIMIT_COUNT,
|
|
[
|
|
startIdx,
|
|
endIdx,
|
|
this.getNetId(),
|
|
this.getEventName(),
|
|
this.getContractAddress()
|
|
]);
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
if (rows.length > 0) {
|
|
|
|
} else {
|
|
this.lastIdx = endIdx;
|
|
}
|
|
} catch (err) {
|
|
log.error(logHead + err);
|
|
await utils.sleep(5000 + utils.randRange(1000, 3000));
|
|
}
|
|
}
|
|
|
|
async getStartIdx() {
|
|
|
|
}
|
|
|
|
async getEndIdx() {
|
|
|
|
}
|
|
|
|
getEventName() {
|
|
return this.eventConf['event_name'];
|
|
}
|
|
|
|
getContractAddress() {
|
|
//return this.bc.getContractAddressByName(this.getContractName());
|
|
}
|
|
|
|
getContractName() {
|
|
return this.eventConf['contract_name'];
|
|
}
|
|
|
|
getInstanceName() {
|
|
const instName = this.getNetId() + '.' + this.getContractName() + '.' + this.getEventName();
|
|
return instName;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = PullDbEvent;
|