Ejemplo n.º 1
0
def test_tuple_encoder():
    encoder = TupleEncoder(encoders=(
        UnsignedIntegerEncoder(value_bit_size=256),
        ByteStringEncoder(),
    ))
    expected = decode_hex(
        '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
    )  # noqa: E501
    actual = encoder((0, b''))
    assert actual == expected
Ejemplo n.º 2
0
def encode_abi(types: Iterable[TypeStr], args: Iterable[Any]) -> bytes:
    """
    Encodes the python values in ``args`` as a sequence of binary values of the
    ABI types in ``types`` via the head-tail mechanism.

    :param types: An iterable of string representations of the ABI types that
        will be used for encoding e.g.  ``('uint256', 'bytes[]', '(int,int)')``
    :param args: An iterable of python values to be encoded.

    :returns: The head-tail encoded binary representation of the python values
        in ``args`` as values of the ABI types in ``types``.
    """
    encoders = [registry.get_encoder(type_str) for type_str in types]

    encoder = TupleEncoder(encoders=encoders)

    return encoder(args)
Ejemplo n.º 3
0
def encode_abi(types, args):
    encoders = [registry.get_encoder(type_str) for type_str in types]

    encoder = TupleEncoder(encoders=encoders)

    return encoder(args)