async def init(self): """ Load raw json config """ self.full_config = copy.deepcopy(json_store.raw_config) self.sol_config = copy.deepcopy(json_store.raw_config) utils.success_msg('config initialized')
async def fetch_jars(self, version): """ get release url """ url = JAVA_LITETOKENS_RELEASES_URL if version == 'lastest': url += 'Odyssey-v' + JAVA_LITETOKENS_LASTEST_VERSION elif '3.1.3' <= version <= '3.1.3': url += 'Odyssey-v' + version self.source_full_jar = 'java-litetokens.jar' elif '3.2.0' <= version <= '3.2.10': url += 'Odyssey-v' + version else: utils.error_msg('version: ' + version + ' not supported') utils.info_msg('current support versions: 3.1.3, 3.2, 3.2.1') exit() """ download """ utils.progress_msg('Downloading full-node jar from released build') await utils.download(self.source_full_jar, url) utils.success_msg('.jar file of Fullnode is successfully downloaded') utils.progress_msg('Downloading solidity-node jar from released build') await utils.download(self.source_sol_jar, url) utils.success_msg('.jar file of Soliditynode is successfully downloaded')
async def stop(self, pid): try: subprocess.Popen(["kill", "-15", pid]) except OSError as err: utils.warning_msg('OSError -' + str(err)) else: await self.nodes_list('', int(pid), 'remove') utils.success_msg('process: ' + pid + ' is shut down')
async def run(self, node_type): pid = await self.start(node_type) utils.success_msg('node running at pid:') utils.msg(str(pid)) utils.info_msg('To stop this node:') utils.msg('litetokens-cli stop --pid ' + str(pid)) utils.info_msg('To check node running details:') utils.msg('litetokens-cli status --node ' + str(pid)) await self.nodes_list(node_type, pid, 'add')
async def set_http_port(self, port_num, node_type): if node_type == 'full': self.full_config[' node'][' http'][' fullNodePort'] = port_num utils.success_msg('full-node http request set to listen: ') utils.msg(LOCAL_HOST + str(port_num)) elif node_type == 'sol': self.sol_config[' node'][' http'][' solidityPort'] = port_num utils.success_msg('solidity-node request set to listen: ') utils.msg(LOCAL_HOST + str(port_num)) else: utils.warning_msg('wrong node_type')
async def set_db_version(self, enablememdb): if enablememdb == 'disable' or enablememdb == '0' or enablememdb == 'False': # enablememdb = False self.full_config[' storage'][' db.version'] = 1 utils.success_msg('Enable in memeory db:') utils.msg('False') else: # enablememdb = True self.full_config[' storage'][' db.version'] = 2 utils.success_msg('Enable in memeory db:') utils.msg('True')
async def set_rpc_port(self, port_num, node_type): if node_type == 'full': self.full_config[' node'][' rpc'][' port'] = port_num self.sol_config[' node'][' trustNode'] = LOCAL_HOST + str(port_num) utils.success_msg('full-node rpc request set to listen: ') utils.msg(LOCAL_HOST + str(port_num)) elif node_type == 'sol': self.sol_config[' node'][' rpc'][' port'] = port_num utils.success_msg('solidity-node rpc request set to listen: ') utils.msg(LOCAL_HOST + str(port_num)) else: utils.warning_msg('wrong node_type')
def create_dirs(self): path = self.root_path try: os.mkdir(path + NODES_DIR) os.mkdir(path + NODES_DIR + FULL_NODE_DIR) os.mkdir(path + NODES_DIR + SOLIDITY_NODE_DIR) except OSError as err: utils.warnning_msg('OS Warning -' + str(err)) else: utils.success_msg('Folders are created:') utils.msg(path + '/ ') utils.msg('└──' + NODES_DIR) utils.msg(' ├──' + FULL_NODE_DIR) utils.msg(' └──' + SOLIDITY_NODE_DIR)
async def export(self): """ Export properties config file """ phrase = utils.Phrase() _target_file_path_full = self.root_path + NODES_DIR + FULL_NODE_DIR + FULL_CONFIG phrase.store_json2properties_to_file(self.full_config, _target_file_path_full) utils.success_msg('fullnode config file exported to: ') utils.msg(_target_file_path_full) _target_file_path_sol = self.root_path + NODES_DIR + SOLIDITY_NODE_DIR + SOL_CONFIG phrase.store_json2properties_to_file(self.sol_config, _target_file_path_sol) utils.success_msg('soliditynode config file exported to: ') utils.msg(_target_file_path_sol)
async def set_net_type(self, net_type): # msg utils.success_msg('net type set to: ') utils.msg(net_type) # P2P verison if net_type == 'main': self.full_config[' node'][' p2p'][' version'] = MAINNET_P2P_VERSION self.sol_config[' node'][' p2p'][' version'] = MAINNET_P2P_VERSION if net_type == 'private': self.full_config[' node'][' p2p'][ ' version'] = PRIVATENET_P2P_VERSION self.sol_config[' node'][' p2p'][ ' version'] = PRIVATENET_P2P_VERSION # committee if net_type == 'main': self.full_config[' committee'][ ' allowCreationOfContracts'] = MAINNET_ALLOW_CREATION_OF_CONTRACTS self.sol_config[' committee'][ ' allowCreationOfContracts'] = MAINNET_ALLOW_CREATION_OF_CONTRACTS if net_type == 'private': self.full_config[' committee'][ ' allowCreationOfContracts'] = PRIVATENET_ALLOW_CREATION_OF_CONTRACTS self.sol_config[' committee'][ ' allowCreationOfContracts'] = PRIVATENET_ALLOW_CREATION_OF_CONTRACTS # vm if net_type == 'main': self.full_config[' vm'][' supportConstant'] = 'false' self.sol_config[' vm'][' supportConstant'] = 'false' if net_type == 'private': self.full_config[' vm'][' supportConstant'] = 'true' self.sol_config[' vm'][' supportConstant'] = 'true' # block if net_type == 'main': self.full_config[' block'][' needSyncCheck'] = 'true' self.sol_config[' block'][' needSyncCheck'] = 'true' if net_type == 'private': self.full_config[' block'][' needSyncCheck'] = 'false' self.sol_config[' block'][' needSyncCheck'] = 'false' # localwitness if net_type == 'main': self.full_config[' localwitness'] = [] self.sol_config[' localwitness'] = [] if net_type == 'private': self.full_config[' localwitness'] = [ 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0' ] self.sol_config[' localwitness'] = [ 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0' ] # genesis.block if net_type == 'main': pass # self.full_config[' genesis.block'][' witnesses'] = # self.sol_config[' genesis.block'][' witnesses'] = if net_type == 'private': self.full_config[' genesis.block'][' witnesses'] = [{ ' address': 'TPL66VK2gCXNCD7EJg9pgJRfqcRazjhUZY', ' url': 'http://litetokensstudio.com', ' voteCount': 10000 }] self.sol_config[' genesis.block'][' witnesses'] = [{ ' address': 'TPL66VK2gCXNCD7EJg9pgJRfqcRazjhUZY', ' url': 'http://litetokensstudio.com', ' voteCount': 10000 }]
async def move_jars(self): shutil.move(self.root_path + '/' + self.source_full_jar, self.root_path + NODES_DIR + FULL_NODE_DIR + FULL_NODE_JAR) shutil.move(self.root_path + '/' + self.source_sol_jar, self.root_path + NODES_DIR + SOLIDITY_NODE_DIR + SOLIDITY_NODE_JAR) utils.success_msg('initialization finished')