github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/types/wasm/instance.go (about) 1 package wasm 2 3 import ( 4 "context" 5 6 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 7 "github.com/machinefi/w3bstream/pkg/enums" 8 ) 9 10 type VM interface { 11 Name() string 12 Init() 13 NewModule(code []byte) Module 14 } 15 16 type Module interface { 17 Init() 18 NewInstance() Instance 19 GetABI() []string 20 } 21 22 type Instance interface { 23 ID() string 24 Start(context.Context) error 25 Stop(context.Context) error 26 State() enums.InstanceState 27 // AddResource(context.Context, []byte) uint32 28 // RmvResource(context.Context, uint32) 29 // GetResource(uint32) ([]byte, bool) 30 // Get(k string) int32 31 32 EventConsumer 33 } 34 35 type EventHandleResult struct { 36 InstanceID string `json:"instanceID"` 37 Rsp []byte `json:"-"` 38 Code ResultStatusCode `json:"code"` 39 ErrMsg string `json:"errMsg"` 40 } 41 42 type EventConsumer interface { 43 HandleEvent(ctx context.Context, handler, eventType string, payload []byte) *EventHandleResult 44 } 45 46 type KVStore interface { 47 Get(string) ([]byte, error) 48 Set(key string, value []byte) error 49 } 50 51 type SQLStore interface { 52 sqlx.SqlExecutor 53 } 54 55 type ContextHandler interface { 56 Name() string 57 GetImports() ImportsHandler 58 SetImports(ImportsHandler) 59 GetExports() ExportsHandler 60 GetInstance() Instance 61 SetInstance(Instance) 62 } 63 64 type ABI interface { 65 Log(loglevel, ptr, size int32) int32 66 GetData(rid, vmAddrPtr, vmSizePtr int32) int32 67 SetData(rid, addr, size int32) int32 68 GetDB(kAddr, kSize, vmAddrPtr, vmSizePtr int32) int32 69 SetDB(kAddr, kSize, vAddr, vSize int32) int32 70 SendTX(chainid int32, offset, size, vmAddrPtr, vmSizePtr int32) int32 71 CallContract(chainid int32, offset, size, vmAddrPtr, vmSizePtr int32) int32 72 SetSQLDB(addr, size int32) int32 73 GetSQLDB(addr, size, vmAddrPtr, vmSizePtr int32) int32 74 GetEnv(kAddr, kSize, vmAddrPtr, vmSizePtr int32) int32 75 SendMqttMsg(topicAddr, topicSize, msgAddr, msgSize int32) int32 76 } 77 78 type Memory interface { 79 Read(context.Context, uint32, uint32) ([]byte, error) 80 Write(context.Context, []byte) 81 } 82 83 type ImportsHandler interface { 84 GetDB(keyAddr, keySize, valAddr, valSize uint32) (code int32) 85 SetDB() 86 GetData() 87 SetData() 88 Log(level uint32) 89 } 90 91 type Handler interface { 92 Name() string 93 Call(context.Context, ...interface{}) 94 } 95 96 type ExportsHandler interface { 97 Start() 98 Alloc() 99 Free() 100 }