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