2022-12-23 17:35:35 +00:00
|
|
|
package frostfs
|
2020-09-08 08:39:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/elliptic"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-09-08 08:39:09 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
2020-09-08 08:39:09 +00:00
|
|
|
"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-09-08 08:39:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type UpdateInnerRing struct {
|
|
|
|
keys []*keys.PublicKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (UpdateInnerRing) MorphEvent() {}
|
|
|
|
|
|
|
|
func (u UpdateInnerRing) Keys() []*keys.PublicKey { return u.keys }
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
func ParseUpdateInnerRing(params []stackitem.Item) (event.Event, error) {
|
2020-09-08 08:39:09 +00:00
|
|
|
var (
|
|
|
|
ev UpdateInnerRing
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if ln := len(params); ln != 1 {
|
|
|
|
return nil, event.WrongNumberOfParameters(1, ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse keys
|
2020-10-26 14:46:15 +00:00
|
|
|
irKeys, err := client.ArrayFromStackItem(params[0])
|
2020-09-08 08:39:09 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get updated inner ring keys: %w", err)
|
2020-09-08 08:39:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ev.keys = make([]*keys.PublicKey, 0, len(irKeys))
|
|
|
|
for i := range irKeys {
|
2020-10-26 14:46:15 +00:00
|
|
|
rawKey, err := client.BytesFromStackItem(irKeys[i])
|
2020-09-08 08:39:09 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get updated inner ring public key: %w", err)
|
2020-09-08 08:39:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
key, err := keys.NewPublicKeyFromBytes(rawKey, elliptic.P256())
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not parse updated inner ring public key: %w", err)
|
2020-09-08 08:39:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ev.keys = append(ev.keys, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ev, nil
|
|
|
|
}
|