2021-05-31 11:50:11 +00:00
|
|
|
package netmap
|
|
|
|
|
2021-07-19 17:15:41 +00:00
|
|
|
import (
|
|
|
|
"crypto/elliptic"
|
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/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.
|
2021-11-10 10:44:19 +00:00
|
|
|
func (c *Client) UpdateInnerRing(p UpdateIRPrm) error {
|
|
|
|
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
|
|
|
|
|
|
|
return c.client.Invoke(prm)
|
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 {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%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 {
|
|
|
|
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", method, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return nil, fmt.Errorf("could not get stack item array (IRNode): %w", err)
|
|
|
|
} 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 {
|
|
|
|
return nil, fmt.Errorf("could not parse bytes from stack item (IRNode): %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys.NewPublicKeyFromBytes(byteKey, elliptic.P256())
|
|
|
|
}
|