package runner import ( "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) type Runner struct { name string controlPoints []ControlPoint } type ControlPoint struct { id int32 photo string } func NewRunner(runnerName string) { ctx := storage.GetContext() existingRunner := storage.Get(ctx, runnerName) if existingRunner != nil { panic("runnner already exists") } runner := Runner{ name: runnerName, controlPoints: make([]ControlPoint, 0), } storage.Put(ctx, runnerName, std.Serialize(runner)) } func Save(controlPointID int32, photo, runnerName string) { ctx := storage.GetReadOnlyContext() data := storage.Get(ctx, runnerName) if data == nil { panic("runner not found") } ctx = storage.GetContext() runner := std.Deserialize(data.([]byte)).(Runner) for _, controlPoint := range runner.controlPoints { if controlPoint.id == controlPointID { controlPoint.photo = photo storage.Put(ctx, runnerName, std.Serialize(runner)) return } } runner.controlPoints = append(runner.controlPoints, ControlPoint{id: controlPointID, photo: photo}) storage.Put(ctx, runnerName, std.Serialize(runner)) } func Get(runnerName string) Runner { ctx := storage.GetContext() data := storage.Get(ctx, runnerName) if data == nil { panic("runner not found") } return std.Deserialize(data.([]byte)).(Runner) }