Documentation ¶
Index ¶
- type CodeID
- type GasMeter
- type GoAPI
- type KVStore
- type Querier
- 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, info types.MessageInfo, executeMsg []byte, ...) (*types.HandleResponse, uint64, error)
- func (w *Wasmer) GetCode(code CodeID) (WasmCode, error)
- func (w *Wasmer) Instantiate(code CodeID, env types.Env, info types.MessageInfo, initMsg []byte, ...) (*types.InitResponse, uint64, error)
- func (w *Wasmer) Migrate(code CodeID, env types.Env, info types.MessageInfo, migrateMsg []byte, ...) (*types.MigrateResponse, uint64, error)
- func (w *Wasmer) Query(code CodeID, env types.Env, queryMsg []byte, store KVStore, goapi GoAPI, ...) ([]byte, uint64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodeID ¶
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 ¶
func (w *Wasmer) Execute( code CodeID, env types.Env, info types.MessageInfo, executeMsg []byte, store KVStore, goapi GoAPI, querier Querier, gasMeter GasMeter, gasLimit uint64, ) (*types.HandleResponse, uint64, 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)
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, info types.MessageInfo, initMsg []byte, store KVStore, goapi GoAPI, querier Querier, gasMeter GasMeter, gasLimit uint64, ) (*types.InitResponse, uint64, 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.
func (*Wasmer) Migrate ¶
func (w *Wasmer) Migrate( code CodeID, env types.Env, info types.MessageInfo, migrateMsg []byte, store KVStore, goapi GoAPI, querier Querier, gasMeter GasMeter, gasLimit uint64, ) (*types.MigrateResponse, uint64, error)
Migrate will migrate an existing contract to a new code binary. This takes storage of the data from the original contract and the CodeID of the new contract that should replace it. This allows it to run a migration step if needed, or return an error if unable to migrate the given data.
MigrateMsg has some data on how to perform the migration.
func (*Wasmer) Query ¶
func (w *Wasmer) Query( code CodeID, env types.Env, queryMsg []byte, store KVStore, goapi GoAPI, querier Querier, gasMeter GasMeter, 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