initia

package module
v0.0.0-...-bdfcca1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

README

InitiaVM

Move VM for the Cosmos SDK.

It allows you to compile, initialize and execute Move smart contracts from Go applications, in particular from x/move.

Structure

This repo contains both Rust and Go code. The rust code is compiled into a dll/so to be linked via cgo and wrapped with a pleasant Go API. The full build step involves compiling rust -> C library, and linking that library to the Go code. For ergonomics of the user, we will include pre-compiled libraries to easily link with, and Go developers should just be able to import this directly.

Support Platform

Requires Rust 1.64+ and Go 1.19+.

The Rust implementation of the VM is compiled to a library called libinitiavm. This is then linked to the Go code when the final binary is built. For that reason not all systems supported by Go are supported by this project.

Linux (tested on CentOS7 and Alpine) and macOS is supported.

Builds of libinitiavm

Our system currently supports the following builds. In general we can only support targets that are supported by Move's singlepass backend, which for example excludes all 32 bit systems.

OS family Arch Linking Supported Note
Linux (glibc) x86_64 shared ✅​libinitia.x86_64.so
Linux (glibc) x86_64 static 🚫​ Would link libinitiavm statically but glibc dynamically as static glibc linking is not recommended. Potentially interesting for Osmosis.
Linux (glibc) aarch64 shared ✅​libinitia.aarch64.so
Linux (glibc) aarch64 static 🚫​
Linux (musl) x86_64 shared 🚫​ Possible but not needed
Linux (musl) x86_64 static ✅​libinitia_muslc.x86_64.a
Linux (musl) aarch64 shared 🚫​ Possible but not needed
Linux (musl) aarch64 static ✅​libinitia_muslc.aarch64.a
macOS x86_64 shared ✅​libinitiavm.dylib
macOS x86_64 static 🚫​
macOS aarch64 shared ✅​libinitiavm.dylib
macOS aarch64 static 🚫​

Development

There are two halfs to this code - go and rust. The first step is to ensure that there is a proper dll built for your platform. This should be api/libinitiavm.X, where X is:

  • so for Linux systems
  • dylib for MacOS

If this is present, then make test will run the Go test suite and you can import this code freely. If it is not present you will have to build it for your system, and ideally add it to this repo with a PR (on your fork). We will set up a proper CI system for building these binaries, but we are not there yet.

To build the rust side, try make build-rust and wait for it to compile. This depends on cargo being installed with rustc version 1.64+. Generally, you can just use rustup to install all this with no problems.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type VM

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

VM struct is the core of initiavm.

func NewVM

func NewVM(printDebug bool) VM

NewVm return VM instance

func (*VM) DecodeModuleBytes

func (vm *VM) DecodeModuleBytes(
	moduleBytes []byte,
) ([]byte, error)

DecodeModuleBytes decode module bytes to MoveModule instance and return as jSON string

func (*VM) DecodeMoveResource

func (vm *VM) DecodeMoveResource(
	kvStore api.KVStore,
	structTag types.StructTag,
	resourceBytes []byte,
) ([]byte, error)

DecodeMoveResource decode resource bytes to move resource instance and return as jSON string

func (*VM) DecodeScriptBytes

func (vm *VM) DecodeScriptBytes(
	scriptBytes []byte,
) ([]byte, error)

DecodeScriptBytes decode script bytes to MoveFunction instance and return as jSON string

func (*VM) Destroy

func (vm *VM) Destroy()

VM Destroyer

func (*VM) ExecuteEntryFunction

func (vm *VM) ExecuteEntryFunction(
	kvStore api.KVStore,
	goApi api.GoAPI,
	gasLimit uint64,
	txHash []byte,
	sender types.AccountAddress,
	payload types.EntryFunction,
) (uint64, []types.ContractEvent, []types.SizeDelta, []types.StakingDelta, error)

Execute calls a given contract. TODO: add params and returns

func (*VM) ExecuteScript

func (vm *VM) ExecuteScript(
	kvStore api.KVStore,
	goApi api.GoAPI,
	gasLimit uint64,
	txHash []byte,
	sender types.AccountAddress,
	payload types.Script,
) (uint64, []types.ContractEvent, []types.SizeDelta, []types.StakingDelta, error)

Execute calls a given contract. TODO: add params and returns

func (*VM) Initialize

func (vm *VM) Initialize(
	kvStore api.KVStore,
	goApi api.GoAPI,
	moduleBundle types.ModuleBundle,
) error

Initialize deploys std libs and move libs for bootstrapping genesis

func (*VM) PublishModuleBundle

func (vm *VM) PublishModuleBundle(
	kvStore api.KVStore,
	goApi api.GoAPI,
	gasLimit uint64,
	txHash []byte,
	sender types.AccountAddress,
	moduleBundle types.ModuleBundle,
) (uint64, []types.ContractEvent, []types.SizeDelta, []types.StakingDelta, error)

PublishModuleBundle will publish a given module.

func (*VM) QueryEntryFunction

func (vm *VM) QueryEntryFunction(
	kvStore api.KVStore,
	goApi api.GoAPI,
	gasLimit uint64,
	payload types.EntryFunction,
) ([]byte, error)

Query will do a query request to VM

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳