Esempio n. 1
0
    def __init__(self,
                 base_domain_url: str,
                 version: int,
                 request_kwargs: dict = None):
        """
        The initializer to be set with base domain URL and version.

        :param base_domain_url: base domain URL as like <scheme>://<host>:<port>
        :param version: version for RPC server
        :param request_kwargs: kwargs for setting to head of request
        """
        if not self._validate_base_domain_url(base_domain_url):
            logger.error(
                f"While setting HTTPProvider, raised URLException because the URL is invalid. "
                f"URL: {base_domain_url}")
            raise URLException(
                "Invalid base domain URL. "
                "Valid base domain URL format is as like <scheme>://<host>:<port>."
            )
        self._full_path_url = None
        self._base_domain_url = base_domain_url
        self._version = version
        self._request_kwargs = request_kwargs or {}
        logger.info(
            f"Set HTTPProvider. "
            f"Base domain URL: {base_domain_url}, Version: {version}, Request kwargs: {self._request_kwargs}"
        )
Esempio n. 2
0
    def load(file_path: str, password: str) -> 'KeyWallet':
        """Loads a wallet from a keystore file with your password and generates an instance of Wallet.

        :param file_path: File path of the keystore file. type(str)
        :param password:
            Password for the keystore file.
            It must include alphabet character, number, and special character.
        :return: An instance of Wallet class.
        """
        try:
            with open(file_path, 'rb') as file:
                private_key: bytes = extract_key_from_keyfile(
                    file, bytes(password, 'utf-8'))
                private_key_object = PrivateKey(private_key)
                wallet = KeyWallet(private_key_object)
                logger.info(
                    f"Loaded Wallet by the keystore file. Address: {wallet.get_address()}, File path: {file_path}"
                )
                return wallet
        except FileNotFoundError:
            logger.exception(
                f"Raised KeyStoreException while loading the wallet by the keystore file because the file is not found."
            )
            raise KeyStoreException("File is not found.")
        except ValueError:
            logger.exception(
                f"Raised KeyStoreException while loading the wallet by the keystore file because the password is wrong."
            )
            raise KeyStoreException("Password is wrong.")
        except Exception as e:
            logger.exception(
                f"Raised KeyStoreException while loading the wallet by the keystore file. Error message: {e}"
            )
            raise KeyStoreException(f'keystore file error.{e}')
Esempio n. 3
0
    def store(self, file_path: str, password: str):
        """Stores data of an instance of a derived wallet class on the file path with your password.

        :param file_path: File path of the keystore file. type(str)
        :param password:
            Password for the keystore file. Password must include alphabet character, number, and special character.
            type(str)
        """
        try:
            key_store_contents = create_keyfile_json(self.__private_key,
                                                     bytes(password, 'utf-8'),
                                                     iterations=16384,
                                                     kdf="scrypt")
            key_store_contents['address'] = self.get_address()
            key_store_contents['coinType'] = 'icx'

            # validate the  contents of a keystore file.
            if is_keystore_file(key_store_contents):
                json_string_keystore_data = json.dumps(key_store_contents)
                store_keystore_file_on_the_path(file_path,
                                                json_string_keystore_data)
                logger.info(
                    f"Stored Wallet. Address: {self.get_address()}, File path: {file_path}"
                )
        except FileExistsError:
            raise KeyStoreException("File already exists.")
        except PermissionError:
            raise KeyStoreException("Not enough permission.")
        except FileNotFoundError:
            raise KeyStoreException("File not found.")
        except IsADirectoryError:
            raise KeyStoreException("Directory is invalid.")
Esempio n. 4
0
    def create() -> 'KeyWallet':
        """Generates an instance of Wallet without a specific private key.

        :return: An instance of Wallet class.
        """
        private_key_object = PrivateKey()
        wallet = KeyWallet(private_key_object)
        logger.info(f"Created Wallet. Address: {wallet.get_address()}")
        return wallet
Esempio n. 5
0
    def __init__(self, full_path_url: str, request_kwargs: dict = None):
        """
        The initializer to be set with full path url as like <scheme>://<host>:<port>/api/v3.
        If you need to use a channel, you can use it such as <scheme>://<host>:<port>/api/v3/{channel}.

        :param full_path_url: full path URL as like <scheme>://<host>:<port>/api/v3
        :param request_kwargs: kwargs for setting to head of request
        """
        self._full_path_url = full_path_url
        self._request_kwargs = request_kwargs or {}
        logger.info(
            f"Set HTTPProvider. "
            f"Full path URL: {full_path_url}, Request kwargs: {self._request_kwargs}"
        )
Esempio n. 6
0
    def load(private_key: bytes) -> 'KeyWallet':
        """Loads a wallet from a private key and generates an instance of Wallet.

        :param private_key: private key in bytes
        :return: An instance of Wallet class.
        """
        try:
            private_key_object = PrivateKey(private_key)
            wallet = KeyWallet(private_key_object)
            logger.info(
                f"Loaded Wallet by the private key. Address: {wallet.get_address()}"
            )
            return wallet
        except TypeError:
            raise DataTypeException("Private key is invalid.")