2020-09-03 14:04:04 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/elliptic"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
|
|
"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
|
|
|
|
status uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (UpdatePeer) MorphEvent() {}
|
|
|
|
|
|
|
|
func (s UpdatePeer) Status() uint32 {
|
|
|
|
return s.status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s UpdatePeer) PublicKey() *keys.PublicKey {
|
|
|
|
return s.publicKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseUpdatePeer(prms []smartcontract.Parameter) (event.Event, error) {
|
|
|
|
var (
|
|
|
|
ev UpdatePeer
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if ln := len(prms); ln != 2 {
|
|
|
|
return nil, event.WrongNumberOfParameters(2, ln)
|
|
|
|
}
|
|
|
|
|
2020-10-05 15:29:06 +00:00
|
|
|
// parse node status
|
|
|
|
st, err := client.IntFromStackParameter(prms[0])
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not get node status")
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.status = uint32(st)
|
|
|
|
|
2020-09-03 14:04:04 +00:00
|
|
|
// parse public key
|
2020-10-05 15:29:06 +00:00
|
|
|
key, err := client.BytesFromStackParameter(prms[1])
|
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")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|