Package genlayer#

Common import for all contracts

It exposes most of the types to the top scope and encapsulates other utility under gl namespace which is a proxy to genlayer.std

genlayer.gl#

Blockchain specific functionality, that won’t work without GenVM and reexports form genlayer.py provided for convenience

Proxy to genlayer.std

class genlayer.Address[source]#

Bases: object

Represents GenLayer Address

SIZE: Final[int] = 20#

Constant that represents size of a Genlayer address

__eq__(r)[source]#

Return self==value.

__format__(fmt: Literal['x', 'b64', 'cd', '']) str[source]#

Default object formatter.

Return str(self) if format_spec is empty. Raise TypeError otherwise.

Return type:

str

__ge__(r)[source]#

Return self>=value.

__gt__(r)[source]#

Return self>value.

__hash__()[source]#

Return hash(self).

__init__(val: str | Buffer)[source]#
Parameters:

val (str | Buffer) – either a hex encoded address (that starts with ‘0x’), or base64 encoded address, or buffer of 20 bytes

Warning

checksum validation is not performed

__le__(r)[source]#

Return self<=value.

__lt__(r)[source]#

Return self<value.

__repr__() str[source]#

Return repr(self).

Return type:

str

__str__() str[source]#

Return str(self).

Return type:

str

property as_b64: str#
>>> Address('0x5b38da6a701c568545dcfcb03fcb875f56beddc4').as_b64
'WzjaanAcVoVF3PywP8uHX1a+3cQ='
Returns:

base64 representation of an address (most compact string)

property as_bytes: bytes#
>>> Address('0x5b38da6a701c568545dcfcb03fcb875f56beddc4').as_bytes
b'[8\xdajp\x1cV\x85E\xdc\xfc\xb0?\xcb\x87_V\xbe\xdd\xc4'
Returns:

raw bytes of an address (most compact representation)

property as_hex: str#
>>> Address('0x5b38da6a701c568545dcfcb03fcb875f56beddc4').as_hex
'0x5B38Da6a701c568545dCfcB03FcB875f56beddC4'
Returns:

checksum string representation

property as_int: u160#
>>> Address('0x5b38da6a701c568545dcfcb03fcb875f56beddc4').as_int
1123907236495940146162314350759402901750813440091
>>> hex(Address('0x5b38da6a701c568545dcfcb03fcb875f56beddc4').as_int)
'0xc4ddbe565f87cb3fb0fcdc4585561c706ada385b'
Returns:

int representation of an address (unsigned little endian)

class genlayer.Array[source]#

Bases: Sequence, SizedArray, Generic

Constantly sized array that can be persisted on the blockchain

__getitem__(idx: SupportsIndex) T[source]#
__getitem__(idx: slice) Array
__init__()[source]#

This class can’t be created with Array()

Raises:

TypeError – always

__iter__()[source]#
__len__() int[source]#
Return type:

int

__setitem__(idx: int, val: T) None[source]#
class genlayer.DynArray[source]#

Bases: MutableSequence, Generic

Represents exponentially growing array (list in python terms) that can be persisted on the blockchain

__delitem__(idx: int) None[source]#
__delitem__(idx: slice) None
__getitem__(idx: int) T[source]#
__getitem__(idx: slice) list[T]
__init__()[source]#

This class can’t be created with DynArray()

Raises:

TypeError – always

__iter__() Any[source]#
Return type:

Any

__len__() int[source]#
Return type:

int

__repr__() str[source]#

Return repr(self).

Return type:

str

__setitem__(idx: SupportsIndex, val: T) None[source]#
__setitem__(idx: slice, val: collections.abc.Sequence[T]) None
append(value: T) None[source]#

S.append(value) – append value to the end of the sequence

append_new_get() T[source]#
Return type:

T

insert(index: int, value: T) None[source]#

S.insert(index, value) – insert value before index

pop([index]) item -- remove and return item at index (default last).[source]#

Raise IndexError if list is empty or index is out of range.

genlayer.Keccak256(initial_input: Buffer | None = None)#
exception genlayer.Rollback[source]#

Bases: Exception

Exception that will be treated as a “Rollback”

__init__(msg: str)[source]#
class genlayer.TreeMap[source]#

Bases: MutableMapping, Generic

Represents a mapping from keys to values that can be persisted on the blockchain

Tparam K:

must implement genlayer.py.storage.tree_map.Comparable protocol (“<” is needed) and be storage-allowed

Tparam V:

must be storage-allowed

__contains__(k: object) bool[source]#
Return type:

bool

__delitem__(k: K)[source]#
__getitem__(k: K) V[source]#
Return type:

V

__gl_allow_storage__ = True#
__iter__()[source]#
__len__() int[source]#
Return type:

int

__repr__() str[source]#

Return repr(self).

Return type:

str

__setitem__(k: K, v: V)[source]#
clear() None.  Remove all items from D.[source]#
compute_if_absent(k: K, supplier: Callable[[], V]) V[source]#
Returns:

Value associated with k if it is present, otherwise get’s new value from the supplier, stores it at k and returns

Return type:

V

get(k: K, /) V | None[source]#
get(k: K, /, default: G) V | G
Returns:

Value associated with k or default if there is no such value

get_or_insert_default(k: K) V[source]#
Return type:

V

items() a set-like object providing a view on D's items[source]#
Return type:

ItemsView

genlayer.allow_storage(cls: T) T[source]#
Return type:

T

Integer aliases#

It also have aliases for signed and unsigned integer types (such as u256) and bigint alias that can be used in storage unlike regular int