Beispiel #1
0
def is_score_address(value) -> bool:
    """
    Checks if value is T_ADDR_SCORE type.
    T_ADDR_SCORE is data type which is 40-digit hexadecimal string prefixed with `cx`.

    :param value: SCORE address
    """
    return is_str(value) and value.islower() and is_cx_prefixed(value) and len(remove_cx_prefix(value)) == 40
Beispiel #2
0
def is_wallet_address(value) -> bool:
    """
    Checks if value is T_ADDR_EOA type.
    T_ADDR_EOA is data type which is 40-digit hexadecimal string prefixed with `hx`.

    :param value: wallet address
    """
    return is_str(value) and value.islower() and is_hx_prefixed(value) and len(remove_hx_prefix(value)) == 40
Beispiel #3
0
def is_hex_block_hash(value) -> bool:
    """
    Checks the value - a parameter is valid.
    Hash value of a block starts with '0x' and 64 digits hex string

    :param value: hash value of a block, hexadecimal digits. type(str)
    :return: type(bool)
    """
    return is_str(value) and is_0x_prefixed(value) and len(remove_0x_prefix(value)) == 64
def convert_hex_str_to_int(value: str) -> int:
    """Converts hex string prefixed with '0x' into int."""
    if is_str(value):
        return int(value, 16)
    else:
        raise DataTypeException("Data type should be string.")
Beispiel #5
0
def is_cx_prefixed(value: str) -> bool:
    """Used for checking an address of SCORE."""
    if not is_str(value):
        raise DataTypeException("Value type must be str. Got: {0}.".format(
            repr(value)))
    return value.startswith("cx")
Beispiel #6
0
def is_0x_prefixed(value: str) -> bool:
    if not is_str(value):
        raise DataTypeException("Value type must be str. Got: {0}".format(
            repr(value)))
    return value.startswith('0x')
def is_hx_prefixed(value):
    """Used for checking an address of a wallet."""
    if not is_str(value):
        raise DataTypeException("Value type must be str. Got: {0}.".format(
            repr(value)))
    return value.startswith('hx')