1
This commit is contained in:
parent
c69add0e46
commit
29c8676ee4
@ -4,8 +4,7 @@ const bcutils = require('j7/bcutils');
|
|||||||
const utils = require('j7/utils');
|
const utils = require('j7/utils');
|
||||||
const j7event = require('j7/event');
|
const j7event = require('j7/event');
|
||||||
const metaFactory = require('../../metadata/factory');
|
const metaFactory = require('../../metadata/factory');
|
||||||
const C = require('../../C');
|
const BaseEventProcess = require('../common/BaseEventProcess');
|
||||||
const gameapi = require('../gameapi');
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
操作成功的事件
|
操作成功的事件
|
||||||
@ -17,16 +16,10 @@ event TokenMinted(
|
|||||||
)
|
)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Activate721Nft {
|
class Activate721Nft extends BaseEventProcess {
|
||||||
|
|
||||||
constructor(proc, conn, eventDb) {
|
|
||||||
this.eventProc = proc;
|
|
||||||
this.conn = conn;
|
|
||||||
this.eventDb = eventDb;
|
|
||||||
}
|
|
||||||
|
|
||||||
async start(event) {
|
async start(event) {
|
||||||
const returnValues = event['returnValues'];
|
const returnValues = this.getReturnValues();
|
||||||
const transId = returnValues['nonce'];
|
const transId = returnValues['nonce'];
|
||||||
const to = returnValues['to'];
|
const to = returnValues['to'];
|
||||||
|
|
||||||
@ -38,7 +31,7 @@ class Activate721Nft {
|
|||||||
|
|
||||||
const params = bcutils.extractParamsFromTransId(transId);
|
const params = bcutils.extractParamsFromTransId(transId);
|
||||||
if (!params || params.length != 3) {
|
if (!params || params.length != 3) {
|
||||||
//this.throwError(instance, 'activate721nft error transId:' + transId);
|
this.throwError(' error transId:' + transId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const itemUniId = params[0];
|
const itemUniId = params[0];
|
||||||
@ -46,7 +39,6 @@ class Activate721Nft {
|
|||||||
|
|
||||||
console.log(params);
|
console.log(params);
|
||||||
await this.mintNft(
|
await this.mintNft(
|
||||||
conn,
|
|
||||||
transId,
|
transId,
|
||||||
bcutils.toNormalAddress(to),
|
bcutils.toNormalAddress(to),
|
||||||
tokenId,
|
tokenId,
|
||||||
@ -55,19 +47,19 @@ class Activate721Nft {
|
|||||||
await gameapi.confirmTransactionDb(transId);
|
await gameapi.confirmTransactionDb(transId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async mintNft(conn, transId, owner, tokenId, itemUniId, itemId) {
|
async mintNft(transId, owner, tokenId, itemUniId, itemId) {
|
||||||
const itemMeta = metaFactory.getMetaByKey('Item', itemId);
|
const itemMeta = metaFactory.getMetaByKey('Item', itemId);
|
||||||
if (!itemMeta) {
|
if (!itemMeta) {
|
||||||
this.throwError(instance, 'activate721nft error transId:1');
|
this.throwError('activate721nft error transId:1');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const tokenType = itemMeta.getNftType();
|
const tokenType = itemMeta.getNftType();
|
||||||
if (tokenType == bcutils.NONE_TYPE) {
|
if (tokenType == bcutils.NONE_TYPE) {
|
||||||
this.throwError(instance, 'activate721nft error transId:2');
|
this.throwError('activate721nft error transId:2');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.updateGameDbInfo(instance, conn, transId, itemUniId, itemId, tokenId, tokenType);
|
await this.updateGameDbInfo(instance, conn, transId, itemUniId, itemId, tokenId, tokenType);
|
||||||
const {err, row} = await conn.ormSelectOne(
|
const {err, row} = await this.conn.ormSelectOne(
|
||||||
't_nft',
|
't_nft',
|
||||||
[
|
[
|
||||||
['token_id', tokenId],
|
['token_id', tokenId],
|
||||||
@ -90,7 +82,7 @@ class Activate721Nft {
|
|||||||
['createtime', nowTime],
|
['createtime', nowTime],
|
||||||
['modifytime', nowTime],
|
['modifytime', nowTime],
|
||||||
];
|
];
|
||||||
const {err} = await conn.insert(
|
const {err} = await this.conn.insert(
|
||||||
't_nft',
|
't_nft',
|
||||||
fieldList
|
fieldList
|
||||||
);
|
);
|
||||||
@ -140,7 +132,7 @@ class Activate721Nft {
|
|||||||
this.throwError(instance, 'error token_type:' + tokenType);
|
this.throwError(instance, 'error token_type:' + tokenType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await conn.update(
|
await this.conn.update(
|
||||||
tblName,
|
tblName,
|
||||||
[
|
[
|
||||||
['idx', itemUniId],
|
['idx', itemUniId],
|
||||||
@ -153,7 +145,7 @@ class Activate721Nft {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
conn.release();
|
this.conn.release();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.throwError(instance, 'updateGameDbInfo err:' + e);
|
this.throwError(instance, 'updateGameDbInfo err:' + e);
|
||||||
@ -161,23 +153,6 @@ class Activate721Nft {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
genLogHead() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
getBlockNumber() {
|
|
||||||
return this.eventDb['block_number'];
|
|
||||||
}
|
|
||||||
|
|
||||||
getReturnValues() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
throwError(instance, err) {
|
|
||||||
const errMsg = 'processActivate721NftEvent:' + utils.jsonEncode(instance) + ' err:' + err;
|
|
||||||
throw errMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Activate721Nft;
|
module.exports = Activate721Nft;
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
const log = require('j7/log');
|
||||||
|
const app = require('j7/app');
|
||||||
|
const bcutils = require('j7/bcutils');
|
||||||
|
const utils = require('j7/utils');
|
||||||
|
const j7event = require('j7/event');
|
||||||
|
const metaFactory = require('../../metadata/factory');
|
||||||
|
|
||||||
|
class BaseEventProcess {
|
||||||
|
|
||||||
|
constructor(proc, conn, eventDb) {
|
||||||
|
this.eventProc = proc;
|
||||||
|
this.conn = conn;
|
||||||
|
this.eventDb = eventDb;
|
||||||
|
this.returnValues = utils.jsonDecode(this.getEventDb());
|
||||||
|
}
|
||||||
|
|
||||||
|
genLogHead(msg) {
|
||||||
|
return this.eventProc.genLogHead(' activate721nft ' + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
getEventDb() {
|
||||||
|
return this.eventDb;
|
||||||
|
}
|
||||||
|
|
||||||
|
getBlockNumber() {
|
||||||
|
return this.eventDb['block_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
getReturnValues() {
|
||||||
|
return this.returnValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
throwError(err) {
|
||||||
|
const errMsg = this.genLogHead(err);
|
||||||
|
throw errMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = BaseEventProcess;
|
Loading…
x
Reference in New Issue
Block a user