2020-09-03 14:04:04 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/elliptic"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-11-16 10:26:35 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
|
|
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
2020-09-03 14:04:04 +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 UpdatePeer struct {
|
|
|
|
publicKey *keys.PublicKey
|
2020-11-16 10:26:35 +00:00
|
|
|
status netmap.NodeState
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (UpdatePeer) MorphEvent() {}
|
|
|
|
|
2020-11-16 10:26:35 +00:00
|
|
|
func (s UpdatePeer) Status() netmap.NodeState {
|
2020-09-03 14:04:04 +00:00
|
|
|
return s.status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s UpdatePeer) PublicKey() *keys.PublicKey {
|
|
|
|
return s.publicKey
|
|
|
|
}
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
func ParseUpdatePeer(prms []stackitem.Item) (event.Event, error) {
|
2020-09-03 14:04:04 +00:00
|
|
|
var (
|
|
|
|
ev UpdatePeer
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if ln := len(prms); ln != 2 {
|
|
|
|
return nil, event.WrongNumberOfParameters(2, ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse public key
|
2020-10-26 14:46:15 +00:00
|
|
|
key, err := client.BytesFromStackItem(prms[0])
|
2020-09-03 14:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get public key")
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.publicKey, err = keys.NewPublicKeyFromBytes(key, elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not parse public key")
|
|
|
|
}
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
// parse node status
|
|
|
|
st, err := client.IntFromStackItem(prms[1])
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get node status")
|
|
|
|
}
|
|
|
|
|
2020-11-16 10:26:35 +00:00
|
|
|
ev.status = netmap.NodeStateFromV2(v2netmap.NodeState(st))
|
2020-10-26 14:46:15 +00:00
|
|
|
|
2020-09-03 14:04:04 +00:00
|
|
|
return ev, nil
|
|
|
|
}
|