wasmer

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: LGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "wasmer"

Name represents the name of the interpreter

Variables

View Source
var (
	ErrCodeEmpty      = errors.New("code is empty")
	ErrWASMDecompress = errors.New("wasm decompression failed")
)
View Source
var (
	ErrInstanceIsStopped      = errors.New("instance is stopped")
	ErrExportFunctionNotFound = errors.New("export function not found")
)
View Source
var DefaultTestLogLvl = log.Info

DefaultTestLogLvl is the log level used for test runtime instances

View Source
var (
	ErrGenesisTopNotFound = errors.New("genesis top not found")
)

Functions

func GetRuntimeVersion added in v0.7.0

func GetRuntimeVersion(code []byte) (version runtime.Version, err error)

GetRuntimeVersion finds the runtime version by initiating a temporary runtime instance using the WASM code provided, and querying it.

func NewRuntimeFromGenesis added in v0.3.0

func NewRuntimeFromGenesis(cfg Config) (instance runtime.Instance, err error)

NewRuntimeFromGenesis creates a runtime instance from the genesis data

func NewTrieFromGenesis added in v0.7.0

func NewTrieFromGenesis(gen genesis.Genesis) (tr trie.Trie, err error)

NewTrieFromGenesis creates a new trie from the raw genesis data

Types

type Config

type Config struct {
	Storage     runtime.Storage
	Keystore    *keystore.GlobalKeystore
	LogLvl      log.Level
	Role        common.Roles
	NodeStorage runtime.NodeStorage
	Network     runtime.BasicNetwork
	Transaction runtime.TransactionState
	CodeHash    common.Hash
	// contains filtered or unexported fields
}

Config is the configuration used to create a Wasmer runtime instance.

func (*Config) SetTestVersion added in v0.7.0

func (c *Config) SetTestVersion(t *testing.T, version runtime.Version)

SetTestVersion sets the test version for the runtime. WARNING: This should only be used for testing purposes. The *testing.T argument is only required to enforce this function to be used in tests only.

type Instance

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

Instance represents a v0.8 runtime go-wasmer instance

func NewInstance

func NewInstance(code []byte, cfg Config) (instance *Instance, err error)

NewInstance instantiates a runtime from raw wasm bytecode

func NewInstanceFromFile

func NewInstanceFromFile(fp string, cfg Config) (*Instance, error)

NewInstanceFromFile instantiates a runtime from a .wasm file

func NewInstanceFromTrie added in v0.3.0

func NewInstanceFromTrie(t *trie.Trie, cfg Config) (*Instance, error)

NewInstanceFromTrie returns a new runtime instance with the code provided in the given trie

func NewTestInstance

func NewTestInstance(t *testing.T, targetRuntime string) *Instance

NewTestInstance will create a new runtime instance using the given target runtime

func NewTestInstanceWithTrie

func NewTestInstanceWithTrie(t *testing.T, targetRuntime string, tt *trie.Trie) *Instance

NewTestInstanceWithTrie will create a new runtime (polkadot/test) with the supplied trie as the storage

func (*Instance) ApplyExtrinsic

func (in *Instance) ApplyExtrinsic(data types.Extrinsic) ([]byte, error)

ApplyExtrinsic calls runtime API function BlockBuilder_apply_extrinsic

func (*Instance) BabeConfiguration

func (in *Instance) BabeConfiguration() (*types.BabeConfiguration, error)

BabeConfiguration gets the configuration data for BABE from the runtime

func (*Instance) CheckInherents

func (in *Instance) CheckInherents()

func (*Instance) DecodeSessionKeys added in v0.7.0

func (in *Instance) DecodeSessionKeys(enc []byte) ([]byte, error)

DecodeSessionKeys decodes the given public session keys. Returns a list of raw public keys including their key type.

func (*Instance) Exec

func (in *Instance) Exec(function string, data []byte) (result []byte, err error)

Exec calls the given function with the given data

func (*Instance) ExecuteBlock

func (in *Instance) ExecuteBlock(block *types.Block) ([]byte, error)

ExecuteBlock calls runtime function Core_execute_block

func (*Instance) FinalizeBlock

func (in *Instance) FinalizeBlock() (*types.Header, error)

FinalizeBlock calls runtime API function BlockBuilder_finalize_block

func (*Instance) GenerateSessionKeys

func (in *Instance) GenerateSessionKeys()

func (*Instance) GetCodeHash added in v0.7.0

func (in *Instance) GetCodeHash() common.Hash

GetCodeHash returns the code of the instance

func (*Instance) GetContext added in v0.7.0

func (in *Instance) GetContext() *runtime.Context

GetContext returns the context of the instance

func (*Instance) GrandpaAuthorities

func (in *Instance) GrandpaAuthorities() ([]types.Authority, error)

GrandpaAuthorities returns the genesis authorities from the runtime

func (*Instance) InherentExtrinsics

func (in *Instance) InherentExtrinsics(data []byte) ([]byte, error)

InherentExtrinsics calls runtime API function BlockBuilder_inherent_extrinsics

func (*Instance) InitializeBlock

func (in *Instance) InitializeBlock(header *types.Header) error

InitializeBlock calls runtime API function Core_initialise_block

func (*Instance) Keystore added in v0.7.0

func (in *Instance) Keystore() *keystore.GlobalKeystore

Keystore to get reference to runtime keystore

func (*Instance) Metadata

func (in *Instance) Metadata() ([]byte, error)

Metadata calls runtime function Metadata_metadata

func (*Instance) NetworkService

func (in *Instance) NetworkService() runtime.BasicNetwork

NetworkService to get referernce to runtime network service

func (*Instance) NodeStorage

func (in *Instance) NodeStorage() runtime.NodeStorage

NodeStorage to get reference to runtime node service

func (*Instance) OffchainWorker

func (in *Instance) OffchainWorker()

func (*Instance) PaymentQueryInfo added in v0.7.0

func (in *Instance) PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)

PaymentQueryInfo returns information of a given extrinsic

func (*Instance) QueryCallFeeDetails added in v0.7.0

func (in *Instance) QueryCallFeeDetails(ext []byte) (*types.FeeDetails, error)

QueryCallFeeDetails returns call fee details for given call

func (*Instance) QueryCallInfo added in v0.7.0

func (in *Instance) QueryCallInfo(ext []byte) (*types.RuntimeDispatchInfo, error)

QueryCallInfo returns information of a given extrinsic

func (*Instance) RandomSeed

func (in *Instance) RandomSeed()

func (*Instance) SetContextStorage added in v0.3.0

func (in *Instance) SetContextStorage(s runtime.Storage)

SetContextStorage sets the runtime's storage. It should be set before calls to the below functions.

func (*Instance) Stop

func (in *Instance) Stop()

Stop closes the WASM instance, its imports and clears the context allocator in a thread-safe way.

func (*Instance) UpdateRuntimeCode added in v0.3.0

func (in *Instance) UpdateRuntimeCode(code []byte) (err error)

UpdateRuntimeCode updates the runtime instance to run the given code

func (*Instance) ValidateTransaction

func (in *Instance) ValidateTransaction(e types.Extrinsic) (
	*transaction.Validity, error)

ValidateTransaction runs the extrinsic through the runtime function TaggedTransactionQueue_validate_transaction and returns *transaction.Validity. The error can be a VDT of either transaction.InvalidTransaction or transaction.UnknownTransaction, or can represent a normal error i.e. unmarshalling error

func (*Instance) Validator added in v0.7.0

func (in *Instance) Validator() bool

Validator returns the context's Validator

func (*Instance) Version

func (in *Instance) Version() (version runtime.Version)

Version returns the instance version. This is cheap to call since the instance version is cached. Note the instance version is set at creation and on code update.

Jump to

Keyboard shortcuts

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