This commit is contained in:
aozhiwei 2023-07-05 19:14:53 +08:00
parent 69717bc402
commit 6ee2aea0eb
3 changed files with 19 additions and 4 deletions

View File

@ -0,0 +1,8 @@
const utils = require('j7/utils');
const basewrap = require('./basewrap');
class Events extends basewrap.BaseWrap {
}
module.exports = Events;

View File

@ -103,6 +103,10 @@ async function init() {
'', '',
'Web3DbSpider' 'Web3DbSpider'
); );
registerMetaClass(configDir + 'events.json',
'net_id',
'Events'
);
load(); load();
{ {
traverseMetaList('BcEventDb', (dbConf, idx) => { traverseMetaList('BcEventDb', (dbConf, idx) => {
@ -122,6 +126,7 @@ async function init() {
'netId': netId, 'netId': netId,
'Web3': utils.readJsonFromFile(netDir + 'web3.json'), 'Web3': utils.readJsonFromFile(netDir + 'web3.json'),
'Contract': utils.readJsonFromFile(netDir + 'contract.json'), 'Contract': utils.readJsonFromFile(netDir + 'contract.json'),
'Events': getMetaByKey('Events', netId)['events']
}; };
netObj.getContractAddressByName = (name) => { netObj.getContractAddressByName = (name) => {
let address = ''; let address = '';

View File

@ -5,6 +5,7 @@ const log = require('j7/log');
const BaseService = require('./baseservice'); const BaseService = require('./baseservice');
const LIMIT_COUNT = 100; const LIMIT_COUNT = 100;
const BCEVENT_TABLE_NAME = 't_blockchain_event';
class PullDbEvent extends BaseService { class PullDbEvent extends BaseService {
@ -13,15 +14,15 @@ class PullDbEvent extends BaseService {
static async staticInit() { static async staticInit() {
const {err, conn} = await app.getDbConn('BcEventDb0'); const {err, conn} = await app.getDbConn('BcEventDb0');
{ {
const {err, maxIdx} = await conn.getMaxIdx(''); const {err, maxIdx} = await conn.getMaxIdx(BCEVENT_TABLE_NAME);
if (err) { if (err) {
throw 'PullDbEvent error:' + err; throw 'PullDbEvent error:' + err;
} }
PullDbEvent.#maxIdx = maxIdx; PullDbEvent.#maxIdx = maxIdx;
} }
async () => { const updateMaxIdxFunc = async () => {
while (true) { while (true) {
const {err, maxIdx} = await conn.getMaxIdx(''); const {err, maxIdx} = await conn.getMaxIdx('BCEVENT_TABLE_NAME');
if (!err) { if (!err) {
PullDbEvent.#maxIdx = maxIdx; PullDbEvent.#maxIdx = maxIdx;
await utils.sleep(500 + utils.randRange(500, 1500)); await utils.sleep(500 + utils.randRange(500, 1500));
@ -29,7 +30,8 @@ class PullDbEvent extends BaseService {
await utils.sleep(5000 + utils.randRange(500, 1500)); await utils.sleep(5000 + utils.randRange(500, 1500));
} }
} }
}(); };
updateMaxIdxFunc();
} }
async init(net, event) { async init(net, event) {