コード例 #1
0
ファイル: abi.py プロジェクト: axing1991/ethereum-abi-utils
def decode_single(typ, data):
    if is_hex_encoded_value(data):
        warnings.warn(
            DeprecationWarning(
                "Automatic inference of hex encoded data has been deprecated. "
                "Please adjust your code to ensure that the data argument for "
                "`decode_single` is a byte string"))
        data = decode_hex(remove_0x_prefix(data))

    if is_text(data):
        warnings.warn(
            DeprecationWarning(
                "Automatic conversion of encoded data to bytes has been deprecated. "
                "Please adjust your code to ensure that the data argument for "
                "`decode_single` is a byte string"))
        data = force_bytes(data)

    try:
        base, sub, arrlist = typ
    except ValueError:
        base, sub, arrlist = process_type(typ)

    decoder = get_single_decoder(base, sub, arrlist)
    stream = BytesIO(data)
    return decoder(stream)
コード例 #2
0
def encode_single(typ, arg):
    try:
        base, sub, arrlist = typ
    except ValueError:
        base, sub, arrlist = process_type(typ)

    encoder = get_single_encoder(base, sub, arrlist)
    return encoder(arg)
コード例 #3
0
def test_multi_decoder(types, data, expected):
    decoders = tuple((
        get_single_decoder(*process_type(t)) for t in types
    ))
    decoder = MultiDecoder.as_decoder(decoders=decoders)
    stream = BytesIO(decode_hex(data))
    actual = decoder(stream)
    assert actual == expected
コード例 #4
0
def decode_abi(types, data):
    if not is_bytes(data):
        raise TypeError(
            "The `data` value must be of bytes type.  Got {0}".format(
                type(data)))

    processed_types = tuple(process_type(_type) for _type in types)
    decoder = get_multi_decoder(processed_types)
    stream = BytesIO(data)
    return decoder(stream)
コード例 #5
0
ファイル: abi.py プロジェクト: axing1991/ethereum-abi-utils
def encode_single(typ, arg):
    try:
        base, sub, arrlist = typ
    except ValueError:
        base, sub, arrlist = process_type(typ)

    if is_text(arg):
        arg = force_bytes(arg)

    encoder = get_single_encoder(base, sub, arrlist)
    return encoder(arg)
コード例 #6
0
def decode_single(typ, data):
    if not is_bytes(data):
        raise TypeError(
            "The `data` value must be of bytes type.  Got {0}".format(
                type(data)))
    try:
        base, sub, arrlist = typ
    except ValueError:
        base, sub, arrlist = process_type(typ)

    decoder = get_single_decoder(base, sub, arrlist)
    stream = BytesIO(data)
    return decoder(stream)
コード例 #7
0
ファイル: abi.py プロジェクト: axing1991/ethereum-abi-utils
def decode_abi(types, data):
    if is_hex_encoded_value(data):
        warnings.warn(
            DeprecationWarning(
                "Automatic inference of hex encoded data has been deprecated. "
                "Please adjust your code to ensure that the data argument for "
                "`decode_single` is a byte string"))
        data = decode_hex(remove_0x_prefix(data))

    if is_text(data):
        warnings.warn(
            DeprecationWarning(
                "Automatic conversion of encoded data to bytes has been deprecated. "
                "Please adjust your code to ensure that the data argument for "
                "`decode_abi` is a byte string"))
        data = force_bytes(data)

    processed_types = tuple(process_type(_type) for _type in types)
    decoder = get_multi_decoder(processed_types)
    stream = BytesIO(data)
    return decoder(stream)
コード例 #8
0
ファイル: abi.py プロジェクト: axing1991/ethereum-abi-utils
def encode_abi(types, args):
    processed_types = [process_type(typ) for typ in types]
    encoder = get_multi_encoder(processed_types)
    return encoder(args)
コード例 #9
0
ファイル: test_parsing.py プロジェクト: tintinweb/eth-abi
def test_collapse_type(original, expected):
    assert collapse_type(*process_type(original)) == expected
コード例 #10
0
ファイル: test_parsing.py プロジェクト: tintinweb/eth-abi
def test_process_parsing_errors(typestr):
    with pytest.raises(ParseError):
        process_type(typestr)
コード例 #11
0
ファイル: test_parsing.py プロジェクト: tintinweb/eth-abi
def test_process_validation_errors(typestr):
    with pytest.raises(ValueError):
        process_type(typestr)
コード例 #12
0
ファイル: test_parsing.py プロジェクト: tintinweb/eth-abi
def test_process_type_requires_basic_type():
    with pytest.raises(ValueError):
        process_type('(int,int)')
コード例 #13
0
ファイル: test_parsing.py プロジェクト: tintinweb/eth-abi
def test_process_type_requires_string_type():
    with pytest.raises(TypeError):
        process_type(b'uint256')
コード例 #14
0
ファイル: test_parsing.py プロジェクト: tintinweb/eth-abi
def test_process_type(typestr, expected_parse):
    assert process_type(typestr) == expected_parse
コード例 #15
0
def test_process_exceptions(typestr):
    with pytest.raises(ValueError):
        process_type(typestr)