Skip to content

Commit

Permalink
Add WasmRuntime interface for comprehensive WASM contract lifecycle m…
Browse files Browse the repository at this point in the history
…anagement

This commit introduces a new WasmRuntime interface that defines a comprehensive set of methods for managing WebAssembly smart contract lifecycles, including:
- Code storage and management operations
- Contract instantiation, execution, and migration methods
- IBC (Inter-Blockchain Communication) entry points
- Caching and resource management
- Metrics retrieval

The interface provides a flexible and extensible approach to handling WASM contract interactions across different runtime environments.
  • Loading branch information
faddat committed Feb 14, 2025
1 parent 230077e commit 6c9103b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions internal/interface/wasmruntime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// file: internal/runtime/wasm_runtime.go
package runtime

import "github.com/CosmWasm/wasmvm/v2/types"

type WasmRuntime interface {
// InitCache sets up any runtime-specific cache or resources. Returns a handle.
InitCache(config types.VMConfig) (any, error)

// ReleaseCache frees resources created by InitCache.
ReleaseCache(handle any)

// Compilation and code storage
StoreCode(code []byte, persist bool) (checksum []byte, err error)
StoreCodeUnchecked(code []byte) ([]byte, error)
GetCode(checksum []byte) ([]byte, error)
RemoveCode(checksum []byte) error
Pin(checksum []byte) error
Unpin(checksum []byte) error
AnalyzeCode(checksum []byte) (*types.AnalysisReport, error)

// Execution lifecycles
Instantiate(checksum []byte, env []byte, info []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
Execute(checksum []byte, env []byte, info []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
Migrate(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
MigrateWithInfo(checksum []byte, env []byte, msg []byte, migrateInfo []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
Sudo(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
Reply(checksum []byte, env []byte, reply []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
Query(checksum []byte, env []byte, query []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)

// IBC entry points
IBCChannelOpen(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
IBCChannelConnect(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
IBCChannelClose(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
IBCPacketReceive(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
IBCPacketAck(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
IBCPacketTimeout(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
IBCSourceCallback(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)
IBCDestinationCallback(checksum []byte, env []byte, msg []byte, otherParams ...interface{}) ([]byte, types.GasReport, error)

// Metrics
GetMetrics() (*types.Metrics, error)
GetPinnedMetrics() (*types.PinnedMetrics, error)
}

0 comments on commit 6c9103b

Please sign in to comment.