genlayer.py.calldata package#

This module is responsible for working with genvm calldata

Calldata natively supports following types:

  1. Primitive types:

    1. python built-in: bool, None, int, str, bytes

    2. Address() type

  2. Composite types:

    1. list (and any other collections.abc.Sequence)

    2. dict with str keys (and any other collections.abc.Mapping with str keys)

For full calldata specification see genvm repo

class genlayer.py.calldata.CalldataEncodable[source]#

Bases: object

Abstract class to support calldata encoding for custom types

Can be used to simplify code

abstract __to_calldata__() Encodable[source]#

Override this method to return calldata-compatible type

Warning

returning self may lead to an infinite loop

Return type:

Encodable

genlayer.py.calldata.decode(mem0: ~collections.abc.Buffer, *, memview2bytes: ~typing.Callable[[memoryview], ~typing.Any] = <class 'bytes'>) Encodable[source]#

Decodes calldata encoded bytes into python DSL

Out of composite types it will contain only dict and list

Return type:

Encodable

genlayer.py.calldata.encode(x: EncodableWithDefault, *, default: Callable[[EncodableWithDefault], Encodable] | None = None) bytes[source]#

Encodes python object into calldata bytes

Parameters:

default (Callable[[EncodableWithDefault], Encodable] | None) – function to be applied to each object recursively, it must return object encodable to calldata

Return type:

bytes

Warning

All composite types in the end are coerced to dict and list, so custom type information is not be preserved. Such types include:

  1. CalldataEncodable

  2. dataclasses

genlayer.py.calldata.to_str(d: Encodable) str[source]#

Transforms calldata DSL into human readable json-like format, should be used for debug purposes only

Return type:

str