This commit is contained in:
aozhiwei 2023-07-06 13:16:40 +08:00
parent 818935d2cb
commit 46c85f4ce0

View File

@ -61,12 +61,28 @@ class DbEventProcess extends BaseService {
const logHead = this.getInstanceName() + ' pullEvent: ';
}
getStartIdx() {
return this.lastIdx;
}
getEndIdx() {
if (utils.hasKey(DbEventProcess.#tableMaxIdxHash, this.getTableName())) {
return DbEventProcess.#tableMaxIdxHash[this.getTableName()];
} else {
return BigInt(0);
}
}
getNetId() {
return this.net['net_id'];
}
getEventName() {
return this.eventConf['event_name'];
}
getContractAddress() {
//return this.bc.getContractAddressByName(this.getContractName());
return this.contractAddress;
}
getContractName() {
@ -78,6 +94,65 @@ class DbEventProcess extends BaseService {
return instName;
}
getTableName() {
return this.eventConf['table_name'];
}
async getLastIdx() {
const logHead = this.getInstanceName() + ' getLastIdx: ';
while (true) {
const {err, row} = await this.conn.ormSelectOne(
't_dbprocess_last_idx',
[
['net_id', this.getNetId()],
['contract_address', this.getContractAddress()],
['event_name', this.getEventName()],
]
);
if (err) {
log.error(logHead + err);
await utils.sleep(5000 + utils.randRange(500, 1500));
continue;
}
if (row) {
return BigInt(row['last_idx']);
}
}
return BigInt(0);
}
async saveLastIdx(lastIdx) {
const logHead = this.getInstanceName() + ' saveLastIdx: ';
while (true) {
const {err} = await this.conn.upsert(
't_dbprocess_last_idx',
[
['net_id', this.getNetId()],
['contract_address', this.getContractAddress()],
['event_name', this.getEventName()],
],
[
['last_idx', lastIdx.toString()],
['modifytime', utils.getUtcTime()],
],
[
['net_id', this.getNetId()],
['contract_address', this.getContractAddress()],
['event_name', this.getEventName()],
['contract_name', this.getContractName()],
['last_idx', lastIdx],
['createtime', utils.getUtcTime()],
['modifytime', utils.getUtcTime()],
]
);
if (!err) {
break;
}
log.error(logHead + err);
await utils.sleep(5000 + utils.randRange(500, 1500));
}
}
}
module.exports = DbEventProcess;