vm

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2025 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleName = "vm"
	RouterKey  = ModuleName
)
View Source
const (
	QueryRender = "qrender"
	QueryFuncs  = "qfuncs"
	QueryEval   = "qeval"
	QueryFile   = "qfile"
	QueryDoc    = "qdoc"
)

query paths

Variables

View Source
var ASCIIDomain = regexp.MustCompile(`^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}$`)
View Source
var Package = amino.RegisterPackage(amino.NewPackage(
	"github.com/gnolang/gno/gno.land/pkg/sdk/vm",
	"vm",
	amino.GetCallersDirname(),
).WithDependencies(
	std.Package,
	gnovm.Package,
).WithTypes(
	MsgCall{}, "m_call",
	MsgRun{}, "m_run",
	MsgAddPackage{}, "m_addpkg",

	InvalidPkgPathError{}, "InvalidPkgPathError",
	NoRenderDeclError{}, "NoRenderDeclError",
	PkgExistError{}, "PkgExistError",
	InvalidStmtError{}, "InvalidStmtError",
	InvalidExprError{}, "InvalidExprError",
	TypeCheckError{}, "TypeCheckError",
	UnauthorizedUserError{}, "UnauthorizedUserError",
))

Functions

func ErrInvalidExpr

func ErrInvalidExpr(msg string) error

func ErrInvalidPkgPath

func ErrInvalidPkgPath(msg string) error

func ErrInvalidStmt

func ErrInvalidStmt(msg string) error

func ErrPkgAlreadyExists

func ErrPkgAlreadyExists(msg string) error

func ErrTypeCheck

func ErrTypeCheck(err error) error

func ErrUnauthorizedUser

func ErrUnauthorizedUser(msg string) error

func NewHandler

func NewHandler(vm *VMKeeper) vmHandler

NewHandler returns a handler for "vm" type messages.

func RegisterInvariants

func RegisterInvariants(ir sdk.InvariantRegistry, vmk VMKeeper)

RegisterInvariants registers the vm module invariants

func ValidateGenesis

func ValidateGenesis(gs GenesisState) error

ValidateGenesis performs basic validation of genesis data returning an error for any failed validation criteria. XXX refactor to .ValidateBasic() method.

Types

type AccountKeeperI

type AccountKeeperI interface {
	GetAccount(ctx sdk.Context, addr crypto.Address) std.Account
}

AccountKeeperI is the limited interface only needed for VM.

type BankKeeperI

type BankKeeperI interface {
	GetCoins(ctx sdk.Context, addr crypto.Address) std.Coins
	SendCoins(ctx sdk.Context, fromAddr crypto.Address, toAddr crypto.Address, amt std.Coins) error
	SubtractCoins(ctx sdk.Context, addr crypto.Address, amt std.Coins) (std.Coins, error)
	AddCoins(ctx sdk.Context, addr crypto.Address, amt std.Coins) (std.Coins, error)
}

BankKeeperI is the limited interface only needed for VM.

type FunctionSignature

type FunctionSignature struct {
	FuncName string
	Params   []NamedType
	Results  []NamedType
}

Public facing function signatures. See convertArgToGno() for supported types.

type FunctionSignatures

type FunctionSignatures []FunctionSignature

func (FunctionSignatures) JSON

func (fsigs FunctionSignatures) JSON() string

type GenesisState

type GenesisState struct {
	Params      Params         `json:"params" yaml:"params"`
	RealmParams []params.Param `json:"realm_params" yaml:"realm_params"`
}

GenesisState - all state that must be provided at genesis

func DefaultGenesisState

func DefaultGenesisState() GenesisState

DefaultGenesisState - Return a default genesis state

func NewGenesisState

func NewGenesisState(params Params) GenesisState

NewGenesisState - Create a new genesis state

type InvalidExprError

type InvalidExprError struct {
	// contains filtered or unexported fields
}

declare all script errors. NOTE: these are meant to be used in conjunction with pkgs/errors.

func (InvalidExprError) AssertABCIError

func (InvalidExprError) AssertABCIError()

func (InvalidExprError) Error

func (e InvalidExprError) Error() string

type InvalidPkgPathError

type InvalidPkgPathError struct {
	// contains filtered or unexported fields
}

declare all script errors. NOTE: these are meant to be used in conjunction with pkgs/errors.

func (InvalidPkgPathError) AssertABCIError

func (InvalidPkgPathError) AssertABCIError()

func (InvalidPkgPathError) Error

func (e InvalidPkgPathError) Error() string

type InvalidStmtError

type InvalidStmtError struct {
	// contains filtered or unexported fields
}

declare all script errors. NOTE: these are meant to be used in conjunction with pkgs/errors.

func (InvalidStmtError) AssertABCIError

func (InvalidStmtError) AssertABCIError()

func (InvalidStmtError) Error

func (e InvalidStmtError) Error() string

type MsgAddPackage

type MsgAddPackage struct {
	Creator crypto.Address    `json:"creator" yaml:"creator"`
	Package *gnovm.MemPackage `json:"package" yaml:"package"`
	Deposit std.Coins         `json:"deposit" yaml:"deposit"`
}

MsgAddPackage - create and initialize new package

func NewMsgAddPackage

func NewMsgAddPackage(creator crypto.Address, pkgPath string, files []*gnovm.MemFile) MsgAddPackage

NewMsgAddPackage - upload a package with files.

func (MsgAddPackage) GetReceived

func (msg MsgAddPackage) GetReceived() std.Coins

Implements ReceiveMsg.

func (MsgAddPackage) GetSignBytes

func (msg MsgAddPackage) GetSignBytes() []byte

Implements Msg.

func (MsgAddPackage) GetSigners

func (msg MsgAddPackage) GetSigners() []crypto.Address

Implements Msg.

func (MsgAddPackage) Route

func (msg MsgAddPackage) Route() string

Implements Msg.

func (MsgAddPackage) Type

func (msg MsgAddPackage) Type() string

Implements Msg.

func (MsgAddPackage) ValidateBasic

func (msg MsgAddPackage) ValidateBasic() error

Implements Msg.

type MsgCall

type MsgCall struct {
	Caller  crypto.Address `json:"caller" yaml:"caller"`
	Send    std.Coins      `json:"send" yaml:"send"`
	PkgPath string         `json:"pkg_path" yaml:"pkg_path"`
	Func    string         `json:"func" yaml:"func"`
	Args    []string       `json:"args" yaml:"args"`
}

MsgCall - executes a Gno statement.

func NewMsgCall

func NewMsgCall(caller crypto.Address, send sdk.Coins, pkgPath, fnc string, args []string) MsgCall

func (MsgCall) GetReceived

func (msg MsgCall) GetReceived() std.Coins

Implements ReceiveMsg.

func (MsgCall) GetSignBytes

func (msg MsgCall) GetSignBytes() []byte

Implements Msg.

func (MsgCall) GetSigners

func (msg MsgCall) GetSigners() []crypto.Address

Implements Msg.

func (MsgCall) Route

func (msg MsgCall) Route() string

Implements Msg.

func (MsgCall) Type

func (msg MsgCall) Type() string

Implements Msg.

func (MsgCall) ValidateBasic

func (msg MsgCall) ValidateBasic() error

Implements Msg.

type MsgRun

type MsgRun struct {
	Caller  crypto.Address    `json:"caller" yaml:"caller"`
	Send    std.Coins         `json:"send" yaml:"send"`
	Package *gnovm.MemPackage `json:"package" yaml:"package"`
}

MsgRun - executes arbitrary Gno code.

func NewMsgRun

func NewMsgRun(caller crypto.Address, send std.Coins, files []*gnovm.MemFile) MsgRun

func (MsgRun) GetReceived

func (msg MsgRun) GetReceived() std.Coins

Implements ReceiveMsg.

func (MsgRun) GetSignBytes

func (msg MsgRun) GetSignBytes() []byte

Implements Msg.

func (MsgRun) GetSigners

func (msg MsgRun) GetSigners() []crypto.Address

Implements Msg.

func (MsgRun) Route

func (msg MsgRun) Route() string

Implements Msg.

func (MsgRun) Type

func (msg MsgRun) Type() string

Implements Msg.

func (MsgRun) ValidateBasic

func (msg MsgRun) ValidateBasic() error

Implements Msg.

type NamedType

type NamedType struct {
	Name  string
	Type  string
	Value string
}

type NoRenderDeclError

type NoRenderDeclError struct {
	// contains filtered or unexported fields
}

declare all script errors. NOTE: these are meant to be used in conjunction with pkgs/errors.

func (NoRenderDeclError) AssertABCIError

func (NoRenderDeclError) AssertABCIError()

func (NoRenderDeclError) Error

func (e NoRenderDeclError) Error() string

type Params

type Params struct {
	SysNamesPkgPath string `json:"sysnames_pkgpath" yaml:"sysnames_pkgpath"`
	ChainDomain     string `json:"chain_domain" yaml:"chain_domain"`
}

Params defines the parameters for the bank module.

func DefaultParams

func DefaultParams() Params

DefaultParams returns a default set of parameters.

func NewParams

func NewParams(namesPkgPath, chainDomain string) Params

NewParams creates a new Params object

func (Params) Equals

func (p Params) Equals(p2 Params) bool

Equals returns a boolean determining if two Params types are identical.

func (Params) String

func (p Params) String() string

String implements the stringer interface.

func (Params) Validate

func (p Params) Validate() error

type ParamsKeeperI

type ParamsKeeperI interface {
	params.ParamsKeeperI

	IsRegistered(moduleName string) bool
	GetRegisteredKeeper(moduleName string) params.ParamfulKeeper
}

ParamsKeeperI is the limited interface only needed for VM.

type PkgExistError

type PkgExistError struct {
	// contains filtered or unexported fields
}

declare all script errors. NOTE: these are meant to be used in conjunction with pkgs/errors.

func (PkgExistError) AssertABCIError

func (PkgExistError) AssertABCIError()

func (PkgExistError) Error

func (e PkgExistError) Error() string

type SDKBanker

type SDKBanker struct {
	// contains filtered or unexported fields
}

func NewSDKBanker

func NewSDKBanker(vmk *VMKeeper, ctx sdk.Context) *SDKBanker

func (*SDKBanker) GetCoins

func (bnk *SDKBanker) GetCoins(b32addr crypto.Bech32Address) (dst std.Coins)

func (*SDKBanker) IssueCoin

func (bnk *SDKBanker) IssueCoin(b32addr crypto.Bech32Address, denom string, amount int64)

func (*SDKBanker) RemoveCoin

func (bnk *SDKBanker) RemoveCoin(b32addr crypto.Bech32Address, denom string, amount int64)

func (*SDKBanker) SendCoins

func (bnk *SDKBanker) SendCoins(b32from, b32to crypto.Bech32Address, amt std.Coins)

func (*SDKBanker) TotalCoin

func (bnk *SDKBanker) TotalCoin(denom string) int64

type SDKParams

type SDKParams struct {
	// contains filtered or unexported fields
}

func NewSDKParams

func NewSDKParams(pmk ParamsKeeperI, ctx sdk.Context) *SDKParams

func (*SDKParams) SetBool

func (prm *SDKParams) SetBool(key string, value bool)

func (*SDKParams) SetBytes

func (prm *SDKParams) SetBytes(key string, value []byte)

func (*SDKParams) SetInt64

func (prm *SDKParams) SetInt64(key string, value int64)

func (*SDKParams) SetString

func (prm *SDKParams) SetString(key string, value string)

The key has the format <module>:(<realm>:)?<paramname>.

func (*SDKParams) SetStrings

func (prm *SDKParams) SetStrings(key string, value []string)

func (*SDKParams) SetUint64

func (prm *SDKParams) SetUint64(key string, value uint64)

type TypeCheckError

type TypeCheckError struct {
	Errors []string `json:"errors"`
	// contains filtered or unexported fields
}

declare all script errors. NOTE: these are meant to be used in conjunction with pkgs/errors.

func (TypeCheckError) AssertABCIError

func (TypeCheckError) AssertABCIError()

func (TypeCheckError) Error

func (e TypeCheckError) Error() string

type UnauthorizedUserError

type UnauthorizedUserError struct {
	// contains filtered or unexported fields
}

declare all script errors. NOTE: these are meant to be used in conjunction with pkgs/errors.

func (UnauthorizedUserError) AssertABCIError

func (UnauthorizedUserError) AssertABCIError()

func (UnauthorizedUserError) Error

func (e UnauthorizedUserError) Error() string

type VMKeeper

type VMKeeper struct {
	// Needs to be explicitly set, like in the case of gnodev.
	Output io.Writer
	// contains filtered or unexported fields
}

VMKeeper holds all package code and store state.

func NewVMKeeper

func NewVMKeeper(
	baseKey store.StoreKey,
	iavlKey store.StoreKey,
	acck AccountKeeperI,
	bank BankKeeperI,
	prmk ParamsKeeperI,
) *VMKeeper

NewVMKeeper returns a new VMKeeper. NOTE: prmk must be the root ParamsKeeper such that ExecContext.Params may set any module's parameter.

func (*VMKeeper) AddPackage

func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error)

AddPackage adds a package with given fileset.

func (*VMKeeper) Call

func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error)

Call calls a public Gno function (for delivertx).

func (*VMKeeper) CommitGnoTransactionStore

func (vm *VMKeeper) CommitGnoTransactionStore(ctx sdk.Context)

func (*VMKeeper) ExportGenesis

func (vm *VMKeeper) ExportGenesis(ctx sdk.Context) GenesisState

ExportGenesis returns a GenesisState for a given context and keeper

func (*VMKeeper) GetParams

func (vm *VMKeeper) GetParams(ctx sdk.Context) Params

func (*VMKeeper) InitGenesis

func (vm *VMKeeper) InitGenesis(ctx sdk.Context, gs GenesisState)

InitGenesis - Init store state from genesis data

func (*VMKeeper) Initialize

func (vm *VMKeeper) Initialize(
	logger *slog.Logger,
	ms store.MultiStore,
)

func (*VMKeeper) LoadStdlib

func (vm *VMKeeper) LoadStdlib(ctx sdk.Context, stdlibDir string)

LoadStdlib loads the Gno standard library into the given store.

func (*VMKeeper) LoadStdlibCached

func (vm *VMKeeper) LoadStdlibCached(ctx sdk.Context, stdlibDir string)

LoadStdlib loads the Gno standard library into the given store.

func (*VMKeeper) MakeGnoTransactionStore

func (vm *VMKeeper) MakeGnoTransactionStore(ctx sdk.Context) sdk.Context

func (*VMKeeper) QueryDoc

func (vm *VMKeeper) QueryDoc(ctx sdk.Context, pkgPath string) (*doc.JSONDocumentation, error)

func (*VMKeeper) QueryEval

func (vm *VMKeeper) QueryEval(ctx sdk.Context, pkgPath string, expr string) (res string, err error)

QueryEval evaluates a gno expression (readonly, for ABCI queries).

func (*VMKeeper) QueryEvalString

func (vm *VMKeeper) QueryEvalString(ctx sdk.Context, pkgPath string, expr string) (res string, err error)

QueryEvalString evaluates a gno expression (readonly, for ABCI queries). The result is expected to be a single string (not a tuple).

func (*VMKeeper) QueryFile

func (vm *VMKeeper) QueryFile(ctx sdk.Context, filepath string) (res string, err error)

func (*VMKeeper) QueryFuncs

func (vm *VMKeeper) QueryFuncs(ctx sdk.Context, pkgPath string) (fsigs FunctionSignatures, err error)

QueryFuncs returns public facing function signatures.

func (*VMKeeper) Run

func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error)

Run executes arbitrary Gno code in the context of the caller's realm.

func (*VMKeeper) SetParams

func (vm *VMKeeper) SetParams(ctx sdk.Context, params Params) error

func (*VMKeeper) WillSetParam

func (vm *VMKeeper) WillSetParam(ctx sdk.Context, key string, value any)

type VMKeeperI

type VMKeeperI interface {
	AddPackage(ctx sdk.Context, msg MsgAddPackage) error
	Call(ctx sdk.Context, msg MsgCall) (res string, err error)
	QueryEval(ctx sdk.Context, pkgPath string, expr string) (res string, err error)
	Run(ctx sdk.Context, msg MsgRun) (res string, err error)
	LoadStdlib(ctx sdk.Context, stdlibDir string)
	LoadStdlibCached(ctx sdk.Context, stdlibDir string)
	MakeGnoTransactionStore(ctx sdk.Context) sdk.Context
	CommitGnoTransactionStore(ctx sdk.Context)
	InitGenesis(ctx sdk.Context, data GenesisState)
}

vm.VMKeeperI defines a module interface that supports Gno smart contracts programming (scripting).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL