Esempio n. 1
0
    def _load_coldkey(self):
        keyfile = os.path.expanduser( self.coldkeyfile )
        keyfile = os.path.expanduser(keyfile)

        if not os.path.isfile(keyfile):
            print(colored("coldkeyfile  {} does not exist".format(keyfile), 'red'))
            raise KeyFileError

        if not os.path.isfile(keyfile):
            print(colored("coldkeyfile  {} is not a file".format(keyfile), 'red'))
            raise KeyFileError

        if not os.access(keyfile, os.R_OK):
            print(colored("coldkeyfile  {} is not readable".format(keyfile), 'red'))
            raise KeyFileError

        with open(keyfile, 'rb') as file:
            data = file.read()
            try:
                # Try key load.
                if is_encrypted(data):
                    password = bittensor.utils.Cli.ask_password()
                    print("decrypting key... (this may take a few moments)")
                    data = decrypt_data(password, data)
                self._coldkey = load_keypair_from_data(data)

            except KeyError:
                print(colored("Invalid password", 'red'))
                sys.exit(1)
            except KeyFileError as e:
                print(colored("Keyfile corrupt", 'red'))
                sys.exit(1)

            print(colored("Loaded coldkey: {}".format(self._coldkey.public_key), 'green'))
Esempio n. 2
0
    def _load_hotkey(self) -> bittensor.substrate.Keypair:

        if not os.path.isfile( self.hotkeyfile ):
            print(colored("hotkeyfile  {} does not exist".format( self.hotkeyfile ), 'red'))
            raise KeyFileError

        if not os.path.isfile( self.hotkeyfile ):
            print(colored("hotkeyfile  {} is not a file".format( self.hotkeyfile ), 'red'))
            raise KeyFileError

        if not os.access( self.hotkeyfile , os.R_OK):
            print(colored("hotkeyfile  {} is not readable".format( self.hotkeyfile ), 'red'))
            raise KeyFileError

        with open( self.hotkeyfile , 'rb') as file:
            data = file.read()
            try:
                # Try hotkey load.
                if is_encrypted(data):
                    password = bittensor.utils.Cli.ask_password()
                    print("decrypting key... (this may take a few moments)")
                    data = decrypt_data(password, data)
                hotkey = load_keypair_from_data(data)
            except KeyError:
                print(colored("Invalid password", 'red'))
                raise KeyError("Invalid password")

            except KeyFileError as e:
                print(colored("Keyfile corrupt", 'red'))
                raise KeyFileError("Keyfile corrupt")

            print(colored("Loaded hotkey: {}".format(hotkey.public_key), 'green'))
            return hotkey
Esempio n. 3
0
 def load_hotkeypair(config):
     keyfile = os.path.expanduser(config.neuron.hotkeyfile)
     with open(keyfile, 'rb') as file:
         data = file.read()
         if is_encrypted(data):
             password = Cli.ask_password()
             data = decrypt_data(password, data)
         hotkey = load_keypair_from_data(data)
         config.neuron.keypair = hotkey
         logger.info("Loaded hotkey: {}", config.neuron.keypair.public_key)
Esempio n. 4
0
 def load_hotkeypair(self):
     keyfile = os.path.expanduser(self.config.wallet.hotkeyfile)
     with open(keyfile, 'rb') as file:
         data = file.read()
         if is_encrypted(data):
             password = bittensor.utils.Cli.ask_password()
             data = decrypt_data(password, data)
         hotkey = load_keypair_from_data(data)
         self.keypair = hotkey
         logger.info("Loaded hotkey: {}", self.keypair.public_key)
Esempio n. 5
0
    def load_key(path) -> Keypair:
        path = os.path.expanduser(path)
        try:
            with open(path, 'rb') as file:
                data = file.read()
                if is_encrypted(data):
                    password = Cli.ask_password()
                    print("decrypting key... (this may take a few moments)")
                    data = decrypt_data(password, data)

                return load_keypair_from_data(data)

        except KeyError:
            print(colored("Invalid password", 'red'))
            quit()
        except KeyFileError as e:
            print(colored("Keyfile corrupt", 'red'))
            raise e
Esempio n. 6
0
    def _load_coldkey(self) -> 'substrateinterface.Keypair':
        if not os.path.isfile(self.coldkeyfile):
            logger.critical("coldkeyfile  {} does not exist".format(
                self.coldkeyfile))
            raise KeyFileError

        if not os.path.isfile(self.coldkeyfile):
            logger.critical("coldkeyfile  {} is not a file".format(
                self.coldkeyfile))
            raise KeyFileError

        if not os.access(self.coldkeyfile, os.R_OK):
            logger.critical("coldkeyfile  {} is not readable".format(
                self.coldkeyfile))
            raise KeyFileError

        with open(self.coldkeyfile, 'rb') as file:
            data = file.read()
            try:
                # Try key load.
                if is_encrypted(data):
                    password = bittensor.utils.Cli.ask_password()
                    logger.info(
                        "decrypting key... (this may take a few moments)")
                    data = decrypt_data(password, data)
                coldkey = load_keypair_from_data(data)

            except KeyError:
                logger.critical("Invalid password")
                raise KeyError("Invalid password")

            except KeyFileError as e:
                logger.critical("Keyfile corrupt")
                raise KeyFileError("Keyfile corrupt")

            logger.success("Loaded coldkey: <cyan>{}</cyan>".format(
                coldkey.public_key))
            return coldkey