frostfs-node/pkg/morph/event/neofs/bind.go
Leonard Lyubich f76083484b [#556] morph/container: Do not parse public key in Put event parser
Morph event structures defined in `pkg/morph/event` should only carry
notification values without any additional interpretation. All logical work
should be concentrated on app-side. Change `Bind.User` / `Unbind.User` to
return byte slice. Change `Bind.Keys` / `Unbind.Keys` to return `[][]byte`.
`ParseBind` / `ParseUnbind` don't decode data from now.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-06-02 10:50:44 +03:00

72 lines
1.4 KiB
Go

package neofs
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
)
type Bind struct {
bindCommon
}
type bindCommon struct {
user []byte
keys [][]byte
}
// MorphEvent implements Neo:Morph Event interface.
func (bindCommon) MorphEvent() {}
func (b bindCommon) Keys() [][]byte { return b.keys }
func (b bindCommon) User() []byte { return b.user }
func ParseBind(params []stackitem.Item) (event.Event, error) {
var (
ev Bind
err error
)
err = parseBind(&ev.bindCommon, params)
if err != nil {
return nil, err
}
return ev, nil
}
func parseBind(dst *bindCommon, params []stackitem.Item) error {
if ln := len(params); ln != 2 {
return event.WrongNumberOfParameters(2, ln)
}
var err error
// parse user
dst.user, err = client.BytesFromStackItem(params[0])
if err != nil {
return fmt.Errorf("could not get bind user: %w", err)
}
// parse keys
bindKeys, err := client.ArrayFromStackItem(params[1])
if err != nil {
return fmt.Errorf("could not get bind keys: %w", err)
}
dst.keys = make([][]byte, 0, len(bindKeys))
for i := range bindKeys {
rawKey, err := client.BytesFromStackItem(bindKeys[i])
if err != nil {
return fmt.Errorf("could not get bind public key: %w", err)
}
dst.keys = append(dst.keys, rawKey)
}
return nil
}