1
This commit is contained in:
parent
86771431ba
commit
973b90b387
@ -4,43 +4,6 @@ const bc = require('./blockchain');
|
||||
const metamgr = require('./metamgr');
|
||||
const dbhelper = require('./dbhelper');
|
||||
|
||||
async function buyBox(req, rsp) {
|
||||
try {
|
||||
const privateKey = metamgr.getWeb3Conf()['private_key'];
|
||||
const paymentTokenAddress = metamgr.getContractByName('coin')['address'];
|
||||
|
||||
const tokenId = 1001;
|
||||
const boxId = 1001;
|
||||
const type = 1001;
|
||||
const price = 100;
|
||||
const buyerAddress = metamgr.getWeb3Conf()['user_address'];
|
||||
|
||||
const nonce = utils.getUtcTime();
|
||||
const signStr = bc.web3.utils.soliditySha3(type, paymentTokenAddress, price, nonce);
|
||||
const { signature } = await bc.web3.eth.accounts.sign(signStr, privateKey);
|
||||
|
||||
await bc.coinInstance.methods.increaseAllowance(
|
||||
metamgr.getContractByName('mall')['address'],
|
||||
price).send({ gas: 1000000 });
|
||||
|
||||
const result = await bc.mallInstance.methods.buyBoxWithSignature(
|
||||
boxId,
|
||||
type,
|
||||
buyerAddress,
|
||||
price,
|
||||
paymentTokenAddress,
|
||||
nonce,
|
||||
signature).send({gas: 1000000});
|
||||
|
||||
utils.rspData(rsp, {
|
||||
'signature' : signature,
|
||||
'result': result
|
||||
});
|
||||
} catch (err) {
|
||||
utils.rspErr(rsp, 1, '' + err);
|
||||
}
|
||||
}
|
||||
|
||||
async function privateKeyToAccount(req, rsp) {
|
||||
const privateKey = metamgr.getWeb3Conf()['private_key'];
|
||||
const account = await bc.web3.eth.accounts.privateKeyToAccount(privateKey);
|
||||
@ -131,6 +94,30 @@ async function clearDb(req, rsp) {
|
||||
utils.rspOk(rsp);
|
||||
}
|
||||
|
||||
async function searchEvent(req, rsp) {
|
||||
let instance = req.query.instance;
|
||||
let event = req.query.event;
|
||||
let from = req.query.from;
|
||||
let paramName = req.query.paramName;
|
||||
let paramValue = req.query.paramValue;
|
||||
|
||||
instance = 'mallInstance';
|
||||
event = 'BEBoxPaid';
|
||||
from = 8639235;
|
||||
paramValue = '1010016076900035502';
|
||||
events = await bc[instance].getPastEvents(
|
||||
event,
|
||||
{
|
||||
fromBlock: from - 1000,
|
||||
toBlock: from + 5000 - 1,
|
||||
filter: {
|
||||
boxId: paramValue
|
||||
}
|
||||
});
|
||||
console.log(events);
|
||||
utils.rspOk(rsp);
|
||||
}
|
||||
|
||||
async function execCmd(req, rsp) {
|
||||
if (utils.isOnlineEnv()) {
|
||||
utils.rspErr(rsp, 100, 'not found');
|
||||
@ -138,12 +125,12 @@ async function execCmd(req, rsp) {
|
||||
}
|
||||
const cmd = req.query.cmd;
|
||||
const handlers = {
|
||||
'buyBox': buyBox,
|
||||
'getAccounts': getAccounts,
|
||||
'getBalance': getBalance,
|
||||
'privateKeyToAccount': privateKeyToAccount,
|
||||
'test': test,
|
||||
'clearDb': clearDb,
|
||||
'searchEvent': searchEvent,
|
||||
};
|
||||
const handle = handlers[cmd];
|
||||
if (handle) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user