From cd6a2c216affab41eaef7c63e774442ee959069a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 20 Apr 2022 15:31:31 +0800 Subject: [PATCH] 1 --- server/bin/web3test/config/web3.json | 2 ++ server/web3test/blockchain.js | 5 +++++ server/web3test/controllers/gm.js | 31 ++++++++++++++++++++++++++++ thrid_party/becrypto | 2 +- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/server/bin/web3test/config/web3.json b/server/bin/web3test/config/web3.json index 37e6c9d..b35fcbb 100644 --- a/server/bin/web3test/config/web3.json +++ b/server/bin/web3test/config/web3.json @@ -1,5 +1,7 @@ { "user_address": "0xAd2DeA1977055Db01C66e6E53309C4604AB869b8", "private_key": "9178a1469fc7121aafe1e5dd485f8fa21627daa4656647abddacfcc1e0dbc90e", + "_user_address": "0x50A8e60041A206AcaA5F844a1104896224be6F39", + "_private_key": "d9ed33809372932059c1ba7b336a33f406b4c55e7430daef8297134c67429d60", "block_server": "https://rpc-testnet.kcc.network" } diff --git a/server/web3test/blockchain.js b/server/web3test/blockchain.js index 1213ccb..0a27955 100644 --- a/server/web3test/blockchain.js +++ b/server/web3test/blockchain.js @@ -29,7 +29,12 @@ class BlockChain { for (const data of metaFactory.getContracts()) { this[`${data.name}Instance`] = await this.initInstance (metaFactory.getUserAddress(), data.address, data.json); + + this[`${data.name}InstanceBuy`] = await this.initInstance + (metaFactory.getUserAddress(), data.address, data.json); + } + console.log(metaFactory.getUserAddress()); event.emitEvent(constant.BC_INITIALIZED_EVENT); } diff --git a/server/web3test/controllers/gm.js b/server/web3test/controllers/gm.js index 1866bc7..7ab7f46 100644 --- a/server/web3test/controllers/gm.js +++ b/server/web3test/controllers/gm.js @@ -237,6 +237,36 @@ async function execCmd(session) { } } +async function openLuckyBox(session, params) { + const userAddress = params[0]; + const boxId = params[1]; + const tokenIds = []; + tokenIds.push(params[2]); + tokenIds.push(params[3]); + tokenIds.push(params[4]); + + let nonce = (Math.random() * 1000) | 0; + 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); + + const result = await bc['boxproxyInstanceBuy'].methods.openBox( + boxId, + tokenIds, + nonce, + signature + ).send({ gas: 1000000 }) + console.log(result); + +} + function init() { app.registerHandler('GM', 'execCmd', execCmd); cmdHash['login'] = login; @@ -244,6 +274,7 @@ function init() { cmdHash['balance'] = balance; cmdHash['getPastEvents'] = getPastEvents; cmdHash['getTrans'] = getTrans; + cmdHash['openLuckybox'] = openLuckyBox; } exports.init = init; diff --git a/thrid_party/becrypto b/thrid_party/becrypto index 2b336a2..a068fda 160000 --- a/thrid_party/becrypto +++ b/thrid_party/becrypto @@ -1 +1 @@ -Subproject commit 2b336a24bc4eb86d27a46d71dacab242af87c754 +Subproject commit a068fda5daa00bd4ba95625241ac980f27bc6bfe