2020-09-08 08:37:58 +00:00
|
|
|
package neofs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/elliptic"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
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"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Bind struct {
|
|
|
|
user util.Uint160
|
|
|
|
keys []*keys.PublicKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (Bind) MorphEvent() {}
|
|
|
|
|
|
|
|
func (b Bind) Keys() []*keys.PublicKey { return b.keys }
|
|
|
|
|
|
|
|
func (b Bind) User() util.Uint160 { return b.user }
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
if ln := len(params); ln != 2 {
|
|
|
|
return nil, event.WrongNumberOfParameters(2, ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse user
|
2020-10-26 14:46:15 +00:00
|
|
|
user, err := client.BytesFromStackItem(params[0])
|
2020-09-08 08:37:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get bind user")
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.user, err = util.Uint160DecodeBytesBE(user)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not convert bind user to uint160")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
return nil, errors.Wrap(err, "could not get bind keys")
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.keys = make([]*keys.PublicKey, 0, len(bindKeys))
|
|
|
|
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 {
|
|
|
|
return nil, errors.Wrap(err, "could not get bind public key")
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := keys.NewPublicKeyFromBytes(rawKey, elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse bind public key")
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.keys = append(ev.keys, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|