This commit is contained in:
aozhiwei 2023-07-11 17:01:07 +08:00
parent d82546500b
commit f078aaaa25
2 changed files with 42 additions and 57 deletions

View File

@ -41,4 +41,25 @@ function getItemMetaNftType(itemMeta) {
return bcconst.BC_NFT_NONE;
}
function getNftTableName(tokenType) {
switch (Number(tokenType)) {
case bcconst.BC_NFT_HERO:
{
return 't_hero';
}
break;
case bcconst.BC_NFT_CHIP:
{
return 't_chip';
}
break;
default:
{
return '';
}
break;
}
}
exports.getItemMetaNftType = getItemMetaNftType;
exports.getNftTableName = getNftTableName;

View File

@ -5,6 +5,7 @@ const utils = require('j7/utils');
const j7event = require('j7/event');
const constant = require('common/constant');
const bcconst = require('common/bcconst');
const bchelper = require('common/bchelper');
const metaFactory = require('../../../metadata/factory');
const BaseEventProcess = require('../common/BaseEventProcess');
@ -60,7 +61,7 @@ class Activate721Nft extends BaseEventProcess {
return;
}
await this.updateGameDbInfo(transId, itemUniId, itemId, tokenId, tokenType);
const {err, row} = await this.bcNftConn(
const {err} = await this.bcNftConn(
'ormSelectOne',
't_nft',
[
@ -94,67 +95,30 @@ class Activate721Nft extends BaseEventProcess {
log.error('processEvent:' + err);
throw 'processEvent:' + err;
}
try {
j7event.emitEvent(C.CREATE_EXEC_CONFIRM_OWNER_EVENT, tokenId);
} catch (err) {
log.warning('processEvent:' + err);
}
}
}
async updateGameDbInfo(transId, itemUniId, itemId, tokenId, tokenType) {
const {err, conn} = await app.getDbConn(constant.GAMEDB_NAME);
if (err) {
this.throwError('gamedb connection err:' + err);
return;
const tblName = bchelper.getNftTableName(tokenType);
if (!tblName) {
this.throwError('error token_type:' + tokenType);
return;
}
const gameDbConn = conn;
try {
try {
let tblName = '';
switch (tokenType) {
case bcconst.BC_NFT_HERO:
{
tblName = 't_hero';
}
break;
case bcconst.BC_NFT_EQUIP:
{
tblName = 't_gun';
}
break;
case bcconst.BC_NFT_CHIP:
{
tblName = 't_chip';
}
break;
default:
{
}
break;
}
if (!tblName) {
this.throwError('error token_type:' + tokenType);
return;
}
await gameDbConn.update(
tblName,
[
['idx', itemUniId],
],
[
['token_id', tokenId],
['!account_id', () => {
return 'null';
}],
]
);
} finally {
gameDbConn.release();
}
} catch (e) {
this.throwError('updateGameDbInfo err:' + e);
return;
const {err} = await this.gameDbConn(
'update',
tblName,
[
['idx', itemUniId],
],
[
['token_id', tokenId],
['!account_id', () => {
return 'null';
}],
]
);
if (err) {
this.throwError('updateGameDbInfo transId:' + transId);
}
}