This commit is contained in:
aozhiwei 2023-07-10 18:12:38 +08:00
parent 7e70934420
commit 1369891b9e
2 changed files with 92 additions and 2 deletions

View File

@ -7,7 +7,7 @@ const serviceFactory = require('../services/factory');
async function activate721Nft(session) { async function activate721Nft(session) {
try { try {
const account = session.request('account'); const account = bcutils.toNormalAddress(session.request('account'));
const netId = session.request('net_id'); const netId = session.request('net_id');
const tokenId = session.request('token_id'); const tokenId = session.request('token_id');
const tokenType = session.request('token_type'); const tokenType = session.request('token_type');
@ -66,7 +66,7 @@ async function activate721Nft(session) {
const nowTime = utils.getUtcTime(); const nowTime = utils.getUtcTime();
const transId = bcutils.genTransId const transId = bcutils.genTransId
( (
bcconst.BC_TRANS_FUNC_ACTIVATE, bcconst.BC_FUNC_COMMON,
nowTime, nowTime,
seqId, seqId,
[ [

View File

@ -0,0 +1,90 @@
const app = require('j7/app');
const utils = require('j7/utils');
const bcutils = require('j7/bcutils');
const bcconst = require('common/bcconst');
const metaFactory = require('../metadata/factory');
async function buy(session) {
try {
const account = bcutils.toNormalAddress(session.request('account', ''));
const netId = session.request('net_id');
const price = session.request('price');
const bc = serviceFactory.create('BlockChain');
{
const ret = await bc.init(netId);
if (!ret) {
session.rspErr(500, 'net_id error');
return;
}
}
{
if (!bc.isValidAddress(account)) {
session.rspErr(500, 'account error');
return;
}
}
const currency = metaFactory.getContractByName('CEG')['address'];
const userAddress = bc.getUserAddress();
const transModel = session.createModel('Transaction');
const usedTokenIdModel = session.createModel('UsedTokenId');
const {err, seqId} = await transModel.add(account, session.requestToJson(), netId);
if (err) {
session.rspErr(500, 'server internal error');
return;
}
const nowTime = utils.getUtcTime();
const transId = bcutils.genTransId
(
bcconst.BC_FUNC_COMMON,
nowTime,
seqId,
[
]
);
await transModel.update
(
seqId,
[
['trans_id', transId]
]);
const nonce = transId;
const orderId = transId;
const signature = await bc.soliditySha3Sign(
account,
orderId,
currency,
price,
nowTime,
nonce
);
const rspParams = [
orderId,
currency,
price,
nowTime,
nonce,
signature
];
utils.arrayToStrings(rspParams);
session.rspData({
'trans_id' : transId,
'order_id': orderId,
'params': rspParams
});
} catch (e) {
session.rspErr(1, 1);
console.log(e);
}
}
function init() {
app.registerHandler('GameItemMall', 'buy', buy);
}
exports.init = init;