genlayer.std package#

Blockchain specific functionality, that won’t work without GenVM

class genlayer.std.Contract[source]#

Bases: object

property address: Address#
Returns:

Address of this contract

property balance: u256#
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

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

Namespace with write message

Returns:

object supporting .name(*args, **kwargs) that emits a message and returns None

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

Method to emit a message that transfers native tokens

view()[source]#

Namespace with all view methods

Returns:

object supporting .name(*args, **kwargs) that calls a contract and returns its result (Any) or rises its Rollback

Note

supports name.lazy(*args, **kwargs) call version

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_address, sender_address, origin_address, value, is_init, chain_id)

static __new__(_cls, contract_address: Address, sender_address: Address, origin_address: Address, value: u256, is_init: bool, chain_id: u256)#

Create new instance of MessageType(contract_address, sender_address, origin_address, value, is_init, chain_id)

chain_id: u256#

Current chain ID

contract_address: Address#

Address of current Intelligent Contract

is_init: bool#

True iff it is a deployment

origin_address: Address#

Entire transaction initiator

sender_address: Address#

Address of this call initiator

value: u256#

Alias for field number 3

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

  • args (Sequence[Any]) – arguments to be encoded into calldata

  • kwargs (Mapping[str, Any]) – keyword arguments to be encoded into calldata

Returns:

address of new contract iff non-zero salt_nonce was provided

Return type:

Address | None

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

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[source]#

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[source]#

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: ContractDeclaration) Callable[[Address], ContractProxy]#
Return type:

Callable[[Address], ContractProxy]

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

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[source]#

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

write = <genlayer.std._write object>#

Decorator that marks a contract method as a public write. Has .payable

@gl.public.write
def foo(self) -> None: ...

@gl.public.write.payable
def bar(self) -> None: ...
Return type:

T

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.calldata

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

Proxy to module genlayer.py.calldata

genlayer.std.advanced

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

Warning

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