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