1
This commit is contained in:
parent
ce6996f218
commit
4cc702b61e
@ -5,16 +5,14 @@ const bcconst = require('common/bcconst');
|
||||
const metaFactory = require('../metadata/factory');
|
||||
const serviceFactory = require('../services/factory');
|
||||
|
||||
async function nftLock(session) {
|
||||
async function mintHero(session) {
|
||||
try {
|
||||
const account = bcutils.toNormalAddress(session.request('account'));
|
||||
const accountAddress = bcutils.toNormalAddress(session.request('account_address'));
|
||||
const netId = session.request('net_id');
|
||||
const tokenId = session.request('token_id');
|
||||
const tokenType = session.request('token_type');
|
||||
const itemUniId = session.request('item_uniid');
|
||||
const itemId = session.request('item_id');
|
||||
const tokenIds = session.request('token_ids').split(',');
|
||||
const nftAddress = bcutils.toNormalAddress(session.request('nft_address'));
|
||||
const toAddress = bcutils.toNormalAddress(session.request('to_address'));
|
||||
const bc = serviceFactory.create('BlockChain');
|
||||
const isMint = session.request('is_mint') ? true : false;
|
||||
{
|
||||
const ret = await bc.init(netId);
|
||||
if (!ret) {
|
||||
@ -23,48 +21,38 @@ async function nftLock(session) {
|
||||
}
|
||||
}
|
||||
{
|
||||
if (!bc.isValidAddress(account)) {
|
||||
session.rspErr(500, 'account error');
|
||||
if (!bc.isValidAddress(accountAddress)) {
|
||||
session.rspErr(500, 'accountAddress error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (!bc.isValidAddress(toAddress)) {
|
||||
session.rspErr(500, 'toAddress error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const nftAddress = bc.getNftAddress(tokenType);
|
||||
const userAddress = bc.getUserAddress();
|
||||
const thisContractAddress = bc.getContractAddressByName('NFTLock');
|
||||
const instance = bc.getInstanceByName('NFTLock');
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const usedTokenIdModel = session.createModel('UsedTokenId');
|
||||
|
||||
{
|
||||
const itemMeta = metaFactory.getMetaByKey('Item', itemId);
|
||||
if (!itemMeta) {
|
||||
session.rspErr(101, 'item_id param error');
|
||||
return;
|
||||
}
|
||||
if (itemMeta.getNftType() != tokenType) {
|
||||
session.rspErr(101, 'item_id param error');
|
||||
return;
|
||||
}
|
||||
if (!(itemMeta.getNftType() == bcconst.BC_NFT_HERO ||
|
||||
itemMeta.getNftType() == bcconst.BC_NFT_GOLD_BULLION)) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
if (itemMeta.getNftType() == bcconst.BC_NFT_GOLD_BULLION && !isMint) {
|
||||
session.rspErr(101, 'gold bullion only mint');
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
const heroAddress = bcutils.toNormalAddress(bc.getNftAddress(bcconst.BC_NFT_HERO));
|
||||
const normalHeroAddress = bcutils.toNormalAddress(bc.getNftAddress(bcconst.BC_NFT_NORMAL_HERO));
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error2');
|
||||
session.rspErr(101, 'nft_address param error2');
|
||||
return;
|
||||
}
|
||||
if (!(toAddress == heroAddress || toAddress == normalHeroAddress)) {
|
||||
session.rspErr(500, 'nft_address is not hero or normalhero address');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson(), netId);
|
||||
const {err, seqId} = await transModel.add(accountAddress, session.requestToJson(), netId);
|
||||
if (err) {
|
||||
console.log(err);
|
||||
session.rspErr(500, 'server internal error');
|
||||
@ -78,8 +66,6 @@ async function nftLock(session) {
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
itemUniId,
|
||||
itemId
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
@ -89,25 +75,22 @@ async function nftLock(session) {
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const nonce = transId;
|
||||
const nftList = [
|
||||
[
|
||||
tokenId,
|
||||
account,
|
||||
isMint
|
||||
]
|
||||
];
|
||||
const nftList = [];
|
||||
tokenids.forEach(ele => {
|
||||
nftList.push([
|
||||
ele,
|
||||
toAddress,
|
||||
false
|
||||
]);
|
||||
});
|
||||
const nftListArr = [];
|
||||
nftList.forEach((item) => {
|
||||
nftListArr.push(item[0].toString());
|
||||
nftListArr.push(account);
|
||||
if (isMint) {
|
||||
nftListArr.push('0x01');
|
||||
} else {
|
||||
nftListArr.push(item[1].toString());
|
||||
nftListArr.push('0x00');
|
||||
}
|
||||
});
|
||||
const signature = await bc.soliditySha3Sign(
|
||||
account,
|
||||
accountAddress,
|
||||
nftAddress,
|
||||
thisContractAddress,
|
||||
netId,
|
||||
@ -116,7 +99,7 @@ async function nftLock(session) {
|
||||
...nftListArr,
|
||||
);
|
||||
console.log(
|
||||
account,
|
||||
accountAddress,
|
||||
nftAddress,
|
||||
thisContractAddress,
|
||||
netId,
|
||||
@ -149,7 +132,7 @@ async function nftLock(session) {
|
||||
}
|
||||
|
||||
function init() {
|
||||
app.registerHandler('BcService', 'nftLock', nftLock);
|
||||
app.registerHandler('BcService', 'mintHero', mintHero);
|
||||
}
|
||||
|
||||
exports.init = init;
|
||||
|
Loading…
x
Reference in New Issue
Block a user