This commit is contained in:
aozhiwei 2022-02-10 16:53:58 +08:00
parent 74f7125951
commit 8045d3a737
3 changed files with 23 additions and 14 deletions

View File

@ -26,7 +26,7 @@ class BlockChain {
}
async init() {
this.web3 = new Web3(metamgr.getServerConf()['block_server']);
this.web3 = new Web3(metamgr.getWeb3Conf()['block_server']);
this.web3.eth.accounts.wallet.add(metamgr.getWalletAccount());
for (const data of metamgr.getContracts()) {
this[`${data.name}Instance`] = await this.initInstance

View File

@ -6,14 +6,14 @@ const dbhelper = require('./dbhelper');
async function buyBox(req, rsp) {
try {
const privateKey = metamgr.getServerConf()['private_key'];
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.getServerConf()['user_address'];
const buyerAddress = metamgr.getWeb3Conf()['user_address'];
const nonce = utils.getUtcTime();
const signStr = bc.web3.utils.soliditySha3(type, paymentTokenAddress, price, nonce);
@ -42,7 +42,7 @@ async function buyBox(req, rsp) {
}
async function privateKeyToAccount(req, rsp) {
const privateKey = metamgr.getServerConf()['private_key'];
const privateKey = metamgr.getWeb3Conf()['private_key'];
const account = await bc.web3.eth.accounts.privateKeyToAccount(privateKey);
utils.rspData(rsp, {
'account' : account
@ -56,9 +56,9 @@ async function getAccounts(req, rsp) {
}
async function getBalance(req, rsp) {
const balance = await bc.getBalance(metamgr.getServerConf()['user_address']);
const balance = await bc.getBalance(metamgr.getWeb3Conf()['user_address']);
utils.rspData(rsp, {
'user_address': metamgr.getServerConf()['user_address'],
'user_address': metamgr.getWeb3Conf()['user_address'],
'balance': balance
});
}
@ -80,8 +80,8 @@ async function test(req, rsp) {
(sec < 10 ? '0' + sec : sec) +
'002006';
}();
const privateKey = metamgr.getServerConf()['private_key'];
const buyerAddress = metamgr.getServerConf()['user_address'];
const privateKey = metamgr.getWeb3Conf()['private_key'];
const buyerAddress = metamgr.getWeb3Conf()['user_address'];
const paymentTokenAddress = metamgr.getContractByName('coin')['address'];
const nowTime = utils.getUtcTime();
const count = 1;

View File

@ -3,12 +3,12 @@ const log = require('./log');
const metaClasses = [];
const MT_WEB3SERVEWR = 0;
const MT_WEB3SERVER = 0;
const MT_CONTRACT = 1;
const MT_MYSQL = 2;
const MT_WEB3 = 3;
function registerMetaClass(fileName, idx, primKey) {
metaClasses.push({
'fileName' : fileName,
'idx' : idx,
@ -48,7 +48,7 @@ function init() {
configDir = '../config/';
}
registerMetaClass(configDir + 'web3server.json',
MT_WEB3SERVEWR,
MT_WEB3SERVER,
''
);
registerMetaClass(configDir + 'contract.json',
@ -58,6 +58,10 @@ function init() {
registerMetaClass(configDir + 'mysql.json',
MT_MYSQL,
'',
);
registerMetaClass(configDir + 'web3.json',
MT_WEB3,
''
);
load();
}
@ -77,7 +81,11 @@ function getMetaList(metaIdx) {
}
function getServerConf() {
return getMetaByKey(MT_WEB3SERVEWR, '0');
return getMetaByKey(MT_WEB3SERVER, '0');
}
function getWeb3Conf() {
return getMetaByKey(MT_WEB3, '0');
}
function getMysqlConf() {
@ -93,17 +101,18 @@ function getContractByName(name) {
}
function getUserAddress() {
return getServerConf()['user_address'];
return getWeb3Conf()['user_address'];
}
function getWalletAccount() {
return getServerConf()['wallet_account'];
return getWeb3Conf()['wallet_account'];
}
exports.init = init;
exports.getMetaByKey = getMetaByKey;
exports.getMetaList = getMetaList;
exports.getServerConf = getServerConf;
exports.getWeb3Conf = getWeb3Conf;
exports.getMysqlConf = getMysqlConf;
exports.getContracts = getContracts;
exports.getContractByName = getContractByName;