/
wasmer_engine.go
102 lines (93 loc) · 3.71 KB
/
wasmer_engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package types
import (
"github.com/CosmWasm/wasmvm"
"github.com/CosmWasm/wasmvm/types"
)
// WasmerEngine defines the WASM contract runtime engine.
type WasmerEngine interface {
// 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.
Create(code cosmwasm.WasmCode) (cosmwasm.CodeID, 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.
Instantiate(
code cosmwasm.CodeID,
env types.Env,
info types.MessageInfo,
initMsg []byte,
store cosmwasm.KVStore,
goapi cosmwasm.GoAPI,
querier cosmwasm.Querier,
gasMeter cosmwasm.GasMeter,
gasLimit uint64,
) (*types.InitResponse, 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)
Execute(
code cosmwasm.CodeID,
env types.Env,
info types.MessageInfo,
executeMsg []byte,
store cosmwasm.KVStore,
goapi cosmwasm.GoAPI,
querier cosmwasm.Querier,
gasMeter cosmwasm.GasMeter,
gasLimit uint64,
) (*types.HandleResponse, 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
Query(
code cosmwasm.CodeID,
env types.Env,
queryMsg []byte,
store cosmwasm.KVStore,
goapi cosmwasm.GoAPI,
querier cosmwasm.Querier,
gasMeter cosmwasm.GasMeter,
gasLimit uint64,
) ([]byte, 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.
Migrate(
code cosmwasm.CodeID,
env types.Env,
info types.MessageInfo,
migrateMsg []byte,
store cosmwasm.KVStore,
goapi cosmwasm.GoAPI,
querier cosmwasm.Querier,
gasMeter cosmwasm.GasMeter,
gasLimit uint64,
) (*types.MigrateResponse, uint64, error)
// 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
GetCode(code cosmwasm.CodeID) (cosmwasm.WasmCode, error)
// Cleanup should be called when no longer using this to free resources on the rust-side
Cleanup()
}