Documentation ¶
Index ¶
- func AppendReplyInternalDataToData(data []byte, internaReplyEnclaveSig []byte, internalMsgId []byte) ([]byte, error)
- type CodeID
- type ContractExecResponse
- type GasMeter
- type GoAPI
- type KVStore
- type Querier
- type V010ContractExecResponse
- type V010ContractInitResponse
- type V010orV1ContractInitResponse
- type V1ContractExecResponse
- type V1ContractInitResponse
- type WasmCode
- type Wasmer
- func (w *Wasmer) AnalyzeCode(codeHash []byte) (*v1types.AnalysisReport, error)
- 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, ...) (interface{}, uint64, error)
- func (w *Wasmer) GetCode(code CodeID) (WasmCode, error)
- func (w *Wasmer) Instantiate(codeId CodeID, env types.Env, initMsg []byte, store KVStore, goapi GoAPI, ...) (interface{}, []byte, 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 ¶
Types ¶
type CodeID ¶
type CodeID []byte
CodeID represents an ID for a given wasm code blob, must be generated from this library
type ContractExecResponse ¶
type ContractExecResponse struct { V1 *V1ContractExecResponse `json:"v1,omitempty"` V010 *V010ContractExecResponse `json:"v010,omitempty"` InternaReplyEnclaveSig []byte `json:"internal_reply_enclave_sig"` InternalMsgId []byte `json:"internal_msg_id"` IBCBasic *v1types.IBCBasicResult `json:"ibc_basic,omitempty"` IBCPacketReceive *v1types.IBCReceiveResult `json:"ibc_packet_receive,omitempty"` IBCChannelOpen *v1types.IBCOpenChannelResult `json:"ibc_open_channel,omitempty"` }
This struct helps us to distinguish between v0.10 contract response and v1 contract response
type V010ContractExecResponse ¶
type V010ContractExecResponse struct { Ok *v010types.HandleResponse `json:"Ok,omitempty"` Err *types.StdError `json:"Err,omitempty"` }
type V010ContractInitResponse ¶
type V010ContractInitResponse struct { Ok *v010types.InitResponse `json:"Ok,omitempty"` Err *types.StdError `json:"Err,omitempty"` }
type V010orV1ContractInitResponse ¶
type V010orV1ContractInitResponse struct { V1 *V1ContractInitResponse `json:"v1,omitempty"` V010 *V010ContractInitResponse `json:"v010,omitempty"` InternaReplyEnclaveSig []byte `json:"internal_reply_enclave_sig"` InternalMsgId []byte `json:"internal_msg_id"` }
type V1ContractExecResponse ¶
type V1ContractInitResponse ¶
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 ¶
func NewWasmer(dataDir string, supportedFeatures string, cacheSize uint64, moduleCacheSize uint8) (*Wasmer, error)
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) AnalyzeCode ¶
func (w *Wasmer) AnalyzeCode( codeHash []byte, ) (*v1types.AnalysisReport, error)
AnalyzeCode returns a report of static analysis of the wasm contract (uncompiled). This contract must have been stored in the cache previously (via Create). Only info currently returned is if it exposes all ibc entry points, but this may grow later
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, executeMsg []byte, store KVStore, goapi GoAPI, querier Querier, gasMeter GasMeter, gasLimit uint64, sigInfo types.VerificationInfo, handleType types.HandleType, ) (interface{}, 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 relevant 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( codeId CodeID, env types.Env, initMsg []byte, store KVStore, goapi GoAPI, querier Querier, gasMeter GasMeter, gasLimit uint64, sigInfo types.VerificationInfo, contractAddress sdk.AccAddress, ) (interface{}, []byte, 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) 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