1
This commit is contained in:
parent
9eb0af5e0f
commit
42d7e52899
@ -1,108 +0,0 @@
|
||||
const ethUtil = require('ethereumjs-util');
|
||||
const sigUtil = require('@metamask/eth-sig-util');
|
||||
|
||||
const app = require('j7/app');
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const bc = require('../blockchain');
|
||||
const metaFactory = require('../metadata/factory');
|
||||
|
||||
async function activate721Nft(session) {
|
||||
try {
|
||||
const accountId = session.request('account_id');
|
||||
const account = session.request('account');
|
||||
const sessionId = session.request('session_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 nftAddress = bc.getNftAddress(tokenType);
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
|
||||
{
|
||||
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() == bcutils.HERO_TYPE ||
|
||||
itemMeta.getNftType() == bcutils.EQUIP_TYPE ||
|
||||
itemMeta.getNftType() == bcutils.CHIP_TYPE)) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson());
|
||||
if (err) {
|
||||
session.rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
|
||||
const nowTime = utils.getUtcTime();
|
||||
const transId = bcutils.genTransId
|
||||
(
|
||||
bcutils.BC_TRANS_FUNC_ACTIVATE,
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
itemUniId,
|
||||
itemId
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
(
|
||||
seqId,
|
||||
[
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const nonce = transId;
|
||||
const tokenIds = [tokenId];
|
||||
utils.arrayToStrings(tokenIds);
|
||||
let signStr = await bc.web3.utils.soliditySha3
|
||||
(
|
||||
account,
|
||||
nftAddress,
|
||||
nowTime,
|
||||
nonce,
|
||||
...tokenIds
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
|
||||
const rspParams = [
|
||||
nftAddress,
|
||||
utils.jsonEncode(tokenIds),
|
||||
nowTime,
|
||||
nonce,
|
||||
signature
|
||||
];
|
||||
utils.arrayToStrings(rspParams);
|
||||
|
||||
session.rspData({
|
||||
'trans_id' : transId,
|
||||
'params': rspParams
|
||||
});
|
||||
} catch (e) {
|
||||
session.rspErr(1, 1);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
app.registerHandler('BcService', 'activate721Nft', activate721Nft);
|
||||
}
|
||||
|
||||
exports.init = init;
|
@ -1,156 +0,0 @@
|
||||
const ethUtil = require('ethereumjs-util');
|
||||
const sigUtil = require('@metamask/eth-sig-util');
|
||||
|
||||
const app = require('j7/app');
|
||||
const utils = require('j7/utils');
|
||||
const bc = require('../blockchain');
|
||||
const metaFactory = require('../metadata/factory');
|
||||
|
||||
async function authVerifySignature(session) {
|
||||
try {
|
||||
//const netId = await bc.getNetId();
|
||||
const msgParams = {
|
||||
types: {
|
||||
EIP712Domain: [
|
||||
{ name: 'name', type: 'string' },
|
||||
{ name: 'version', type: 'string' },
|
||||
],
|
||||
set: [
|
||||
{ name: 'tips', type: 'string' },
|
||||
{ name: 'nonce', type: 'string' },
|
||||
]
|
||||
},
|
||||
primaryType: 'set',
|
||||
domain: {
|
||||
name: 'Auth',
|
||||
version: '1',
|
||||
},
|
||||
message: {
|
||||
tips: session.request('tips'),
|
||||
nonce: session.request('nonce')
|
||||
}
|
||||
};
|
||||
const recovered = sigUtil.recoverTypedSignature(
|
||||
{data:
|
||||
msgParams,
|
||||
signature: session.request('signature'),
|
||||
version: 'V4'});
|
||||
session.rspData(
|
||||
{
|
||||
'recovered': recovered
|
||||
});
|
||||
} catch (err) {
|
||||
session.rspErr(1, err);
|
||||
}
|
||||
}
|
||||
|
||||
async function buyBoxVerifySignature(session) {
|
||||
try {
|
||||
const netId = await bc.getNetId();
|
||||
const msgParams = {
|
||||
types: {
|
||||
EIP712Domain: [
|
||||
{ name: 'name', type: 'string' },
|
||||
{ name: 'version', type: 'string' },
|
||||
{ name: 'chainId', type: 'uint256' },
|
||||
{ name: 'verifyingContract', type: 'address' }
|
||||
],
|
||||
set: [
|
||||
{ name: 'item', type: 'uint256' },
|
||||
{ name: 'token', type: 'address' },
|
||||
{ name: 'price', type: 'uint256' },
|
||||
{ name: 'salt', type: 'uint256' }
|
||||
]
|
||||
},
|
||||
primaryType: 'set',
|
||||
domain: {
|
||||
name: 'BEBoxMall',
|
||||
version: '1',
|
||||
chainId: netId,
|
||||
verifyingContract: metaFactory.getMetaByKey('Contract', 'mall')['address'],
|
||||
},
|
||||
message: {
|
||||
item: session.request('type'),
|
||||
token: session.request('paymentTokenAddress'),
|
||||
price: session.request('price'),
|
||||
salt: session.request('nonce')
|
||||
}
|
||||
};
|
||||
const recovered = sigUtil.recoverTypedSignature(
|
||||
{data: msgParams,
|
||||
signature: session.request('signature'),
|
||||
version: 'V4'});
|
||||
console.log(recovered);
|
||||
session.rspData(
|
||||
{
|
||||
'recovered': recovered
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
session.rspErr(1, err);
|
||||
}
|
||||
}
|
||||
|
||||
async function openBoxSignature(session) {
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
const boxId = session.request('box_token_id');
|
||||
const tokenIds = [];
|
||||
tokenIds.push(session.request('token_id1'));
|
||||
tokenIds.push(session.request('token_id2'));
|
||||
tokenIds.push(session.request('token_id3'));
|
||||
|
||||
let nonce = utils.getUtcTime();
|
||||
let signStr = bc.web3.utils.soliditySha3(
|
||||
boxId,
|
||||
tokenIds[0],
|
||||
tokenIds[1],
|
||||
tokenIds[2],
|
||||
nonce
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
console.log('openLuckyBox||sign: ', signature, userAddress, boxId, tokenIds, nonce);
|
||||
session.rspData({
|
||||
'nonce': nonce,
|
||||
'signature': signature
|
||||
});
|
||||
}
|
||||
|
||||
async function activateNftSignature(session) {
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
const account = session.request('account');
|
||||
const oldTokenId = session.request('old_token_id');
|
||||
const oldTokenType = session.request('old_token_type');
|
||||
const newTokenId = session.request('new_token_id');
|
||||
|
||||
let nonce = utils.getUtcTime();
|
||||
let signStr = bc.web3.utils.soliditySha3(
|
||||
account,
|
||||
oldTokenId,
|
||||
newTokenId,
|
||||
oldTokenType,
|
||||
nonce
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
console.log('activateNftSignature||sign: ',
|
||||
signature,
|
||||
userAddress,
|
||||
oldTokenId,
|
||||
newTokenId,
|
||||
oldTokenType,
|
||||
nonce);
|
||||
session.rspData({
|
||||
'nonce': nonce,
|
||||
'signature': signature
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
app.registerHandler('BcService', 'authVerifySignature', authVerifySignature);
|
||||
app.registerHandler('BcService', 'buyBoxVerifySignature', buyBoxVerifySignature);
|
||||
app.registerHandler('BcService', 'openBoxSignature', openBoxSignature);
|
||||
app.registerHandler('BcService', 'activateNftSignature', activateNftSignature);
|
||||
}
|
||||
|
||||
exports.init = init;
|
@ -1,239 +0,0 @@
|
||||
const ethUtil = require('ethereumjs-util');
|
||||
const sigUtil = require('@metamask/eth-sig-util');
|
||||
|
||||
const app = require('j7/app');
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const bc = require('../blockchain');
|
||||
const metaFactory = require('../metadata/factory');
|
||||
|
||||
async function pluginChip(session) {
|
||||
try {
|
||||
const accountId = session.request('account_id');
|
||||
const account = session.request('account');
|
||||
const sessionId = session.request('session_id');
|
||||
const tokenId = session.request('token_id');
|
||||
const tokenType = session.request('token_type');
|
||||
const chipIds = session.request('chip_ids').split('|');
|
||||
const slotIds = session.request('slot_ids').split('|');
|
||||
|
||||
const nftAddress = bc.getNftAddress(tokenType);
|
||||
const chipAddress = bc.getNftAddress(bcutils.CHIP_TYPE);
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
|
||||
{
|
||||
if (!(tokenType == bcutils.HERO_TYPE ||
|
||||
tokenType == bcutils.EQUIP_TYPE)) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
if (!chipAddress) {
|
||||
session.rspErr(101, 'chip_type param error');
|
||||
return;
|
||||
}
|
||||
if (chipIds.length != slotIds.length ||
|
||||
chipIds.length > 4) {
|
||||
session.rspErr(101, 'chip_ids length error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson());
|
||||
if (err) {
|
||||
session.rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
|
||||
const nowTime = utils.getUtcTime();
|
||||
const transId = bcutils.genTransId
|
||||
(
|
||||
bcutils.BC_TRANS_FUNC_PLUGIN,
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
(
|
||||
seqId,
|
||||
[
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const nonce = transId;
|
||||
const signArr = [];
|
||||
for (let i = 0; i < chipIds.length; ++i) {
|
||||
signArr.push(chipIds[i]);
|
||||
signArr.push(slotIds[i]);
|
||||
}
|
||||
let signStr = await bc.web3.utils.soliditySha3
|
||||
(
|
||||
nftAddress,
|
||||
chipAddress,
|
||||
account,
|
||||
|
||||
tokenId,
|
||||
nonce,
|
||||
nowTime,
|
||||
|
||||
...signArr
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
|
||||
const addresses = [
|
||||
nftAddress,
|
||||
chipAddress,
|
||||
userAddress
|
||||
];
|
||||
const values = [
|
||||
tokenId,
|
||||
nonce,
|
||||
nowTime
|
||||
];
|
||||
utils.arrayToStrings(addresses);
|
||||
utils.arrayToStrings(values);
|
||||
utils.arrayToStrings(chipIds);
|
||||
utils.arrayToStrings(slotIds);
|
||||
|
||||
const rspParams = [
|
||||
utils.jsonEncode(addresses),
|
||||
utils.jsonEncode(values),
|
||||
utils.jsonEncode(chipIds),
|
||||
utils.jsonEncode(slotIds),
|
||||
signature
|
||||
];
|
||||
utils.arrayToStrings(rspParams);
|
||||
|
||||
session.rspData({
|
||||
'trans_id' : transId,
|
||||
'params': rspParams
|
||||
});
|
||||
} catch (e) {
|
||||
session.rspErr(1, 1);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function unplugChip(session) {
|
||||
try {
|
||||
const accountId = session.request('account_id');
|
||||
const account = session.request('account');
|
||||
const sessionId = session.request('session_id');
|
||||
const tokenId = session.request('token_id');
|
||||
const tokenType = session.request('token_type');
|
||||
const chipIds = session.request('chip_ids').split('|');
|
||||
const slotIds = session.request('slot_ids').split('|');
|
||||
|
||||
const nftAddress = bc.getNftAddress(tokenType);
|
||||
const chipAddress = bc.getNftAddress(bcutils.CHIP_TYPE);
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
|
||||
{
|
||||
if (!(tokenType == bcutils.HERO_TYPE ||
|
||||
tokenType == bcutils.EQUIP_TYPE)) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
if (!chipAddress) {
|
||||
session.rspErr(101, 'chip_type param error');
|
||||
return;
|
||||
}
|
||||
if (chipIds.length != slotIds.length ||
|
||||
chipIds.length > 4) {
|
||||
session.rspErr(101, 'chip_ids length error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson());
|
||||
if (err) {
|
||||
session.rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
|
||||
const nowTime = utils.getUtcTime();
|
||||
const transId = bcutils.genTransId
|
||||
(
|
||||
bcutils.BC_TRANS_FUNC_PLUGIN,
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
(
|
||||
seqId,
|
||||
[
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const nonce = transId;
|
||||
const signArr = [];
|
||||
for (let i = 0; i < chipIds.length; ++i) {
|
||||
signArr.push(chipIds[i]);
|
||||
signArr.push(slotIds[i]);
|
||||
}
|
||||
let signStr = await bc.web3.utils.soliditySha3
|
||||
(
|
||||
nftAddress,
|
||||
chipAddress,
|
||||
account,
|
||||
|
||||
tokenId,
|
||||
nonce,
|
||||
nowTime,
|
||||
|
||||
...signArr
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
|
||||
const addresses = [
|
||||
nftAddress,
|
||||
chipAddress,
|
||||
userAddress
|
||||
];
|
||||
const values = [
|
||||
tokenId,
|
||||
nonce,
|
||||
nowTime
|
||||
];
|
||||
utils.arrayToStrings(addresses);
|
||||
utils.arrayToStrings(values);
|
||||
utils.arrayToStrings(chipIds);
|
||||
utils.arrayToStrings(slotIds);
|
||||
|
||||
const rspParams = [
|
||||
utils.jsonEncode(addresses),
|
||||
utils.jsonEncode(values),
|
||||
utils.jsonEncode(chipIds),
|
||||
utils.jsonEncode(slotIds),
|
||||
signature
|
||||
];
|
||||
utils.arrayToStrings(rspParams);
|
||||
|
||||
session.rspData({
|
||||
'trans_id' : transId,
|
||||
'params': rspParams
|
||||
});
|
||||
} catch (e) {
|
||||
session.rspErr(1, 1);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
app.registerHandler('BcService', 'pluginChip', pluginChip);
|
||||
app.registerHandler('BcService', 'unplugChip', unplugChip);
|
||||
}
|
||||
|
||||
exports.init = init;
|
@ -1,195 +0,0 @@
|
||||
const ethUtil = require('ethereumjs-util');
|
||||
const sigUtil = require('@metamask/eth-sig-util');
|
||||
|
||||
const app = require('j7/app');
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const bc = require('../blockchain');
|
||||
const metaFactory = require('../metadata/factory');
|
||||
|
||||
async function evolve721Nft(session) {
|
||||
try {
|
||||
const accountId = session.request('account_id');
|
||||
const sessionId = session.request('session_id');
|
||||
const account = session.request('account');
|
||||
const type = session.request('type');
|
||||
const tokenId1 = session.request('token_id1');
|
||||
const tokenId2 = session.request('token_id2');
|
||||
|
||||
console.log(session.requestToJson());
|
||||
let tokenType = 0;
|
||||
switch (type) {
|
||||
case '1':
|
||||
{
|
||||
tokenType = bcutils.HERO_TYPE;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
{
|
||||
tokenType = bcutils.EQUIP_TYPE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
session.rspErr(101, 'type paramater error');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const nftAddress = bc.getNftAddress(tokenType);
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
|
||||
{
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson());
|
||||
if (err) {
|
||||
session.rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
|
||||
const nowTime = utils.getUtcTime();
|
||||
const transId = bcutils.genTransId
|
||||
(
|
||||
bcutils.BC_TRANS_FUNC_EVOLVE,
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
tokenType
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
(
|
||||
seqId,
|
||||
[
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const tokenIds = [tokenId1, tokenId2];
|
||||
const nonce = transId;
|
||||
let signStr = await bc.web3.utils.soliditySha3
|
||||
(
|
||||
account,
|
||||
nowTime,
|
||||
nonce,
|
||||
...tokenIds
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
|
||||
utils.arrayToStrings(tokenIds);
|
||||
|
||||
const rspParams = [
|
||||
nftAddress,
|
||||
utils.jsonEncode(tokenIds),
|
||||
nowTime,
|
||||
nonce,
|
||||
signature
|
||||
];
|
||||
utils.arrayToStrings(rspParams);
|
||||
console.log(rspParams);
|
||||
|
||||
session.rspData({
|
||||
'trans_id' : transId,
|
||||
'params': rspParams
|
||||
});
|
||||
} catch (e) {
|
||||
session.rspErr(1, 1);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function evolveChip(session) {
|
||||
try {
|
||||
const accountId = session.request('account_id');
|
||||
const account = session.request('account');
|
||||
const sessionId = session.request('session_id');
|
||||
const tokenId = session.request('token_id');
|
||||
const itemId = session.request('item_id');
|
||||
const tokenIds = session.request('token_ids').toString().split('|');
|
||||
|
||||
const price = 0;
|
||||
const nftAddress = bc.getNftAddress(bcutils.CHIP_TYPE);
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
const paymentTokenAddress = metaFactory.getContractByName('gold')['address'];
|
||||
|
||||
{
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson());
|
||||
if (err) {
|
||||
session.rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
|
||||
const nowTime = utils.getUtcTime();
|
||||
const transId = bcutils.genTransId
|
||||
(
|
||||
bcutils.BC_TRANS_FUNC_EVOLVE,
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
bcutils.CHIP_TYPE
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
(
|
||||
seqId,
|
||||
[
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const nonce = transId;
|
||||
const signArr = [tokenId];
|
||||
tokenIds.forEach
|
||||
(
|
||||
(element) => {
|
||||
signArr.push(element);
|
||||
}
|
||||
);
|
||||
let signStr = await bc.web3.utils.soliditySha3
|
||||
(
|
||||
account,
|
||||
nowTime,
|
||||
nonce,
|
||||
...signArr
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
|
||||
utils.arrayToStrings(signArr);
|
||||
|
||||
const rspParams = [
|
||||
utils.jsonEncode(signArr),
|
||||
nowTime,
|
||||
nonce,
|
||||
signature
|
||||
];
|
||||
utils.arrayToStrings(rspParams);
|
||||
console.log(rspParams);
|
||||
|
||||
session.rspData({
|
||||
'trans_id' : transId,
|
||||
'params': rspParams
|
||||
});
|
||||
} catch (e) {
|
||||
session.rspErr(1, 1);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
app.registerHandler('BcService', 'evolve721Nft', evolve721Nft);
|
||||
app.registerHandler('BcService', 'evolveChip', evolveChip);
|
||||
}
|
||||
|
||||
exports.init = init;
|
@ -6,11 +6,6 @@ function add(name) {
|
||||
}
|
||||
|
||||
function init() {
|
||||
add('bcservice');
|
||||
add('activate');
|
||||
//add('fragment');
|
||||
//add('evolve');
|
||||
//add('chip_plugin');
|
||||
}
|
||||
|
||||
exports.init = init;
|
||||
|
@ -1,232 +0,0 @@
|
||||
const ethUtil = require('ethereumjs-util');
|
||||
const sigUtil = require('@metamask/eth-sig-util');
|
||||
|
||||
const app = require('j7/app');
|
||||
const utils = require('j7/utils');
|
||||
const bcutils = require('j7/bcutils');
|
||||
const bc = require('../blockchain');
|
||||
const metaFactory = require('../metadata/factory');
|
||||
|
||||
async function mintShardBatchUser(session) {
|
||||
try {
|
||||
const accountId = session.request('account_id');
|
||||
const account = session.request('account');
|
||||
const sessionId = session.request('session_id');
|
||||
const tokenId = session.request('token_id');
|
||||
const itemUniId = session.request('item_uniid');
|
||||
const itemId = session.request('item_id');
|
||||
const num = session.request('num');
|
||||
|
||||
const nftAddress = bc.getNftAddress(bcutils.FRAGMENT_TYPE);
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
|
||||
{
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson());
|
||||
if (err) {
|
||||
session.rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
|
||||
const nowTime = utils.getUtcTime();
|
||||
const transId = bcutils.genTransId
|
||||
(
|
||||
bcutils.BC_TRANS_FUNC_MINT_SHARD,
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
itemUniId,
|
||||
utils.pad(itemId, 10) + utils.pad(num, 10)
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
(
|
||||
seqId,
|
||||
[
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const nonce = transId;
|
||||
let signStr = await bc.web3.utils.soliditySha3
|
||||
(
|
||||
account,
|
||||
nftAddress,
|
||||
nowTime,
|
||||
nonce,
|
||||
tokenId,
|
||||
num
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
|
||||
const ids = [
|
||||
tokenId
|
||||
];
|
||||
const amounts = [
|
||||
num
|
||||
];
|
||||
utils.arrayToStrings(ids);
|
||||
utils.arrayToStrings(amounts);
|
||||
|
||||
const rspParams = [
|
||||
utils.jsonEncode(ids),
|
||||
utils.jsonEncode(amounts),
|
||||
nowTime,
|
||||
nonce,
|
||||
signature
|
||||
];
|
||||
utils.arrayToStrings(rspParams);
|
||||
|
||||
session.rspData({
|
||||
'trans_id' : transId,
|
||||
'params': rspParams
|
||||
});
|
||||
} catch (e) {
|
||||
session.rspErr(1, 1);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function shardMixByUser(session) {
|
||||
try {
|
||||
const accountId = session.request('account_id');
|
||||
const account = session.request('account');
|
||||
const sessionId = session.request('session_id');
|
||||
const tokenId = session.request('token_id');
|
||||
const tokenType = session.request('token_type');
|
||||
const itemId = session.request('item_id');
|
||||
const tokenIds = session.request('token_ids').toString().split('|');
|
||||
|
||||
const price = 0;
|
||||
const nftAddress = bc.getNftAddress(tokenType);
|
||||
const shardAddress = metaFactory.getContractByName('shard')['address'];
|
||||
const userAddress = metaFactory.getUserAddress();
|
||||
const paymentTokenAddress = metaFactory.getContractByName('gold')['address'];
|
||||
|
||||
console.log(session.requestToJson());
|
||||
if (itemId) {
|
||||
const itemMeta = metaFactory.getMetaByKey('Item', itemId);
|
||||
console.log(itemMeta, 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() == bcutils.HERO_TYPE ||
|
||||
itemMeta.getNftType() == bcutils.EQUIP_TYPE)) {
|
||||
session.rspErr(101, 'item_id param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let nftType = 0;
|
||||
if (tokenType == bcutils.HERO_TYPE) {
|
||||
nftType = 0;
|
||||
} else if (tokenType == bcutils.EQUIP_TYPE) {
|
||||
nftType = 1;
|
||||
} else {
|
||||
session.rspErr(101, 'invalid nft type');
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
if (!nftAddress) {
|
||||
session.rspErr(101, 'token_type param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const transModel = session.createModel('Transaction');
|
||||
const {err, seqId} = await transModel.add(account, session.requestToJson());
|
||||
if (err) {
|
||||
session.rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
|
||||
const nowTime = utils.getUtcTime();
|
||||
const transId = bcutils.genTransId
|
||||
(
|
||||
bcutils.BC_TRANS_FUNC_MINT_SHARD,
|
||||
nowTime,
|
||||
seqId,
|
||||
[
|
||||
utils.pad(itemId, 10) + utils.pad(tokenType, 10)
|
||||
]
|
||||
);
|
||||
await transModel.update
|
||||
(
|
||||
seqId,
|
||||
[
|
||||
['trans_id', transId]
|
||||
]);
|
||||
const nonce = transId;
|
||||
const signArr = [];
|
||||
tokenIds.forEach
|
||||
(
|
||||
(element) => {
|
||||
signArr.push(element);
|
||||
signArr.push(1);
|
||||
}
|
||||
);
|
||||
let signStr = await bc.web3.utils.soliditySha3
|
||||
(
|
||||
account,
|
||||
nftAddress,
|
||||
tokenId,
|
||||
paymentTokenAddress,
|
||||
price,
|
||||
nowTime,
|
||||
nonce,
|
||||
...signArr
|
||||
);
|
||||
let signature = await bc.web3.eth.sign(signStr, userAddress);
|
||||
signature = signature.replace(/00$/, "1b").replace(/01$/, "1c");
|
||||
|
||||
const amounts = [];
|
||||
tokenIds.forEach
|
||||
(
|
||||
(element) => {
|
||||
amounts.push(1);
|
||||
}
|
||||
);
|
||||
utils.arrayToStrings(tokenIds);
|
||||
utils.arrayToStrings(amounts);
|
||||
|
||||
const rspParams = [
|
||||
tokenId,
|
||||
nftType,
|
||||
paymentTokenAddress,
|
||||
price,
|
||||
utils.jsonEncode(tokenIds),
|
||||
utils.jsonEncode(amounts),
|
||||
nowTime,
|
||||
nonce,
|
||||
signature
|
||||
];
|
||||
utils.arrayToStrings(rspParams);
|
||||
console.log(rspParams);
|
||||
|
||||
session.rspData({
|
||||
'trans_id' : transId,
|
||||
'params': rspParams
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
session.rspErr(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
app.registerHandler('BcService', 'mintShardBatchUser', mintShardBatchUser);
|
||||
app.registerHandler('BcService', 'shardMixByUser', shardMixByUser);
|
||||
}
|
||||
|
||||
exports.init = init;
|
Loading…
x
Reference in New Issue
Block a user