1
This commit is contained in:
parent
849259aeef
commit
4b8f73485c
@ -4,6 +4,7 @@ const db = require("./db");
|
||||
const dbhelper = require("./dbhelper");
|
||||
const log = require("./log");
|
||||
const bc = require('./blockchain');
|
||||
const metamgr = require('./metamgr');
|
||||
const C = require('./C');
|
||||
|
||||
class BoxOrder {
|
||||
@ -51,6 +52,7 @@ class BoxOrder {
|
||||
JSON.stringify(this.getOrderDb()),
|
||||
)
|
||||
);
|
||||
await this.bcMintHero();
|
||||
await this.updateDb(logClass,
|
||||
[
|
||||
['done', 1]
|
||||
@ -111,6 +113,7 @@ class BoxOrder {
|
||||
const err = await this.updateDb(
|
||||
logClass,
|
||||
[
|
||||
['state', C.ORDER_STATE_PAID],
|
||||
['bc_synced', 1],
|
||||
['bc_sync_count', 1],
|
||||
['bc_sync_time', nowTime],
|
||||
@ -147,10 +150,7 @@ class BoxOrder {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const err = await this.updateDb(logClass,
|
||||
[
|
||||
['state', C.ORDER_STATE_PAID]
|
||||
]);
|
||||
const err = await this.bcMintHero();
|
||||
if (!err) {
|
||||
break;
|
||||
}
|
||||
@ -171,6 +171,54 @@ class BoxOrder {
|
||||
utils.emitEvent(C.REMOVE_PENDING_ORDER_EVENT, this.getOrderId());
|
||||
}
|
||||
|
||||
async bcMintHero() {
|
||||
const logClass = 'bcMintHero';
|
||||
const userAddress = metamgr.getUserAddress();
|
||||
const tokenId = this.getOrderId();
|
||||
const result = await bc.factoryInstance.methods.mintHeroTo(
|
||||
userAddress,
|
||||
tokenId).send({ gas: 1000000 });
|
||||
{
|
||||
const err = await this.updateDb(
|
||||
logClass,
|
||||
[
|
||||
['token_id', tokenId]
|
||||
]
|
||||
);
|
||||
}
|
||||
{
|
||||
const nowTime = utils.getUtcTime();
|
||||
const fieldList = [
|
||||
['token_id', tokenId],
|
||||
['item_id', this.orderDb['item_id']],
|
||||
['owner_id', ''],
|
||||
['owner_address', this.orderDb['buyer_address']],
|
||||
['owner_name', ''],
|
||||
['createtime', nowTime],
|
||||
['modifytime', nowTime],
|
||||
];
|
||||
const err = await dbhelper.insert(
|
||||
't_nft',
|
||||
fieldList);
|
||||
if (err) {
|
||||
log.error(util.format('%s insert nft table orderDb:%s fieldList:%s err:%s',
|
||||
logClass,
|
||||
JSON.stringify(this.orderDb),
|
||||
JSON.stringify(fieldList),
|
||||
err
|
||||
)
|
||||
);
|
||||
} else {
|
||||
log.info(util.format('%s insert nft table orderDb:%s',
|
||||
logClass,
|
||||
JSON.stringify(this.orderDb),
|
||||
JSON.stringify(fieldList)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async updateDb(logClass, fieldList) {
|
||||
const err = await dbhelper.update(
|
||||
't_box_order',
|
||||
|
@ -88,6 +88,11 @@ function getContractByName(name) {
|
||||
return getMetaByKey(MT_CONTRACT, name);
|
||||
}
|
||||
|
||||
function getUserAddress() {
|
||||
const userAddress = getServerConf()['user_address'];
|
||||
return userAddress;
|
||||
}
|
||||
|
||||
exports.init = init;
|
||||
exports.getMetaByKey = getMetaByKey;
|
||||
exports.getMetaList = getMetaList;
|
||||
@ -95,3 +100,4 @@ exports.getServerConf = getServerConf;
|
||||
exports.getMysqlConf = getMysqlConf;
|
||||
exports.getContracts = getContracts;
|
||||
exports.getContractByName = getContractByName;
|
||||
exports.getUserAddress = getUserAddress;
|
||||
|
Loading…
x
Reference in New Issue
Block a user