예제 #1
0
    def restore_accounts(self):
        '''
        '''
        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 shell.account import create_account
                    create_account(object_name,
                                   name,
                                   restore=True,
                                   verbosity=None)
                except errors.AccountDoesNotExistError:
                    pass

            manager.save_account_map(new_map)
        else:
            logger.INFO('''
                 * The wallet is empty.
            ''')
예제 #2
0
    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")'
            or the corresponding method of any object of the 'pyteos.wallet.Wallet` 
            class to edit the file.
                    ''')
            else:
                break
예제 #3
0
    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))
예제 #4
0
    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
예제 #5
0
 def delete_globals(self):
     account_map = manager.account_map()
     for name, object_name in account_map.items():
         del Wallet.globals[object_name]