2021-09-09 11:55:01 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/elliptic"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
2021-09-09 11:55:01 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
|
|
|
)
|
|
|
|
|
2024-12-12 11:59:49 +00:00
|
|
|
var errNilPubKey = errors.New("public key is nil")
|
2021-09-09 11:55:01 +00:00
|
|
|
|
|
|
|
func (s *UpdatePeer) setPublicKey(v []byte) (err error) {
|
|
|
|
if v == nil {
|
|
|
|
return errNilPubKey
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:57:27 +00:00
|
|
|
s.PubKey, err = keys.NewPublicKeyFromBytes(v, elliptic.P256())
|
2021-09-09 11:55:01 +00:00
|
|
|
if err != nil {
|
2024-12-12 11:59:49 +00:00
|
|
|
return fmt.Errorf("parse public key: %w", err)
|
2021-09-09 11:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
// UpdateStateNotaryEvent is method name for netmap state updating
|
|
|
|
// operations in `Netmap` contract. Is used as identificator for
|
|
|
|
// notary delete container requests.
|
|
|
|
UpdateStateNotaryEvent = "updateState"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ParseUpdatePeerNotary from NotaryEvent into netmap event structure.
|
|
|
|
func ParseUpdatePeerNotary(ne event.NotaryEvent) (event.Event, error) {
|
|
|
|
var (
|
|
|
|
ev UpdatePeer
|
|
|
|
err error
|
|
|
|
|
|
|
|
currCode opcode.Opcode
|
|
|
|
)
|
|
|
|
|
|
|
|
fieldNum := 0
|
|
|
|
|
|
|
|
for _, op := range ne.Params() {
|
|
|
|
currCode = op.Code()
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case fieldNum == 0 && opcode.PUSHDATA1 <= currCode && currCode <= opcode.PUSHDATA4:
|
|
|
|
err = ev.setPublicKey(op.Param())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldNum++
|
|
|
|
case fieldNum == 1:
|
|
|
|
state, err := event.IntFromOpcode(op)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-28 11:34:28 +00:00
|
|
|
err = ev.decodeState(state)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-06-08 23:18:26 +00:00
|
|
|
}
|
2021-09-09 11:55:01 +00:00
|
|
|
|
|
|
|
fieldNum++
|
|
|
|
case fieldNum == expectedItemNumUpdatePeer:
|
|
|
|
return nil, event.UnexpectedArgNumErr(UpdateStateNotaryEvent)
|
|
|
|
default:
|
|
|
|
return nil, event.UnexpectedOpcode(UpdateStateNotaryEvent, currCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:57:27 +00:00
|
|
|
ev.Request = ne.Raw()
|
2021-09-09 11:55:01 +00:00
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|