Example #1
0
def show_asset_list(password, file_path, url):
    """ Enumerate the list of all the assets of the wallet.

    :param password: Password including alphabet character, number, and special character.
    If the user doesn't give password with -p, then CLI will show the prompt and user need to type the password.
    :param file_path:
    :param url:
    :return:
    """
    if not utils.validate_password(password):
        raise PasswordIsNotAcceptable
    try:
        validate_key_store_file(file_path)
        private_key_bytes = __key_from_key_store(file_path,
                                                 bytes(password, 'utf-8'))
        wallet_info = __read_wallet(file_path)
        wallet_address = wallet_info['address']
        balance = __get_balance(wallet_address, url)
        return wallet_address, balance
    except json.decoder.JSONDecodeError:
        raise NetworkIsInvalid
    except FileNotFoundError:
        raise FilePathIsWrong
    except ValueError:
        raise PasswordIsWrong
Example #2
0
def show_wallet(password, file_path, url):
    """ Shows the all information of wallet
    :param password:  Password including alphabet character, number, and special character.
    If the user doesn't give password with -p, then CLI will show the prompt and user need to type the password.
    :param file_path:
    :param url: api url. type(str)
    :return:
    """

    if not utils.validate_password(password):
        raise PasswordIsNotAcceptable

    try:
        validate_key_store_file(file_path)
        private_key_bytes = __key_from_key_store(file_path,
                                                 bytes(password, 'utf-8'))

        wallet_info = __read_wallet(file_path)
        wallet_address = wallet_info['address']
        balance = __get_balance(wallet_address, url)
        return wallet_address, balance, wallet_info
    except FileNotFoundError:
        raise FilePathIsWrong
    except ValueError:
        raise PasswordIsWrong
Example #3
0
def transfer_value_with_the_fee(password, fee, decimal_point, to, amount, file_path, url):
    """ Transfer the value to the specific address with the fee.

    :param password: Password including alphabet character, number, and special character.
    If the user doesn't give password with -p, then CLI will show the prompt and user need to type the password.
    :param fee: Transaction fee.
    :param decimal_point: A user can change the decimal point to express all numbers including fee and amount.
    :param to: Address of wallet to receive the asset.
    :param amount: Amount of money. *The decimal point number is valid up to tenth power of 18. *
    :param file_path: File path for the keystore file of the wallet.
    :param url: Api url. type(str)
    :return:
    """
    try:
        url = f'{url}v2'
        validate_key_store_file(file_path)
        private_key_bytes = __key_from_key_store(file_path, bytes(password, 'utf-8'))
        user_address = get_address_by_privkey(private_key_bytes)

        validate_address(user_address)
        validate_address(to)

        method = 'icx_sendTransaction'

        amount_wei = icx_str_to_wei(amount)
        fixed_amount = int(floor_point(amount_wei, decimal_point))

        fee_wei = get_fee_wei(fee)
        fixed_fee = int(floor_point(fee_wei, decimal_point))

        check_amount_and_fee_is_valid(fixed_amount, fixed_fee)

        params = __make_params(user_address, to, fixed_amount, fixed_fee, method, private_key_bytes)
        payload = create_jsonrpc_request_content(0, method, params)

        # Request the balance repeatedly until we get the response from ICON network.
        request_gen = request_generator(url)
        balance = __get_balance_after_trasfer(user_address, url, request_gen)
        check_balance_enough(balance, amount, fee)
        next(request_gen)
        response = request_gen.send(payload)
        return response

    except FileNotFoundError:
        print("File does not exists.")
        raise FilePathIsWrong
    except IsADirectoryError:
        print(f"{file_path} is a directory.")
        raise FilePathIsWrong
    except ValueError:
        raise PasswordIsWrong
Example #4
0
    def test_create_wallet_case5(self):
        """Test for create_wallet function.
        Case when user entered the file, not a key_store_file.
        """
        # Given
        file_path = os.path.join(TEST_DIR, "not_a_key_store_file.txt")
        password = "******"

        # When
        try:
            wallet_info = validate_key_store_file(file_path)
        except icx.NotAKeyStoreFile:
            self.assertTrue(True)
Example #5
0
    def test_created_store_key_file(self):
        """Check the file is saved in the correct format.
        """
        # Given
        password = "******"
        wallet_name = "wname"
        file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        # When
        try:
            wallet_info = icx.wallet.create_wallet(password, file_path)

            # Then
            self.assertTrue(utils.validate_key_store_file(file_path))
        except:
            self.assertTrue(False)  # Never happen this case.