const util = require('util'); const Web3 = require('web3'); const utils = require('j7/utils'); const event = require('j7/event'); const sync = require("j7/sync"); const log = require("j7/log"); const metaFactory = require('./metadata/factory'); const C = require("./C"); class BlockChain { constructor() { this.netId = 0; } async initInstance(user, address, jsonUrl) { const json = utils.readJsonFromFile(jsonUrl); return new this.web3.eth.Contract( json.abi, address, { from: user } ); } async init() { this.web3 = new Web3(metaFactory.getWeb3Conf()['block_server']); this.web3.eth.handleRevert = true; for (const data of metaFactory.getContracts()) { this[`${data.name}Instance`] = await this.initInstance (metaFactory.getUserAddress(), data.address, data.json); } event.emitEvent(C.BC_INITIALIZED_EVENT); } async getNetId() { return await this.web3.eth.getChainId(); } } module.exports = new BlockChain();