forked from Web3N3/runchain
Add runner contract
This commit is contained in:
parent
5109ce9ba7
commit
bda71c7d43
4 changed files with 74 additions and 0 deletions
5
runnner/config.yml
Normal file
5
runnner/config.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
name: "Runner"
|
||||||
|
supportedstandards: []
|
||||||
|
events:
|
||||||
|
permissions:
|
||||||
|
- methods: []
|
5
runnner/go.mod
Normal file
5
runnner/go.mod
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module runner
|
||||||
|
|
||||||
|
go 1.23.1
|
||||||
|
|
||||||
|
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240912064531-e1d5ac8557d7
|
2
runnner/go.sum
Normal file
2
runnner/go.sum
Normal file
|
@ -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=
|
62
runnner/runner.go
Normal file
62
runnner/runner.go
Normal file
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in a new issue