diff --git a/runnner/config.yml b/runnner/config.yml new file mode 100644 index 0000000..dfe37b3 --- /dev/null +++ b/runnner/config.yml @@ -0,0 +1,5 @@ +name: "Runner" +supportedstandards: [] +events: +permissions: + - methods: [] \ No newline at end of file diff --git a/runnner/go.mod b/runnner/go.mod new file mode 100644 index 0000000..8c73f33 --- /dev/null +++ b/runnner/go.mod @@ -0,0 +1,5 @@ +module runner + +go 1.23.1 + +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240912064531-e1d5ac8557d7 diff --git a/runnner/go.sum b/runnner/go.sum new file mode 100644 index 0000000..bc3ed10 --- /dev/null +++ b/runnner/go.sum @@ -0,0 +1,2 @@ +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240912064531-e1d5ac8557d7 h1:M8YSwQMkcUA3TJ1uT53eZ8WDoXnpIcXsRMPs7CjowV0= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240912064531-e1d5ac8557d7/go.mod h1:kVLzmbeJJdbIPF2bUYhD8YppIiLXnRQj5yqNZvzbOL0= diff --git a/runnner/runner.go b/runnner/runner.go new file mode 100644 index 0000000..218a545 --- /dev/null +++ b/runnner/runner.go @@ -0,0 +1,62 @@ +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) +}