genlayer.std package#

Blockchain specific functionality, that won’t work without GenVM

class genlayer.std.ContractAt[source]#

Bases: GenVMContractProxy

Provides a way to call view methods and send transactions to GenVM contracts

__init__(addr: Address)[source]#
address: Address#

Address to which this proxy points

emit(**data: Unpack[TransactionDataKwArgs])[source]#

Namespace with write message

view()[source]#

Namespace with all view methods

class genlayer.std.Lazy[source]#

Bases: Generic

Base class to support lazy evaluation

__init__(_eval: Callable[[], T])[source]#
get() T[source]#

Performs evaluation if necessary (only ones) and stores the result

Returns:

result of evaluating

Raises:

iff evaluation raised, this outcome is also cached, so subsequent calls will raise same exception

Return type:

T

class genlayer.std.MessageType[source]#

Bases: NamedTuple

MessageType(contract_account, sender_account, origin_account, value, is_init, chain_id)

static __new__(_cls, contract_account: Address, sender_account: Address, origin_account: Address, value: int | None, is_init: bool, chain_id: u256)#

Create new instance of MessageType(contract_account, sender_account, origin_account, value, is_init, chain_id)

chain_id: u256#

Current chain ID

contract_account: Address#

Address of current Intelligent Contract

is_init: bool#

True iff it is a deployment

origin_account: Address#

Entire transaction initiator

sender_account: Address#

Address of this call initiator

value: int | None#

Alias for field number 3

genlayer.std.contract(t: type) type[source]#

Decorator that marks class as a contract

Note

There can be only one “contract” at address, so this function must be called at least once

Return type:

type

genlayer.std.contract_interface(_contr: GenVMContractDeclaration) Callable[[Address], GenVMContractProxy][source]#

This decorator produces an “interface” for other GenVM contracts. It has no semantical value, but can be used for auto completion and type checks

@gl.contract_interface
class MyContract:
  class View:
    def view_meth(self, i: int) -> int: ...

  class Write:
    def write_meth(self, i: int) -> None: ...
Return type:

Callable[[Address], GenVMContractProxy]

genlayer.std.deploy_contract(*, code: bytes, args: Sequence[Any] = [], kwargs: Mapping[str, Any] = {}, **data: Unpack[DeploymentTransactionDataKwArgs]) Address | None[source]#

Function for deploying new genvm contracts

Parameters:

code (bytes) – code (i.e. contents of a python file) of the contract

Returns:

address of new contract iff salt_nonce was provided

Return type:

Address | None

genlayer.std.eq_principle_prompt_comparative(fn: Callable[[], Any], principle: str) str#

Comparative equivalence principle that utilizes NLP for verifying that results are equivalent

Parameters:
  • fn (Callable[[], Any]) – function that does all the job

  • principle (str) – principle with which equivalence will be evaluated in the validator

Return type:

str

Note

As leader results are encoded as calldata, format() is used for string representation. However, operating on strings by yourself is more safe in general

Note

supports .lazy() version, which will return Lazy

genlayer.std.eq_principle_prompt_non_comparative(fn: Callable[[], str], *, task: str, criteria: str) str#

Non-comparative equivalence principle that must cover most common use cases

Both leader and validator finish their execution via NLP, that is used to perform task on input. Leader just executes this task, but the validator checks if task was performed with integrity. This principle is useful when task is subjective

Note

supports .lazy() version, which will return Lazy

Return type:

str

genlayer.std.eq_principle_strict_eq(fn: Callable[[], T]) T#

Comparative equivalence principle that checks for strict equality

Parameters:

fn (Callable[[], T]) – functions to perform an action

Return type:

T

Note

supports .lazy() version, which will return Lazy

genlayer.std.eth_contract(contr: EthContractDeclaration) Callable[[Address], EthContractProxy]#
Return type:

Callable[[Address], EthContractProxy]

genlayer.std.exec_prompt(prompt: str, **config: Unpack[ExecPromptKwArgs]) str#

API to execute a prompt (perform NLP)

Parameters:
  • prompt (str) – prompt itself

  • **config (ExecPromptKwArgs) – configuration

Return type:

str

Note

supports .lazy() version, which will return Lazy

genlayer.std.get_webpage(url: str, **config: Unpack[GetWebpageKwArgs]) str#

API to get a webpage after rendering it

Parameters:
  • url (str) – url of website

  • **config (GetWebpageKwArgs) – configuration

Return type:

str

Note

supports .lazy() version, which will return Lazy

genlayer.std.message: MessageType = Ellipsis#

Represents fields from a transaction message that was sent

genlayer.std.message_raw: dict = Ellipsis#

Raw message as parsed json

genlayer.std.private(f)[source]#

Decorator that marks method as private. As all methods are private by default it does nothing.

class genlayer.std.public[source]#

Bases: object

static view(f)[source]#

Decorator that marks a contract method as a public view

static write(f)[source]#

Decorator that marks a contract method as a public write

genlayer.std.rollback_immediate(reason: str) NoReturn[source]#

Performs an immediate rollback, current VM won’t be able to handle it, stack unwind will not happen

Return type:

NoReturn

genlayer.std.sandbox(data: Callable[[], Any]) Any#

Runs function in the sandbox

Warning

It returns result via pickle, which can be unsafe. If it is not desired wrap it to bytes yourself

Note

supports .lazy() version, which will return Lazy

Return type:

Any

genlayer.std.calldata

This module is responsible for working with genvm calldata

Calldata supports following types:

  1. Primitive types:

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

    2. Address() type

  2. Composite types:

    1. list and dict, as well as collections.abc.Sequence and collections.abc.Mapping

    #. CalldataEncodable # dataclasses

For full calldata specification see genvm repo

Proxy to module genlayer.py.calldata

genlayer.std.advanced

This module provides some “advanced” features that can be used for optimizations

If you are using something “advanced” you must know what you do

Proxy to module genlayer.std.advanced

genlayer.std.wasi

Proxy to module genlayer.std._wasi