From 46c85f4ce097724d8147a76c5986824310ffcc5b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 6 Jul 2023 13:16:40 +0800 Subject: [PATCH] 1 --- .../web3dbspider/services/dbevent_process.js | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/server/web3dbspider/services/dbevent_process.js b/server/web3dbspider/services/dbevent_process.js index 7012874..55aec1b 100644 --- a/server/web3dbspider/services/dbevent_process.js +++ b/server/web3dbspider/services/dbevent_process.js @@ -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;