def table(account_object, table_name, scope="", binary=False, limit=10, key="", lower="", upper=""): logger.INFO(''' * Table ``{}`` for ``{}`` '''.format(table_name, scope)) result = cleos.GetTable(account_object, table_name, scope, binary, limit, key, lower, upper, is_verbose=False) try: account_map = manager.account_map() scope = account_map[str(scope)] except: pass logger.OUT(result.out_msg) return result
def restore_accounts(self): '''Restore into the global namespace all the account objects represented in the wallet. ''' self.open_unlock() account_map = manager.account_map() new_map = {} wallet_keys = cleos.WalletKeys(is_verbose=0) if len(account_map) > 0: logger.INFO(''' ######### Restore cached account objects: ''') for name, object_name in account_map.items(): try: account_ = cleos.GetAccount(name, is_info=False, is_verbose=False) if account_.owner_key in wallet_keys.json and \ account_.active_key in wallet_keys.json: new_map[name] = object_name from eosfactory.shell.account import create_account create_account(object_name, name, restore=True) except errors.AccountDoesNotExistError: pass manager.save_account_map(new_map) else: logger.INFO(''' * The wallet is empty. ''')
def is_name_taken(self, account_object_name, account_name): '''Check whether the given name is available is a name of an account object. If the name points to an existing account, propese an action that may resolve the conflict. Args: account_object_name (str): The proposed name of a new account object. account_name (str): The EOSIO name of the account mapped with the new account object. Returns: bool: Whether the given name is available is a name of an account object. ''' while True: account_map_json = manager.account_map() if account_map_json is None: return False is_taken = False for name, object_name in account_map_json.items(): if object_name == account_object_name: if not name == account_name: logger.OUT(''' The given account object name ``{}`` points to an existing account, of the name {}, mapped in a file in directory: {} Cannot overwrite it. However, you can free the name by changing the mapping. Do you want to edit the file? '''.format(account_object_name, name, self.wallet_dir)) is_taken = True break if is_taken: temp = None if account_object_name in Wallet.globals: temp = Wallet.globals[account_object_name] del Wallet.globals[account_object_name] answer = input("y/n <<< ") if answer == "y": manager.edit_account_map() continue else: if temp: Wallet.globals[account_object_name] = temp raise errors.Error(''' Use the function 'manager.edit_account_map()' to edit the file. ''') else: break
def delete_globals(self): '''Delete from the global namespace all the account objects restored with the function :func:`restore_accounts`. ''' account_map = manager.account_map() for account_object, object_name in account_map.items(): del Wallet.globals[object_name]
def table( self, table_name, scope="", binary=False, limit=10, lower="", upper="", index="", key_type="", encode_type="", reverse=False, show_payer=False ): '''Retrieve the contents of a database table Args: table (str): The name of the table as specified by the contract abi. scope (str or .interface.Account): The scope within the account in which the table is found. binary (bool): Return the value as BINARY rather than using abi to interpret as JSON. Default is *False*. limit (int): The maximum number of rows to return. Default is 10. lower (str): JSON representation of lower bound value of key, defaults to first. upper (str): JSON representation of upper bound value value of key, defaults to last. index (int or str): Index number, 1 - primary (first), 2 - secondary index (in order defined by multi_index), 3 - third index, etc. Number or name of index can be specified, e.g. 'secondary' or '2'. key_type (str): The key type of --index, primary only supports (i64), all others support (i64, i128, i256, float64, float128, ripemd160, sha256). Special type 'name' indicates an account name. encode_type (str): The encoding type of key_type (i64 , i128 , float64, float128) only support decimal encoding e.g. 'dec'i256 - supports both 'dec' and 'hex', ripemd160 and sha256 is 'hex' only. reverse (bool): Iterate in reverse order. show_payer (bool): Show RAM payer. Returns: :class:`.cleos_set.SetTable` object ''' stop_if_account_is_not_set(self) logger.INFO(''' * Table ``{}`` for ``{}`` '''.format(table_name, scope)) result = cleos_get.GetTable( self, table_name, scope, binary, limit, lower, upper, index, key_type, encode_type, reverse, show_payer, is_verbose=False) try: account_map = manager.account_map() scope = account_map[str(scope)] except: pass logger.OUT(result.out_msg) return result
def table(self, table_name, scope="", binary=False, limit=10, key="", lower="", upper=""): '''Retrieve the contents of a database table Args: scope (str or .interface.Account): The scope within the account in which the table is found. table (str): The name of the table as specified by the contract abi. binary (bool): Return the value as BINARY rather than using abi to interpret as JSON. Default is *False*. limit (int): The maximum number of rows to return. Default is 10. lower (str): JSON representation of lower bound value of key, defaults to first. upper (str): JSON representation of upper bound value value of key, defaults to last. Returns: :class:`.cleos_set.SetTable` object ''' logger.INFO(''' * Table ``{}`` for ``{}`` '''.format(table_name, scope)) result = cleos_get.GetTable(self, table_name, scope, binary, limit, key, lower, upper, is_verbose=False) try: account_map = manager.account_map() scope = account_map[str(scope)] except: pass logger.OUT(result.out_msg) return result
def is_name_taken(self, account_object_name, account_name): while True: account_map_json = manager.account_map(self) if account_map_json is None: return False is_taken = False for name, object_name in account_map_json.items(): if object_name == account_object_name: if not name == account_name: logger.OUT(''' The given account object name ``{}`` points to an existing account, of the name {}, mapped in a file in directory: {} Cannot overwrite it. However, you can free the name by changing the mapping. Do you want to edit the file? '''.format(account_object_name, name, self.wallet_dir)) is_taken = True break if is_taken: temp = None if account_object_name in Wallet.globals: temp = Wallet.globals[account_object_name] del Wallet.globals[account_object_name] answer = input("y/n <<< ") if answer == "y": manager.edit_account_map() continue else: if temp: Wallet.globals[account_object_name] = temp raise errors.Error(''' Use the function 'manager.edit_account_map(text_editor="nano")' to edit the file. ''') else: break
def map_account(self, account_object_name, account_object): ''' ''' if not self.is_name_taken(account_object_name, account_object.name): account_map_json = manager.account_map(self) if account_map_json is None: return account_map_json[account_object.name] = account_object_name with open(self.wallet_dir + setup.account_map, "w") as out: out.write( json.dumps(account_map_json, indent=3, sort_keys=True)) logger.TRACE(''' * Account object ``{}`` stored in the file ``{}`` in the wallet directory: {} '''.format(account_object_name, setup.account_map, self.wallet_dir + setup.account_map))
def delete_globals(self): account_map = manager.account_map() for name, object_name in account_map.items(): del Wallet.globals[object_name]