2021-05-31 11:50:11 +00:00
|
|
|
package netmap
|
|
|
|
|
2021-07-19 17:15:41 +00:00
|
|
|
import (
|
2024-10-21 13:27:28 +00:00
|
|
|
"context"
|
2021-07-19 17:15:41 +00:00
|
|
|
"crypto/elliptic"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-07-19 17:15:41 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
)
|
2021-05-31 11:50:11 +00:00
|
|
|
|
2021-11-10 10:44:19 +00:00
|
|
|
// UpdateIRPrm groups parameters of UpdateInnerRing
|
|
|
|
// invocation.
|
|
|
|
type UpdateIRPrm struct {
|
|
|
|
keys keys.PublicKeys
|
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetKeys sets new inner ring keys.
|
|
|
|
func (u *UpdateIRPrm) SetKeys(keys keys.PublicKeys) {
|
|
|
|
u.keys = keys
|
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// UpdateInnerRing updates inner ring keys.
|
2024-10-21 13:27:28 +00:00
|
|
|
func (c *Client) UpdateInnerRing(ctx context.Context, p UpdateIRPrm) error {
|
2021-11-10 10:44:19 +00:00
|
|
|
args := make([][]byte, len(p.keys))
|
2021-05-31 11:50:11 +00:00
|
|
|
for i := range args {
|
2021-11-10 10:44:19 +00:00
|
|
|
args[i] = p.keys[i].Bytes()
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(updateInnerRingMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
prm.SetArgs(args)
|
2021-11-10 10:44:19 +00:00
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
_, err := c.client.Invoke(ctx, prm)
|
2023-11-07 15:13:26 +00:00
|
|
|
return err
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|
2021-07-19 17:15:41 +00:00
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// GetInnerRingList return current IR list.
|
|
|
|
func (c *Client) GetInnerRingList() (keys.PublicKeys, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(innerRingListMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
prms, err := c.client.TestInvoke(invokePrm)
|
2021-07-19 17:15:41 +00:00
|
|
|
if err != nil {
|
2024-12-04 08:17:13 +00:00
|
|
|
return nil, fmt.Errorf("test invoke (%s): %w", innerRingListMethod, err)
|
2021-07-19 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
return irKeysFromStackItem(prms, innerRingListMethod)
|
2021-07-19 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func irKeysFromStackItem(stack []stackitem.Item, method string) (keys.PublicKeys, error) {
|
|
|
|
if ln := len(stack); ln != 1 {
|
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
irs, err := client.ArrayFromStackItem(stack[0])
|
|
|
|
if err != nil {
|
2024-12-12 12:06:20 +00:00
|
|
|
return nil, fmt.Errorf("get stack item array from stack item (%s): %w", method, err)
|
2021-07-19 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
irKeys := make(keys.PublicKeys, len(irs))
|
|
|
|
|
|
|
|
for i := range irs {
|
|
|
|
irKeys[i], err = irKeyFromStackItem(irs[i])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return irKeys, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const irNodeFixedPrmNumber = 1
|
|
|
|
|
|
|
|
func irKeyFromStackItem(prm stackitem.Item) (*keys.PublicKey, error) {
|
|
|
|
prms, err := client.ArrayFromStackItem(prm)
|
|
|
|
if err != nil {
|
2024-12-12 12:06:20 +00:00
|
|
|
return nil, fmt.Errorf("get stack item array (IRNode): %w", err)
|
2021-07-19 17:15:41 +00:00
|
|
|
} else if ln := len(prms); ln != irNodeFixedPrmNumber {
|
|
|
|
return nil, fmt.Errorf(
|
|
|
|
"unexpected stack item count (IRNode): expected %d, has %d",
|
|
|
|
irNodeFixedPrmNumber,
|
|
|
|
ln,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
byteKey, err := client.BytesFromStackItem(prms[0])
|
|
|
|
if err != nil {
|
2024-12-12 12:06:20 +00:00
|
|
|
return nil, fmt.Errorf("parse bytes from stack item (IRNode): %w", err)
|
2021-07-19 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return keys.NewPublicKeyFromBytes(byteKey, elliptic.P256())
|
|
|
|
}
|