添加激活nft功能
This commit is contained in:
parent
6829810a88
commit
88efafb39f
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"list":["22042103"],
|
"list":[],
|
||||||
"id_section": {
|
"id_section": {
|
||||||
"id_22042102":[30001, 40000]
|
"id_22042102":[30001, 40000],
|
||||||
|
"id_22042301":[32001, 32003]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,5 +58,10 @@
|
|||||||
"name": "boxproxy",
|
"name": "boxproxy",
|
||||||
"json": "assets/contracts/MysteryBoxProxy.json",
|
"json": "assets/contracts/MysteryBoxProxy.json",
|
||||||
"address": "0xA171C03Fa71bD66A013e53F64dDb9455C58E6567"
|
"address": "0xA171C03Fa71bD66A013e53F64dDb9455C58E6567"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "activateproxy",
|
||||||
|
"json": "assets/contracts/NFTActivateProxy.json",
|
||||||
|
"address": "0x244B1F2c13eCbF9Ac918a01F5261972459dCd7c6"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
117
server/web3helper/services/_internal/activate_process.js
Normal file
117
server/web3helper/services/_internal/activate_process.js
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
const log = require('j7/log');
|
||||||
|
const bcutils = require('j7/bcutils');
|
||||||
|
const utils = require('j7/utils');
|
||||||
|
const event = require('j7/event');
|
||||||
|
const metaFactory = require('../../metadata/factory');
|
||||||
|
const C = require('../../C');
|
||||||
|
|
||||||
|
class ActivateProcess {
|
||||||
|
|
||||||
|
async start(instance, conn, event) {
|
||||||
|
const {err, row} = await conn.ormSelectOne(
|
||||||
|
't_activate_event',
|
||||||
|
[
|
||||||
|
['txhash', event['transactionHash']],
|
||||||
|
['log_index', event['logIndex']],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
if (err) {
|
||||||
|
this.throwError(instance, err);
|
||||||
|
}
|
||||||
|
if (!row) {
|
||||||
|
const blockNumber = event['blockNumber'];
|
||||||
|
const returnValues = event['returnValues'];
|
||||||
|
const oldTokenId = returnValues['nftOld'];
|
||||||
|
const newTokenId = returnValues['nftNew'];
|
||||||
|
const fieldList = [
|
||||||
|
['old_token_id', oldTokenId],
|
||||||
|
['old_token_type', returnValues['nftType']],
|
||||||
|
['new_token_id', newTokenId],
|
||||||
|
['txhash', event['transactionHash']],
|
||||||
|
['block_number', blockNumber],
|
||||||
|
['log_index', event['logIndex']],
|
||||||
|
['_to', bcutils.toNormalAddress(returnValues['to'])],
|
||||||
|
['raw_data', utils.jsonEncode(event)],
|
||||||
|
['createtime', utils.getUtcTime()],
|
||||||
|
['modifytime', utils.getUtcTime()],
|
||||||
|
];
|
||||||
|
{
|
||||||
|
const {err, row} = await conn.ormSelectOne(
|
||||||
|
't_nft',
|
||||||
|
[
|
||||||
|
['token_id', oldTokenId],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
if (err) {
|
||||||
|
log.error('processEvent:' + err);
|
||||||
|
throw 'processEvent:' + err;
|
||||||
|
} else {
|
||||||
|
await this.mintNft(
|
||||||
|
conn,
|
||||||
|
bcutils.toNormalAddress(returnValues['to']),
|
||||||
|
blockNumber,
|
||||||
|
newTokenId,
|
||||||
|
row['token_type'],
|
||||||
|
row['item_id'],
|
||||||
|
row['tags']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const {err} = await conn.insert(
|
||||||
|
't_activate_event',
|
||||||
|
fieldList
|
||||||
|
);
|
||||||
|
if (err) {
|
||||||
|
this.throwError(instance, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async mintNft(conn, owner, blockNumber, tokenId, tokenType, itemId, tags) {
|
||||||
|
const {err, row} = await conn.ormSelectOne(
|
||||||
|
't_nft',
|
||||||
|
[
|
||||||
|
['token_id', tokenId],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
if (err) {
|
||||||
|
log.error('processEvent:' + err);
|
||||||
|
throw 'processEvent:' + err;
|
||||||
|
}
|
||||||
|
if (!row) {
|
||||||
|
const nowTime = utils.getUtcTime();
|
||||||
|
const fieldList = [
|
||||||
|
['token_id', tokenId],
|
||||||
|
['token_type', tokenType],
|
||||||
|
['item_id', itemId],
|
||||||
|
['tags', tags],
|
||||||
|
['game_id', 2006],
|
||||||
|
['owner_address', bcutils.toNormalAddress(owner)],
|
||||||
|
['creator_address', bcutils.toNormalAddress(owner)],
|
||||||
|
['confirm_block_number', blockNumber],
|
||||||
|
['createtime', nowTime],
|
||||||
|
['modifytime', nowTime],
|
||||||
|
];
|
||||||
|
const {err} = await conn.insert(
|
||||||
|
't_nft',
|
||||||
|
fieldList
|
||||||
|
);
|
||||||
|
if (err) {
|
||||||
|
log.error('processEvent:' + err);
|
||||||
|
throw 'processEvent:' + err;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
event.emitEvent(C.CREATE_EXEC_CONFIRM_OWNER_EVENT, tokenId);
|
||||||
|
} catch (err) {
|
||||||
|
log.warning('processEvent:' + err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throwError(instance, err) {
|
||||||
|
const errMsg = 'processActivateEvent:' + utils.jsonEncode(instance) + ' err:' + err;
|
||||||
|
throw errMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ActivateProcess;
|
@ -8,6 +8,7 @@ const bc = require('../blockchain');
|
|||||||
const C = require('../C');
|
const C = require('../C');
|
||||||
const factory = require('./factory');
|
const factory = require('./factory');
|
||||||
const BoxOpenedProcess = require('./_internal/boxopened_process');
|
const BoxOpenedProcess = require('./_internal/boxopened_process');
|
||||||
|
const ActivateProcess = require('./_internal/activate_process');
|
||||||
const NftTransferProcess = require('./_internal/nft_transfer_process');
|
const NftTransferProcess = require('./_internal/nft_transfer_process');
|
||||||
|
|
||||||
const LIMIT_COUNT = 100;
|
const LIMIT_COUNT = 100;
|
||||||
@ -38,6 +39,11 @@ class EventCenter extends BaseService {
|
|||||||
'eventName': 'BoxOpened',
|
'eventName': 'BoxOpened',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
activateInstance = {
|
||||||
|
'name': 'activateproxyInstance',
|
||||||
|
'eventName': 'LogNFTActivate',
|
||||||
|
};
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
this.lastIdx = 0;
|
this.lastIdx = 0;
|
||||||
this.pendingConfirmOwnerHash = {};
|
this.pendingConfirmOwnerHash = {};
|
||||||
@ -85,6 +91,7 @@ class EventCenter extends BaseService {
|
|||||||
allInstances.push(item);
|
allInstances.push(item);
|
||||||
});
|
});
|
||||||
allInstances.push(this.boxInstance);
|
allInstances.push(this.boxInstance);
|
||||||
|
allInstances.push(this.activateInstance);
|
||||||
allInstances.forEach((item) => {
|
allInstances.forEach((item) => {
|
||||||
initInstance(item);
|
initInstance(item);
|
||||||
});
|
});
|
||||||
@ -117,6 +124,12 @@ class EventCenter extends BaseService {
|
|||||||
await (new BoxOpenedProcess()).start(this.boxInstance, this.conn, event);
|
await (new BoxOpenedProcess()).start(this.boxInstance, this.conn, event);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
factory.create('EventProcess', null)
|
||||||
|
.init(this.conn, this.activateInstance, async (event) => {
|
||||||
|
await (new ActivateProcess()).start(this.activateInstance, this.conn, event);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addConfirmOwnerRequest(tokenId) {
|
async addConfirmOwnerRequest(tokenId) {
|
||||||
|
@ -116,10 +116,41 @@ async function openBoxSignature(session) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
function init() {
|
||||||
app.registerHandler('BcService', 'authVerifySignature', authVerifySignature);
|
app.registerHandler('BcService', 'authVerifySignature', authVerifySignature);
|
||||||
app.registerHandler('BcService', 'buyBoxVerifySignature', buyBoxVerifySignature);
|
app.registerHandler('BcService', 'buyBoxVerifySignature', buyBoxVerifySignature);
|
||||||
app.registerHandler('BcService', 'openBoxSignature', openBoxSignature);
|
app.registerHandler('BcService', 'openBoxSignature', openBoxSignature);
|
||||||
|
app.registerHandler('BcService', 'activateNftSignature', activateNftSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.init = init;
|
exports.init = init;
|
||||||
|
2
third_party/j7
vendored
2
third_party/j7
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 3b3e2ff5ed360b626d92a9906d5fddaa500422ee
|
Subproject commit 786102288f4bd7e2184838531fc211803c2ce7e1
|
@ -1 +1 @@
|
|||||||
Subproject commit 0e0ebcbb9a3cb8639b0975903e05901261685d1c
|
Subproject commit e3d33d93c08de3abf0126ea87e9a3e905dcd8e95
|
Loading…
x
Reference in New Issue
Block a user