Ejemplo n.º 1
0
    def restore_accounts(self, namespace):
        account_names = set() # accounts in wallets
        keys = cleos.WalletKeys(is_verbose=0).json

        for key in keys[""]:
            accounts = cleos.GetAccounts(key, is_verbose=0)
            for acc in accounts.json["account_names"]:
                account_names.add(acc)

        if self.is_verbose:
            print("Restored accounts as global variables:")

        restored = dict()
        if len(account_names) > 0:
            if setup.is_use_keosd():
                wallet_dir_ = os.path.expandvars(teos.get_keosd_wallet_dir())
            else:
                wallet_dir_ = teos.get_node_wallet_dir()
            try:
                with open(wallet_dir_ + setup.account_map, "r") as input:    
                    account_map = json.load(input)
            except:
                account_map = {}
            
            object_names = set()

            for name in account_names:
                try:
                    object_name = account_map[name]
                    if object_name in object_names:
                        object_name = object_name + "_" + name
                except:
                    object_name = name
                object_names.add(object_name)

                if object_name:
                    if self.is_verbose:
                        print("     {0} ({1})".format(object_name, name))
                    restored[object_name] = account(name, restore=True)
        else:
            if self.is_verbose:
                print("     empty list")

        namespace.update(restored)
        return restored
Ejemplo n.º 2
0
def wallet_dir():
    if setup.is_use_keosd():
        wallet_dir_ = os.path.expandvars(teos.get_keosd_wallet_dir())
    else:
        wallet_dir_ = teos.get_node_wallet_dir()
    return wallet_dir_
Ejemplo n.º 3
0
    def __init__(
                self, name="default", password="", is_verbose=1,
                verbosity=None):

        is_verbose = self.verify_is_verbose(verbosity, is_verbose)

        if not setup.is_use_keosd(): # look for password:
            self.wallet_dir_ = teos.get_node_wallet_dir()
        else:
            self.wallet_dir_ = os.path.expandvars(teos.get_keosd_wallet_dir())
        
        if setup.is_use_keosd():
            self.EOSF_TRACE("""
                ######### 
                Create a `Wallet` object with the KEOSD Wallet Manager.
                """)
        else:
            self.EOSF_TRACE("""
                ######### 
                Create a `Wallet` object with the NODEOS wallet plugin.
                """)

        if cleos.is_notrunningnotkeosd_error(self):
            self.ERROR(self.err_msg)
            return

        if not password and not setup.is_use_keosd(): # look for password:
            try:
                with open(self.wallet_dir_ + setup.password_map, "r") \
                        as input:    
                    password_map = json.load(input)
                    password = password_map[name]

                self.EOSF("""
                    Pasword is restored from the file:
                    {}
                    """.format(self.wallet_dir_ + setup.password_map))
            except:
                pass

        self.EOSF("""
            Wallet directory is {}
            """.format(self.wallet_dir_))

        self.DEBUG("""
            Local node is running: {}
            """.format(cleos.node_is_running()))

        cleos.WalletCreate.__init__(self, name, password, is_verbose)

        self.DEBUG("""
            Name is `{}`
            Wallet URL is {}
            Use keosd status is {}
            self._out:
            {}
            self.err_msg:
            {}
            """.format(
                self.name,
                cleos.wallet_url(), setup.is_use_keosd(),
                self._out,
                self.err_msg
                ))
            
        if not self.error:
            if not setup.is_use_keosd(): 
                try:
                    with open(self.wallet_dir_ + setup.password_map, "r") \
                            as input:
                        password_map = json.load(input)
                except:
                    password_map = {}
                password_map[name] = self.password

                with open(self.wallet_dir_ + setup.password_map, "w+") \
                        as out:
                    json.dump(password_map, out)

                if not password: # new password
                    self.EOSF_TRACE("""
                        Created wallet `{}` with the local testnet.
                        Password is saved to the file {} in the wallet directory.
                        """.format(self.name, setup.password_map)
                    )

                else: # password taken from file
                    self.EOSF_TRACE("""Opened wallet `{}`.""".format(self.name))

            else: # KEOSD Wallet Manager
                if not password: # new password
                    self.EOSF_TRACE("""
                        Created wallet `{}` with the `keosd` Wallet Manager.
                        Save password to use in the future to unlock this wallet.
                        Without password imported keys will not be retrievable.
                        {}
                        """.format(self.name, self.password)
                    )

                else: # password introduced
                    self.EOSF_TRACE("""
                        Opened wallet {}
                        """.format(self.name))

        else: # wallet.error:
            if "Wallet already exists" in self.err_msg:
                self.ERROR("Wallet `{}` already exists.".format(self.name))
                return
            if "Invalid wallet password" in self.err_msg:
                self.ERROR("Invalid password.")
                return

            self.ERROR(self.err_msg)