91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
const utils = require('./utils');
|
|
|
|
const BC_BASE_GAME_ID = 2005;
|
|
|
|
const BC_FUNC_CREATION = 1;
|
|
const BC_FUNC_GUILD = 3;
|
|
const BC_FUNC_BLIND_BOX = 5;
|
|
const BC_MAX_TOKEN_IDX = 99999;
|
|
|
|
const BC_EPOCH = 1643212800;
|
|
|
|
const NONE_TYPE = 0;
|
|
const HERO_TYPE = 1;
|
|
const EQUIP_TYPE = 2;
|
|
const CHIP_TYPE = 3;
|
|
const BLIND_BOX_TYPE = 4;
|
|
|
|
function isValidBcGameId(gameId) {
|
|
return gameID > BASE_BC_GAME_ID && gameID < BC_BASE_GAME_ID + 99;
|
|
}
|
|
|
|
function isValidBcTime(time) {
|
|
return time >= BC_EPOCH && time < BC_EPOCH + 3600 * 24 * 365 * 20;
|
|
}
|
|
|
|
function isValidBcFuncId(funcId) {
|
|
return funcId > 0 && funcId < 10;
|
|
}
|
|
|
|
function toBcTime(time) {
|
|
return time - BC_EPOCH;
|
|
}
|
|
|
|
function toBcGameId(gameId) {
|
|
return gameId - BC_BASE_GAME_ID;
|
|
}
|
|
|
|
function toNormalAddress(address) {
|
|
return address.toLowerCase();
|
|
}
|
|
|
|
function genTokenId(gameId, funcId, time, subIdx, idx) {
|
|
const tokenId =
|
|
funcId.toString() +
|
|
utils.pad(toBcGameId(gameId), 2) +
|
|
utils.pad(toBcTime(time), 9) +
|
|
utils.pad(subIdx, 1) +
|
|
utils.pad(1 + (idx % BC_MAX_TOKEN_IDX), 5);
|
|
return tokenId;
|
|
}
|
|
|
|
function isValidTokenId(tokenId) {
|
|
return utils.isPureNumberStr(tokenId.toString()) && tokenId.toString().length == 18;
|
|
}
|
|
|
|
function setTokenIdSubIdx(tokenId, idx) {
|
|
if (!isValidTokenId(tokenId)) {
|
|
throw 'setTokenIdSubIdx error tokenId:' + tokenId + ' idx:' + idx;
|
|
}
|
|
if (idx < 0 || idx > 9 || idx.toString().length != 1) {
|
|
throw 'setTokenIdSubIdx error tokenId:' + tokenId + ' idx:' + idx;
|
|
}
|
|
throw 'setTokenIdSubIdx error tokenId:' + tokenId + ' idx:' + idx;
|
|
}
|
|
|
|
function isSameAddress(a, b) {
|
|
return a.toLowerCase() == b.toLowerCase();
|
|
}
|
|
|
|
exports.BC_BASE_GAME_ID = BC_BASE_GAME_ID;
|
|
exports.BC_FUNC_CREATION = BC_FUNC_CREATION;
|
|
exports.BC_FUNC_GUILD = BC_FUNC_GUILD;
|
|
exports.BC_FUNC_BLIND_BOX = BC_FUNC_BLIND_BOX;
|
|
exports.BC_EPOCH = BC_EPOCH;
|
|
exports.BC_MAX_TOKEN_IDX = BC_MAX_TOKEN_IDX;
|
|
exports.NONE_TYPE = NONE_TYPE;
|
|
exports.HERO_TYPE = HERO_TYPE
|
|
exports.EQUIP_TYPE = EQUIP_TYPE
|
|
exports.CHIP_TYPE = CHIP_TYPE
|
|
exports.BLIND_BOX_TYPE = BLIND_BOX_TYPE
|
|
exports.isValidBcGameId = isValidBcGameId;
|
|
exports.isValidBcTime = isValidBcTime;
|
|
exports.isValidBcFuncId = isValidBcFuncId;
|
|
exports.toBcTime = toBcTime;
|
|
exports.toBcGameId = toBcGameId;
|
|
exports.toNormalAddress = toNormalAddress;
|
|
exports.genTokenId = genTokenId;
|
|
exports.isValidTokenId = isValidTokenId;
|
|
exports.setTokenIdSubIdx = setTokenIdSubIdx;
|
|
exports.isSameAddress = isSameAddress;
|