def __init__(self, up_config: dict): self.tag = util.tag_from_path(__file__, Controller.__name__) # set config self.up_config = up_config self.root_path = os.path.abspath( os.path.join(os.path.abspath(__file__), "../../../")) self.config = util.read_config_file( os.path.join(self.root_path, "config.json")) self.node_types = ["ela", "arbiter", "did", "token", "neo", "geth"] self.reset_config(up_config) self.params = Parameter(self.config, self.root_path) self.check_params() self.env_manager = EnvManager() self.keystore_manager = KeyStoreManager(self.params) self.node_manager = NodeManager(self.params, self.env_manager, self.keystore_manager) self.tx_manager = TransactionManager(self.node_manager) # init tap amount and register amount(unit: ELA) self.tap_amount = 20000000 self.register_amount = 6000 self.node_amount = 5000 self.backup_amount = 5000 # necessary keystore self.foundation_account = self.keystore_manager.foundation_account self.tap_account = self.keystore_manager.tap_account self.init_for_testing() self.later_nodes = self.node_manager.ela_nodes[( self.params.ela_params.number - self.params.ela_params.later_start_number + 1):] self.dpos_votes_dict = dict()
def __init__(self, arg, password="******"): self._password = password self._valid = False self._password_double_hash = keytool.sha256_hash( str.encode(self._password), 2) self._password_thrice_hash = keytool.sha256_hash( str.encode(self._password), 3) self._accounts_data_list = list() self._sub_accounts_list = list() if isinstance(arg, Account): self._main_account = arg self._iv = keytool.create_urandom(16) self._master_key = keytool.create_urandom(32) self._master_key_encrypted = keytool.aes_encrypt( self._master_key, self._password_double_hash, self._iv) self._accounts_data_list.append( self._create_account_data(self._main_account, self.MAIN_ACCOUNT)) elif isinstance(arg, str): self._store_dict = util.read_config_file(arg) if not self._check_password(): return if "IV" not in self._store_dict.keys(): return self._iv = bytes.fromhex(self._get_iv()) self._master_key_encrypted = bytes.fromhex( self._get_master_key_encrypted()) self._master_key = self._get_master_key() self._accounts_data_list = self._get_accounts_data() self._main_account = self._get_account(0) self._sub_accounts_list = self._get_sub_accounts() self._valid = True
def _read_key_stores(self, category: str, num: int): dest_path = os.path.join(self.stables_path, category + ".json") if not os.path.exists(dest_path): Logger.error( "{} read key stores failed, dest path {} is not found, exit..." .format(self.tag, dest_path)) time.sleep(1) exit(-1) content_dict = util.read_config_file(dest_path) for i in range(num): private_key_str = content_dict[category + "_" + str(i)]["private_key"] a = Account(private_key_str) self.category_dict[category].append(a) Logger.debug("{} load {} keystore on success !".format( self.tag, category))
def _deploy_nodes(self, category: str, num: int): src_path = os.path.join(self.env_manager.elastos_path, self.env_manager.src_path_dict[category]) if not os.path.exists(src_path): return False Logger.debug("{} src_path: {}".format(self.tag, src_path)) config_path = os.path.join(src_path, "config.json.sample") if os.path.exists(config_path): Logger.debug("{} config.json will generate from the sample".format( self.tag)) config_dict = util.read_config_file(config_path) else: Logger.debug( "{} config.json will generate from the default".format( self.tag)) config_dict = self.env_manager.config_dict[category] global ela_type global temp_dest_dir temp_dest_dir = os.path.join(self.env_manager.test_path, self.env_manager.current_date_time) for i in range(num + 1): if category == "ela" and i == 0: dest_path = os.path.join(temp_dest_dir, category + "_nodes", "miner") ela_type = ElaNode.TYPE_MINER elif category == "ela" and i <= self.params.ela_params.crc_number: dest_path = os.path.join(temp_dest_dir, category + "_nodes", "crc" + str(i)) ela_type = ElaNode.TYPE_CRC elif category == "ela" and i <= self.params.ela_params.crc_number * 3: dest_path = os.path.join(temp_dest_dir, category + "_nodes", "producer" + str(i)) ela_type = ElaNode.TYPE_PRODUCER else: if category is not "ela" and i == 0: continue elif category == "ela": ela_type = ElaNode.TYPE_CANDIDATE dest_path = os.path.join(temp_dest_dir, category + "_nodes", category + str(i)) Logger.debug("{} dest_path: {}".format(self.tag, dest_path)) if not os.path.exists(dest_path): os.makedirs(dest_path) shutil.copy(os.path.join(src_path, category), os.path.join(dest_path, category + str(i))) node = self._init_nodes(category, config_dict, i, dest_path, ela_type) node.reset_config() util.write_config_file(node.config, os.path.join(dest_path, "config.json")) self.nodes_dict[category].append(node) if category == "ela": shutil.copy( os.path.join(self.params.root_path, "datas/stables/node", "node" + str(i) + ".dat"), os.path.join(dest_path, "keystore.dat")) if i == 0 and category == "ela": shutil.copy( os.path.join(self.params.root_path, "datas/stables/special/special0.dat"), os.path.join(dest_path, "foundation.dat")) shutil.copy( os.path.join(self.params.root_path, "datas/stables/special/special1.dat"), os.path.join(dest_path, "miner.dat")) shutil.copy( os.path.join(self.params.root_path, "datas/stables/special/special3.dat"), os.path.join(dest_path, "tap.dat")) if category == "arbiter": if i == 0: continue shutil.copy( os.path.join( self.params.root_path, "datas/stables/arbiter/arbiter" + str(i) + ".dat"), os.path.join(dest_path, "keystore.dat")) return True