async def _start( self, fingerprint: Optional[int] = None, new_wallet: bool = False, backup_file: Optional[Path] = None, skip_backup_import: bool = False, ) -> bool: private_key = self.get_key_for_fingerprint(fingerprint) if private_key is None: return False db_path_key_suffix = str(private_key.get_g1().get_fingerprint()) path = path_from_root(self.root_path, f"{self.config['database_path']}-{db_path_key_suffix}") mkdir(path.parent) self.wallet_state_manager = await WalletStateManager.create(private_key, self.config, path, self.constants) self.wsm_close_task = None assert self.wallet_state_manager is not None backup_settings: BackupInitialized = self.wallet_state_manager.user_settings.get_backup_settings() if backup_settings.user_initialized is False: if new_wallet is True: await self.wallet_state_manager.user_settings.user_created_new_wallet() self.wallet_state_manager.new_wallet = True elif skip_backup_import is True: await self.wallet_state_manager.user_settings.user_skipped_backup_import() elif backup_file is not None: await self.wallet_state_manager.import_backup_info(backup_file) else: self.backup_initialized = False await self.wallet_state_manager.close_all_stores() self.wallet_state_manager = None return False self.backup_initialized = True if backup_file is not None: json_dict = open_backup_file(backup_file, self.wallet_state_manager.private_key) if "start_height" in json_dict["data"]: start_height = json_dict["data"]["start_height"] self.config["starting_height"] = max(0, start_height - self.config["start_height_buffer"]) else: self.config["starting_height"] = 0 else: self.config["starting_height"] = 0 if self.state_changed_callback is not None: self.wallet_state_manager.set_callback(self.state_changed_callback) self.wallet_state_manager.set_pending_callback(self._pending_tx_handler) self._shut_down = False self.peer_task = asyncio.create_task(self._periodically_check_full_node()) self.sync_event = asyncio.Event() self.sync_task = asyncio.create_task(self.sync_job()) self.log.info("self.sync_job") self.logged_in_fingerprint = fingerprint return True
async def import_backup_info(self, file_path): json_dict = open_backup_file(file_path, self.private_key) wallet_list_json = json_dict["data"]["wallet_list"] for wallet_info in wallet_list_json: await self.user_store.create_wallet( wallet_info["name"], wallet_info["type"], wallet_info["data"], wallet_info["id"], ) await self.load_wallets() await self.user_settings.user_imported_backup() await self.create_more_puzzle_hashes(from_zero=True)