Documentation
¶
Index ¶
- type CodeID
- type GoAPI
- type KVStore
- type WasmCode
- type Wasmer
- func (w *Wasmer) Cleanup()
- func (w *Wasmer) Create(code WasmCode) (CodeID, error)
- func (w *Wasmer) Execute(code CodeID, env types.Env, executeMsg []byte, store KVStore, goapi GoAPI, ...) (*types.Result, error)
- func (w *Wasmer) GetCode(code CodeID) (WasmCode, error)
- func (w *Wasmer) Instantiate(code CodeID, env types.Env, initMsg []byte, store KVStore, goapi GoAPI, ...) (*types.Result, error)
- func (w *Wasmer) Query(code CodeID, queryMsg []byte, store KVStore, goapi GoAPI, gasLimit uint64) ([]byte, uint64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodeID ¶ added in v0.2.0
type CodeID []byte
CodeID represents an ID for a given wasm code blob, must be generated from this library
type Wasmer ¶
type Wasmer struct {
// contains filtered or unexported fields
}
Wasmer is the main entry point to this library. You should create an instance with it's own subdirectory to manage state inside, and call it for all cosmwasm code related actions.
func NewWasmer ¶
NewWasmer creates an new binding, with the given dataDir where it can store raw wasm and the pre-compile cache. cacheSize sets the size of an optional in-memory LRU cache for prepared VMs. They allow popular contracts to be executed very rapidly (no loading overhead), but require ~32-64MB each in memory usage.
func (*Wasmer) Cleanup ¶
func (w *Wasmer) Cleanup()
Cleanup should be called when no longer using this to free resources on the rust-side
func (*Wasmer) Create ¶
Create will compile the wasm code, and store the resulting pre-compile as well as the original code. Both can be referenced later via CodeID This must be done one time for given code, after which it can be instatitated many times, and each instance called many times.
For example, the code for all ERC-20 contracts should be the same. This function stores the code for that contract only once, but it can be instantiated with custom inputs in the future.
TODO: return gas cost? Add gas limit??? there is no metering here...
func (*Wasmer) Execute ¶ added in v0.3.0
func (w *Wasmer) Execute(code CodeID, env types.Env, executeMsg []byte, store KVStore, goapi GoAPI, gasLimit uint64) (*types.Result, error)
Execute calls a given contract. Since the only difference between contracts with the same CodeID is the data in their local storage, and their address in the outside world, we need no ContractID here. (That is a detail for the external, sdk-facing, side).
The caller is responsible for passing the correct `store` (which must have been initialized exactly once), and setting the env with relevent info on this instance (address, balance, etc)
TODO: add callback for querying into other modules
func (*Wasmer) GetCode ¶
GetCode will load the original wasm code for the given code id. This will only succeed if that code id was previously returned from a call to Create.
This can be used so that the (short) code id (hash) is stored in the iavl tree and the larger binary blobs (wasm and pre-compiles) are all managed by the rust library
func (*Wasmer) Instantiate ¶
func (w *Wasmer) Instantiate(code CodeID, env types.Env, initMsg []byte, store KVStore, goapi GoAPI, gasLimit uint64) (*types.Result, error)
Instantiate will create a new contract based on the given codeID. We can set the initMsg (contract "genesis") here, and it then receives an account and address and can be invoked (Execute) many times.
Storage should be set with a PrefixedKVStore that this code can safely access.
Under the hood, we may recompile the wasm, use a cached native compile, or even use a cached instance for performance.
TODO: clarify which errors are returned? vm failure. out of gas. code unauthorized. TODO: add callback for querying into other modules
func (*Wasmer) Query ¶
func (w *Wasmer) Query(code CodeID, queryMsg []byte, store KVStore, goapi GoAPI, gasLimit uint64) ([]byte, uint64, error)
Query allows a client to execute a contract-specific query. If the result is not empty, it should be valid json-encoded data to return to the client. The meaning of path and data can be determined by the code. Path is the suffix of the abci.QueryRequest.Path