This commit is contained in:
aozhiwei 2023-07-05 15:46:47 +08:00
parent 70e0407f22
commit d630f75e32
2 changed files with 39 additions and 2 deletions

View File

@ -41,7 +41,8 @@ CREATE TABLE `t_blockchain_event` (
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `unikey` (`txhash`, `hash_code`, `log_index`, `net_id`, `event_name`, `contract_address`)
UNIQUE KEY `unikey` (`txhash`, `hash_code`, `log_index`, `net_id`, `event_name`, `contract_address`),
KEY `net_id_event_name_contract_address` (`net_id`, `event_name`, `contract_address`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -4,6 +4,8 @@ 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) {
@ -25,7 +27,41 @@ class PullDbEvent extends BaseService {
}
async pullEvent() {
const logHead = this.getInstanceName() + ' 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() {