This commit is contained in:
aozhiwei 2023-07-13 14:03:28 +08:00
parent d8dfd4dd67
commit cd713ad5fe

View File

@ -6,31 +6,10 @@ const constant = require('common/constant');
const dbpool = require('common/dbpool');
const BaseService = require('./baseservice');
let g_bcevent_conn = null;
let lock_times = 0;
async function getGBcEventConn() {
while (lock_times > 0) {
await utils.sleep(1);
}
if (!g_bcevent_conn) {
++lock_times;
try {
const {err, conn} = await app.getDbConn(constant.BCEVENTDB_NAME);
if (err) {
throw new Error('getGBcEventConn error:' + err);
}
g_bcevent_conn = conn;
} finally {
--lock_times;
}
}
return g_bcevent_conn;
}
class PullBcEvent extends BaseService {
async init(bc, net, event) {
this.conn = await getGBcEventConn();
this.conn = await dbpool.getBcEventConn(app);
this.lastBlockNumber = 0;
this.bc = bc;
this.net = net;