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 togenlayer.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
- __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#
>>> 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
- class genlayer.DynArray[source]#
Bases:
MutableSequence
,Generic
Represents exponentially growing array (
list
in python terms) that can be persisted on the blockchain
- exception genlayer.Rollback[source]#
Bases:
Exception
Exception that will be treated as a “Rollback”
- class genlayer.TreeMap[source]#
Bases:
MutableMapping
,Generic
Represents a mapping from keys to values that can be persisted on the blockchain
K
must implementgenlayer.py.storage.tree_map.Comparable
protocol (“<” and “=” are needed)- 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
- 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:
vector (can have duplicates)
id (int alias, can’t have duplicates)
- Element = Element#
- Id = 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
- 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