def update_for_platon(bin_path): platon_cfg_path = os.path.join(g_dict_dir_config["conf_dir"], 'platon.cfg') if not os.path.exists(platon_cfg_path): cust_print('The node is not initialized, please check!:{}'.format( g_current_dir), fg='r') sys.exit(1) platon_cfg = get_local_platon_cfg() # 进程是否在运行 pid = get_pid(PLATON_NAME, int(platon_cfg['rpcport'])) if pid: confirm = input( 'PlatON is running, rpc port:{}, Whether or not to continue? [Y|y/N|n]: ' .format(int(platon_cfg['rpcport']))) # 关闭进程 if confirm == 'Y' or confirm == 'y': shutdown_node() else: cust_print( 'Failed to upgrade platon node!:{}'.format(g_current_dir), fg='r') return # 开始下载,替换 # download_file(download_path, g_dict_dir_config["platon_dir"]) # 已下载到本地,直接替换 old_bin_dir = os.path.join(g_dict_dir_config["platon_dir"], PLATON_NAME) remove(old_bin_dir) shutil.move(bin_path, g_dict_dir_config["platon_dir"]) # 重启节点 startup_node()
def generateNodeKey(keyPath): """ this is node submodule generateNodeKey command. """ if not os.path.exists(keyPath): cust_print("invalid path:{}".format(keyPath), bg='r') return nodeIdPath = os.path.join(keyPath, 'nodeid') nodeKeyPath = os.path.join(keyPath, 'nodekey') if os.path.exists(nodeIdPath) or os.path.exists(nodeKeyPath): confirm = input( 'The key file already exists in the directory. Do you want to overwrite it? [Y|y/N|n]: ' ) if confirm != 'Y' and confirm != 'y': cust_print('Generate node key fail!', fg='r') return platon_cfg_path = os.path.join(g_dict_dir_config["conf_dir"], 'platon.cfg') hrp = 'lat' if os.path.exists(platon_cfg_path): platon_cfg = get_local_platon_cfg() hrp = platon_cfg['hrp'] if generate_nodekey(keyPath, hrp): cust_print('Generate node key success:{}.'.format(keyPath), fg='y') else: cust_print('Generate node key fail!', fg='r')
def rollback_for_platon(dataPath): platon_cfg_path = os.path.join(g_dict_dir_config["conf_dir"], 'platon.cfg') if not os.path.exists(platon_cfg_path): cust_print('The node is not initialized, please check!:{}'.format(g_current_dir), fg='r') sys.exit(1) platon_cfg = get_local_platon_cfg() # 进程是否在运行 pid = get_pid(PLATON_NAME, int(platon_cfg['rpcport'])) if pid: confirm = input('PlatON is running, rpc port:{}, Whether or not to continue? [Y|y/N|n]: '. format(int(platon_cfg['rpcport']))) # 关闭进程 if confirm == 'Y' or confirm == 'y': shutdown_node() else: cust_print('Failed to rollback platon data!:{}'.format(g_current_dir), fg='r') return confirm = input('Current CLI workspace directory:{}, do you want to continue? [Y|y/N|n]: '. format(g_current_dir)) # 关闭进程 if confirm != 'Y' and confirm != 'y': cust_print('Failed to rollback platon data!:{}'.format(g_current_dir), fg='r') return cust_print('start to rollback node data...:{}'.format(g_current_dir), fg='g') # delete data dir of platon old_data_dir = os.path.join(g_dict_dir_config["platon_dir"], "data") remove(old_data_dir) shutil.move(dataPath, old_data_dir) # 重启节点 startup_node() cust_print("Rollback success...", bg='y')
def info(): """ this is node submodule info command. """ platon_cfg = get_local_platon_cfg() pid = get_pid(PLATON_NAME, int(platon_cfg['rpcport'])) if not pid: cust_print( "The node is not started, rpc port:{}, please check!...".format( int(platon_cfg['rpcport'])), fg='r') return url = "http://{}:{}".format(platon_cfg["rpcaddr"], platon_cfg["rpcport"]) w3 = Web3(HTTPProvider(url)) # 获取节点信息 admin = Admin(w3) nodeId = admin.nodeInfo.id cust_print("NodeId:{}".format(nodeId), fg='g') # NodeName NodeName = "" cust_print("NodeName:{}".format(NodeName), fg='g') # BenefitAddress BenefitAddress = "" cust_print("BenefitAddress:{}".format(BenefitAddress), fg='g')
def move(original, target, movetype): """ this is node submodule move command. """ if not os.path.exists(original): cust_print("invalid original path: {}".format(original), fg='r') return original_cnf_path = "{}/{}/{}".format(original, 'config', 'platon.cfg') org_cnf = get_local_platon_cfg(original_cnf_path) if not os.path.exists(target): cust_print("invalid target path: {}".format(target), fg='r') return target_cnf_path = "{}/{}/{}".format(target, 'config', 'platon.cfg') tag_cnf = get_local_platon_cfg(target_cnf_path) # 源节点 if not is_continue(org_cnf, original): return # 目标节点 if not is_continue(tag_cnf, target): return if "all" == movetype or "key" == movetype: cust_print( "Start to migrating nodekey and blskey: {}.".format(original), fg='g') for key in ['nodeKey', 'blsKey']: key_path = "{}/{}/{}".format(original, "platon", key) des_path = "{}/{}/{}".format(target, "platon", key) remove(des_path) shutil.move(key_path, des_path) cust_print('migrating key successfully.', fg='g') if "all" == movetype or "data" == movetype: cust_print("Start to migrating block data: {}.".format(original), fg='g') src_path = os.path.join(original, "data") des_path = os.path.join(target, "data") remove(des_path) shutil.move(src_path, des_path) cust_print('migrating block data successfully.', fg='g')
def check(): """ this is node submodule check command. """ platon_cfg_path = os.path.join(g_dict_dir_config["conf_dir"], 'platon.cfg') platon_cfg = get_local_platon_cfg(platon_cfg_path) url = "http://{}:{}".format(platon_cfg["rpcaddr"], platon_cfg["rpcport"]) cust_print("connect node: {}".format(url), fg='g') hrp = platon_cfg["hrp"] cust_print("get hrp:{} from platon_cfg file: {}".format( hrp, platon_cfg_path), fg='g') # get platon version on chain try: ret = platon_call(url, dict_gov_contractAddr[hrp]) platon_version = ret["Ret"] cust_print("platon version on chain: {}".format( formatVersion(platon_version)), fg='g') # get platon current version current_version = get_platon_version() cust_print( "platon current version on local: {}".format(current_version), fg='g') if platon_version > versionToNum(current_version): cust_print( "The current version is not the latest version. It is recommended that the user change the version " "of platon. Please provide the latest download address according to the official and use the " "command: platoncli node upgrade --path.", fg='r', level="warning") else: cust_print( "The current binary is the latest version and does not need to be updated: {}" .format(g_current_dir), fg='g') except Exception as e: cust_print("Failed to get version: {}".format(e), fg='r') sys.exit(1)
def blockinput(zipFile): """ this is node submodule blockinput command. """ if not os.path.exists(zipFile) or not zipFile.endswith(".zip"): cust_print( "Invalid address, please enter zip file path: {}".format(zipFile), fg='r') return platon_cfg = get_local_platon_cfg() # 进程是否在运行 pid = get_pid(PLATON_NAME, int(platon_cfg['rpcport'])) if pid: confirm = input( 'PlatON is running, rpc port:{}, Whether or not to continue? [Y|y/N|n]: ' .format(int(platon_cfg['rpcport']))) # 关闭进程 if confirm == 'Y' or confirm == 'y': shutdown_node() else: cust_print('Failed to input block data!:{}'.format(g_current_dir), fg='r') return # node is deploy data_dir = os.path.join(g_dict_dir_config["platon_dir"], "data") if os.path.exists(data_dir): # delete old chain data cust_print("start to remove old chain data: {}.".format(data_dir), fg='g') remove(data_dir) cust_print("remove old chain data succeed.", fg='g') cust_print('start to input the block data:{}.'.format(zipFile), fg='g') # unzip un_zip(zipFile, g_dict_dir_config["platon_dir"]) cust_print('input the block data successfully.', fg='g')
def blockexport(savePath): """ this is node submodule blockexport command. """ if not os.path.exists(savePath): cust_print("invalid path: {}".format(savePath), fg='r') return # 节点数据 data_dir = os.path.join(g_dict_dir_config["platon_dir"], "data") if not os.path.exists(data_dir): cust_print("Data file not found: {}".format(data_dir), fg='r') return platon_cfg = get_local_platon_cfg() # 进程是否在运行 pid = get_pid(PLATON_NAME, int(platon_cfg['rpcport'])) if pid: confirm = input( 'PlatON is running, rpc port:{}, Whether or not to continue? [Y|y/N|n]: ' .format(int(platon_cfg['rpcport']))) # 关闭进程 if confirm == 'Y' or confirm == 'y': shutdown_node() else: cust_print('Failed to export block data!:{}'.format(g_current_dir), fg='r') return cust_print('Start exporting the block data.', fg='g') # make zip zip_name = "data_" + get_time_stamp() + ".zip" zip_path = os.path.join(savePath, zip_name) make_zip(data_dir, zip_path) cust_print('Export block data successfully.', fg='g')
def reset_node(clearFlag): platon_cfg_path = os.path.join(g_dict_dir_config["conf_dir"], 'platon.cfg') if not os.path.exists(platon_cfg_path): cust_print('The node is not initialized, please check!:{}'.format(g_current_dir), fg='r') sys.exit(1) platon_cfg = get_local_platon_cfg() hrp = platon_cfg['hrp'] network_type = "PlatON" if 'atp' == hrp or 'atx': network_type = "Alaya" # 判断是否已安装 if not check_install_valid(network_type): cust_print('Node binary not installed, please check!:{}'.format(g_current_dir), fg='r') sys.exit(1) # 进程是否在运行 pid = get_pid(PLATON_NAME, int(platon_cfg['rpcport'])) if pid: confirm = input('PlatON is running, rpc port:{}, Whether or not to continue? [Y|y/N|n]: '. format(int(platon_cfg['rpcport']))) # 关闭进程 if confirm == 'Y' or confirm == 'y': shutdown_node() else: cust_print('Failed to reset platon node!:{}'.format(g_current_dir), fg='r') return # 再次提示 confirm = input('Whether to consider data backup? [Y|y/N|n]: ') if confirm == 'Y' or confirm == 'y': cust_print('Please do a manual backup of the data you need.', fg='g') return # 删除data数据 data_path = os.path.join(g_dict_dir_config["platon_dir"], "data") if os.path.exists(data_path): remove(data_path) cust_print('The data directory was deleted successfully:{}.'.format(data_path), fg='g') if clearFlag: # 删除key数据 nodeKey_path = g_dict_dir_config["nodekey_dir"] blsKey_path = g_dict_dir_config["blskey_dir"] if os.path.exists(nodeKey_path): remove(nodeKey_path) cust_print('The nodekey directory was deleted successfully:{}.'.format(nodeKey_path), fg='g') if os.path.exists(blsKey_path): remove(blsKey_path) cust_print('The blskey directory was deleted successfully:{}.'.format(blsKey_path), fg='g') # 删除log日志 log_path = platon_cfg['logfile'] if os.path.exists(log_path): remove(log_path) cust_print('The log file was deleted successfully:{}.'.format(log_path), fg='g') try: cust_print('Reset platon node successfully.', fg='g') except Exception as e: cust_print('Unable to reset platon node: {}'.format(e), fg='r')