github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/vm/instance_new.go (about) 1 package vm 2 3 import ( 4 "context" 5 6 "github.com/machinefi/w3bstream/pkg/depends/kit/logr" 7 "github.com/machinefi/w3bstream/pkg/enums" 8 "github.com/machinefi/w3bstream/pkg/modules/vm/wasmtime" 9 "github.com/machinefi/w3bstream/pkg/types" 10 ) 11 12 func NewInstance(ctx context.Context, code []byte, id types.SFID, state enums.InstanceState) error { 13 ctx, l := logr.Start(ctx, "vm.NewInstance") 14 defer l.End() 15 16 ins, err := wasmtime.NewInstanceByCode(ctx, id, code, state) 17 if err != nil { 18 l.Error(err) 19 return err 20 } 21 AddInstanceByID(ctx, id, ins) 22 l.WithValues("instance_id", id, "state", state.String()).Info("instance created") 23 return nil 24 }