コード例 #1
0
ファイル: normalization.py プロジェクト: w0x12ef/py-evm
def normalize_bytes(value: Union[bytes, str]) -> bytes:
    if is_bytes(value):
        return cast(bytes, value)
    elif is_text(value) and is_hex(value):
        return decode_hex(cast(str, value))
    elif is_text(value):
        return b''
    else:
        raise TypeError("Value must be either a string or bytes object")
コード例 #2
0
ファイル: normalization.py プロジェクト: w0x12ef/py-evm
def normalize_int(value: IntConvertible) -> int:
    """
    Robust to integer conversion, handling hex values, string representations,
    and special cases like `0x`.
    """
    if is_integer(value):
        return cast(int, value)
    elif is_bytes(value):
        return big_endian_to_int(cast(bytes, value))
    elif is_hex(value) and is_0x_prefixed(value):
        value = cast(str, value)
        if len(value) == 2:
            return 0
        else:
            return int(value, 16)
    elif is_string(value):
        return int(value)
    else:
        raise TypeError(f"Unsupported type: Got `{type(value)}`")
コード例 #3
0
def is_transaction_hash_list(value):
    return all(is_bytes(item) for item in value)