This commit is contained in:
aozhiwei 2023-07-15 15:55:25 +08:00
parent 9856247a69
commit 288a2fe503

View File

@ -1,11 +1,20 @@
const log = require('j7/log');
const utils = require('j7/utils');
const bcutils = require('j7/bcutils');
const bcconst = require('common/bcconst');
const constant = require('common/constant');
const BaseEventProcess = require('../common/BaseEventProcess');
class Transfer extends BaseEventProcess {
async start() {
const returnValues = this.getReturnValues();
if (bcutils.isSysAddress(returnValues['from'])) {
await this.mint(returnValues['from'],
returnValues['to'],
returnValues['tokenId']
);
}
await this.add721NftRefresh
(
this.getNetId(),
@ -16,6 +25,38 @@ class Transfer extends BaseEventProcess {
await this.markOk();
}
async mint(from, to, tokenId) {
const logHead = this.genLogHead(' mint ');
const nowTime = utils.getUtcTime();
const fieldList = [
['token_id', tokenId],
['token_type', bcconst.BC_NFT_GENESIS],
['item_id', constant.GENESIS_ITEM_ID],
['owner_address', bcutils.toNormalAddress(to)],
['creator_address', bcutils.toNormalAddress(to)],
['confirm_block_number', this.getBlockNumber()],
['net_id', this.getNetId()],
['contract_address', this.getContractAddress()],
['createtime', nowTime],
['modifytime', nowTime],
];
const {err} = await this.bcNftDbConn(
'upsert',
't_nft',
[
['token_id', tokenId],
['net_id', this.getNetId()],
['contract_address', this.getContractAddress()],
],
[
],
fieldList
);
if (err) {
this.throwError('mintNft ' + err);
}
}
}
module.exports = Transfer;