genlayer package#

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

Proxy to genlayer.std

class genlayer.Address[source]#

Bases: object

Represents GenLayer Address

SIZE = 20#

Constant that represents size of a Genlayer address

__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

property as_b64: str#
Returns:

base64 representation of an address (most compact string)

property as_bytes: bytes#
Returns:

raw bytes of an address (most compact representation)

property as_hex: str#
Returns:

checksum string representation

property as_int: int#
Returns:

int representation of an address (unsigned little endian)

class genlayer.Array[source]#

Bases: Sequence, Generic

Constantly sized array that can be persisted on the blockchain

__init__()[source]#

This class can’t be created with Array()

Raises:

TypeError – always

class genlayer.DynArray[source]#

Bases: MutableSequence, Generic

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

__init__()[source]#

This class can’t be created with DynArray()

Raises:

TypeError – always

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=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

__init__()[source]#

This class can’t be created with TreeMap()

Raises:

TypeError – always

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, default: G = None) V | G[source]#
Returns:

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

Return type:

V | G

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

class genlayer.VecDB[source]#

Bases: Generic

Data structure that supports storing and querying vector data

There are two entities that can act as a key:

  1. vector (can have duplicates)

  2. id (int alias, can’t have duplicates)

Id = genlayer.py.storage.vecdb.Id#
get_by_id(id: Id) VecDBElement[T, S, V, None][source]#
Return type:

VecDBElement[T, S, V, None]

get_by_id_or_none(id: Id) VecDBElement[T, S, V, None] | None[source]#
Return type:

VecDBElement[T, S, V, None] | None

insert(key: np.ndarray[tuple[S], np.dtype[T]], val: V) Id[source]#
Return type:

Id

knn(v: np.ndarray[tuple[S], np.dtype[T]], k: int) Iterator[VecDBElement[T, S, V, T]][source]#
Return type:

Iterator[VecDBElement[T, S, V, 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