2020-09-08 08:38:49 +00:00
|
|
|
package neofs
|
|
|
|
|
|
|
|
import (
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-09-08 08:38:49 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
key []byte
|
|
|
|
value []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (Config) MorphEvent() {}
|
|
|
|
|
|
|
|
func (u Config) Key() []byte { return u.key }
|
|
|
|
|
|
|
|
func (u Config) Value() []byte { return u.value }
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
func ParseConfig(params []stackitem.Item) (event.Event, error) {
|
2020-09-08 08:38:49 +00:00
|
|
|
var (
|
|
|
|
ev Config
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if ln := len(params); ln != 2 {
|
|
|
|
return nil, event.WrongNumberOfParameters(2, ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse key
|
2020-10-26 14:46:15 +00:00
|
|
|
ev.key, err = client.BytesFromStackItem(params[0])
|
2020-09-08 08:38:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get config key")
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse value
|
2020-10-26 14:46:15 +00:00
|
|
|
ev.value, err = client.BytesFromStackItem(params[1])
|
2020-09-08 08:38:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get config value")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|