예제 #1
0
def is_notrunningnotkeosd_error(cleos_object):

    is_error = not setup.is_use_keosd() and not node_is_running()
    if is_error:
        cleos_object.error = True
        cleos_object.err_msg = heredoc("""
Cannot use the local node Wallet Manager if the node is not running.
            """)
    return is_error
예제 #2
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
예제 #3
0
    def __init__(
            self, name="", owner_key_public="", active_key_public="", 
            is_verbose=1, verbosity=None):

        is_verbose = self.verify_is_verbose(verbosity, is_verbose)
    
        self.EOSF_TRACE("""
            ######### 
            Get master account.
            """)

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

        AccountEosio.__init__(self, 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 cleos.is_notrunningnotkeosd_error(self):
            self.ERROR(self.err_msg)
            return

        if self.is_local_testnet():
            return

        self.account_info = "The account is not opened yet!"
        self.DEBUG("It is not the local testnet.")
        #cleos.set_wallet_url_arg(node, "")

        # not local testnet:
        if not owner_key_public: # print data for registration
            if not name: 
                self.name = cleos.account_name()
            else:
                self.name = name

            self.owner_key = cleos.CreateKey("owner", is_verbose=0)
            self.active_key = cleos.CreateKey("active", is_verbose=0)
            self.OUT("""
                Use the following data to register a new account on a public testnet:
                Accout Name: {}
                Owner Public Key: {}
                Owner Private Key: {}
                Active Public Key: {}
                Active Private Key: {}
                """.format(
                    self.name,
                    self.owner_key.key_public, self.owner_key.key_private,
                    self.active_key.key_public, self.active_key.key_private
                    ))
        else: # restore the master account
            self.name = name
            self.owner_key = cleos.CreateKey("owner", owner_key_public, is_verbose=0)
            if not active_key_public:
                self.active_key = owner_key
            else:
                self.active_key = cleos.CreateKey(
                    "active", active_key_public, is_verbose=0)
            account_ = cleos.GetAccount(name, is_verbose=-1)
            if not account_.error:
                self.account_info = str(account_)
예제 #4
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_
예제 #5
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)