From c7a7205f60f11386254bfa542ebe3268f6cdbeb7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 26 Jul 2024 10:58:26 +0800 Subject: [PATCH] 1 --- server/web3sign/controllers/recharge.js | 38 ++++++++++++------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/server/web3sign/controllers/recharge.js b/server/web3sign/controllers/recharge.js index 6d8f9e7..c6fd4ec 100644 --- a/server/web3sign/controllers/recharge.js +++ b/server/web3sign/controllers/recharge.js @@ -35,30 +35,33 @@ async function recharge(session) { return; } } + const currencyMeta = bc.getContractByName(currencyName); + if (!currencyMeta) { + session.rspErr(500, 'currency meta not found'); + return; + } + if (currencyMeta['type'] != 'erc20') { + session.rspErr(500, 'currency meta type error'); + return; + } + const gameMallMeta = bc.getContractByName(bccontract.GameItemMall_INSTANCE_NAME); + if (!gameMallMeta) { + session.rspErr(500, 'gamemall meta not found'); + return; + } + const currencyAddress = bcutils.toNormalAddress(currencyMeta['address']); + const gameMallAddress = bcutils.toNormalAddress(gameMallMeta['address']); - let currencyAddress = ''; const nowTime = utils.getUtcTime(); const calls = []; { - const contractMeta = bc.getContractByName(currencyName); - if (!contractMeta) { - session.rspErr(500, 'currency meta not found'); - return; - } - console.log(contractMeta); - if (contractMeta['type'] != 'erc20') { - session.rspErr(500, 'currency meta type error'); - return; - } - currencyAddress = bcutils.toNormalAddress(contractMeta['address']); - const instance = bc.getInstanceByName(currencyName); if (!instance) { session.rspErr(500, 'currency error'); return; } let data = instance.methods.approve( - spender, + gameMallAddress, amount).encodeABI(); calls.push({ 'trans_id' : '', @@ -69,11 +72,6 @@ async function recharge(session) { }); } { - const contractMeta = bc.getContractByName(bccontract.GameItemMall_INSTANCE_NAME); - if (!contractMeta) { - session.rspErr(500, 'gamemall meta not found'); - return; - } const instance = bc.getInstanceByName(bccontract.GameItemMall_INSTANCE_NAME); if (!instance) { @@ -102,7 +100,7 @@ async function recharge(session) { calls.push({ 'trans_id' : '', 'trans_req': { - 'to': bcutils.toNormalAddress(contractMeta['address']), + 'to': gameMallAddress, 'data': data } });