def keosd_start(): if not config.keosd_wallet_dir(raise_error=False): utils.spawn([config.keosd_exe()]) while True: time.sleep(1) if config.keosd_wallet_dir(raise_error=False): break
def keosd_start(): if not config.keosd_wallet_dir(raise_error=False): subprocess.Popen(config.keosd_exe(), stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True) while True: time.sleep(1) if config.keosd_wallet_dir(raise_error=False): break
def wallet_json_read(): try: with open(config.keosd_wallet_dir() + setup.password_map, "r") \ as f: return json.load(f) except: return {}
def clear_testnet_cache(verbosity=None): ''' Remove wallet files associated with the current testnet. ''' if not setup.file_prefix(): return logger.TRACE(''' Removing testnet cache for prefix `{}` '''.format(setup.file_prefix())) kill_keosd() # otherwise the manager may protects the wallet files dir = config.keosd_wallet_dir() files = os.listdir(dir) try: for file in files: if file.startswith(setup.file_prefix()): os.remove(os.path.join(dir, file)) except Exception as e: raise errors.Error(''' Cannot remove testnet cache. The error message is: {} '''.format(str(e))) logger.TRACE(''' Testnet cache successfully removed. ''')
def wallets(): directory = os.fsencode(config.keosd_wallet_dir()) retval = [] for file in os.listdir(directory): filename = os.fsdecode(file) if filename.endswith(_file_ext): retval.append(filename) return retval
def __init__(self, name=None, password="", verbosity=None, file=False): cleos.set_local_nodeos_address_if_none() if name is None: name = setup.wallet_default_name else: name = setup.file_prefix() + name if not self.wallet is None: raise errors.Error(''' It can be only one ``Wallet`` object in the script; there is one named ``{}``. '''.format(wallet.name)) return self.wallet_dir = config.keosd_wallet_dir() logger.INFO(''' * Wallet name is ``{}``, wallet directory is {}. '''.format(name, self.wallet_dir)) if not password: # look for password: passwords = wallet_json_read() if name in passwords: password = passwords[name] logger.INFO( ''' The password is restored from the file: {} '''.format( os.path.join(self.wallet_dir, setup.password_map)), verbosity) cleos.WalletCreate.__init__(self, name, password, is_verbose=False) if self.is_created: # new password logger.INFO( ''' * Created wallet ``{}``. '''.format(self.name), verbosity) ############################################################################### # TO DO: detect live node!!!!!!!!!! if manager.is_local_testnet() or file or True: ############################################################################### password_map = wallet_json_read() password_map[name] = self.password wallet_json_write(password_map) logger.INFO( ''' * Password is saved to the file ``{}`` in the wallet directory. '''.format(setup.password_map), verbosity) else: logger.OUT(self.out_msg) else: logger.TRACE(''' Opened wallet ``{}`` '''.format(self.name))
def account_map(logger=None): '''Return json account map Attempt to open the account map file named ``setup.account_map``, located in the wallet directory ``config.keosd_wallet_dir()``, to return its json contents. If the file does not exist, return an empty json. If the file is corrupted, offer editing the file with the ``nano`` linux editor. Return ``None`` if the the offer is rejected. ''' wallet_dir_ = config.keosd_wallet_dir(raise_error=False) if not wallet_dir_: return {} path = os.path.join(wallet_dir_, setup.account_map) while True: try: # whether the setup map file exists: with open(path, "r") as input_file: return json.load(input_file) except Exception as e: if isinstance(e, FileNotFoundError): return {} else: logger.OUT(''' The account mapping file is misformed. The error message is: {} Do you want to edit the file? '''.format(str(e))) answer = input("y/n <<< ") if answer == "y": edit_account_map() continue else: raise errors.Error(''' Use the function 'efman.edit_account_map(text_editor="nano")' or the corresponding method of any object of the 'eosfactory.wallet.Wallet` class to edit the file. ''') return None
def read_map(file_name, text_editor="nano"): '''Return json account map Attempt to open the account map file named ``setup.account_map``, located in the wallet directory ``config.keosd_wallet_dir()``, to return its json contents. If the file does not exist, return an empty json. If the file is corrupted, offer editing the file with the ``nano`` linux editor. Return ``None`` if the the offer is rejected. ''' wallet_dir_ = config.keosd_wallet_dir() path = os.path.join(wallet_dir_, file_name) while True: try: # whether the setup map file exists: with open(path, "r") as input_file: return json.load(input_file) except Exception as e: if isinstance(e, FileNotFoundError): return {} else: raise errors.Error(''' The json file {} is misformed. The error message is: {} Do you want to edit the file? '''.format(str(path), str(e)), translate=False) answer = input("y/n <<< ") if answer == "y": utils.spawn([text_editor, path]) continue else: raise errors.Error(''' Use the function 'manager.edit_account_map(text_editor="nano")' to edit the file. ''', translate=False) return None
def wallet_json_write(wallet_json): with open(config.keosd_wallet_dir() + setup.password_map, "w+") as out: json.dump(wallet_json, out)
def edit_map(file_name, text_editor="nano"): import subprocess subprocess.run([text_editor, os.path.join( config.keosd_wallet_dir(), file_name)]) read_map(file_name, text_editor)
def save_map(map, file_name): map = json.dumps(map, indent=3, sort_keys=True) with open(os.path.join(config.keosd_wallet_dir(), file_name), "w") as out: out.write(map)
def edit_map(file_name, text_editor="nano"): utils.spawn( [text_editor, os.path.join(config.keosd_wallet_dir(), file_name)]) read_map(file_name, text_editor)
def get_keosd_wallet_dir(): ''' Get the directory of the `nodeos` local wallet. ''' return config.keosd_wallet_dir()
def wallet_file(name): return config.keosd_wallet_dir() + name + _file_ext