From 145d173f5cba467d762f7358b77489066e0f10be Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 4 Aug 2023 15:58:01 +0800 Subject: [PATCH] 1 --- server/common/bcconst.js | 6 ++++++ server/web3sign/blockchain.js | 13 +++++++++++++ server/web3sign/controllers/game_item_mall.js | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/server/common/bcconst.js b/server/common/bcconst.js index ad0922d..5050c60 100644 --- a/server/common/bcconst.js +++ b/server/common/bcconst.js @@ -19,6 +19,9 @@ const BC_TRANS_FUNC_EVOLVE = 3; const BC_TRANS_FUNC_PLUGIN = 4; const BC_TRANS_FUNC_COMMON = 5; +const ARBITRUM_NET_ID = 42161; +const ARBITRUM_TEST_NET_ID = 421613; + exports.BC_NFT_NONE = BC_NFT_NONE; exports.BC_NFT_HERO = BC_NFT_HERO; exports.BC_NFT_EQUIP = BC_NFT_EQUIP; @@ -39,3 +42,6 @@ exports.BC_TRANS_FUNC_MINT_SHARD = BC_TRANS_FUNC_MINT_SHARD; exports.BC_TRANS_FUNC_EVOLVE = BC_TRANS_FUNC_EVOLVE; exports.BC_TRANS_FUNC_PLUGIN = BC_TRANS_FUNC_PLUGIN; exports.BC_TRANS_FUNC_COMMON = BC_TRANS_FUNC_COMMON; + +exports.ARBITRUM_NET_ID = ARBITRUM_NET_ID; +exports.ARBITRUM_TEST_NET_ID = ARBITRUM_TEST_NET_ID; diff --git a/server/web3sign/blockchain.js b/server/web3sign/blockchain.js index cad614b..47bc10e 100644 --- a/server/web3sign/blockchain.js +++ b/server/web3sign/blockchain.js @@ -36,6 +36,15 @@ class BlockChain { this[`${data.name}Instance`] = await this.initInstance (this.getUserAddress(), data.address, this.netDir + data.json); } + this.currencyHash = {}; + this.currencyHash['CEG'] = this.getContractByName(contract.CEG_INSTANCE_NAME); + if (this.netId == bcconst.ARBITRUM_NET_ID) { + this.currencyHash['USDT'] = bcutils.toNormalAddress('0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9'); + this.currencyHash['USDC'] = bcutils.toNormalAddress('0xaf88d065e77c8cC2239327C5EDb3A432268e5831'); + } else if (this.netId == bcconst.ARBITRUM_TEST_NET_ID) { + this.currencyHash['USDT'] = bcutils.toNormalAddress('0xaa34B79A0Ab433eaC900fB3CB9f191F5Cd27501D'); + this.currencyHash['USDC'] = bcutils.toNormalAddress('0x944D0A8463B2c955F90F7252bBb99A3395087155'); + } const chainId = await this.web3.eth.getChainId(); if (chainId != this.netId) { log.warning(util.format('net id error %s %s', @@ -85,6 +94,10 @@ class BlockChain { return bcutils.isValidAddress(address); } + getCurrencyAddressByName(currencyName) { + return utils.hasKey(this.currencyHash, currencyName) ? this.currencyHash[currencyName] : ''; + } + } module.exports = BlockChain; diff --git a/server/web3sign/controllers/game_item_mall.js b/server/web3sign/controllers/game_item_mall.js index 211fd98..e8c1895 100644 --- a/server/web3sign/controllers/game_item_mall.js +++ b/server/web3sign/controllers/game_item_mall.js @@ -26,7 +26,7 @@ async function buy(session) { } } - const currency = bc.getContractAddressByName(currencyName); + const currency = bc.getCurrencyAddressByName(currencyName); const userAddress = bc.getUserAddress(); { if (!bc.isValidAddress(currency)) {