frostfs-node/pkg/morph/client/netmap/innerring.go
Pavel Karpy 1db6d316c2 [#971] morph/client: Adapt signature changes in wrappers
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-11-19 09:58:03 +03:00

83 lines
2.1 KiB
Go

package netmap
import (
"crypto/elliptic"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// UpdateInnerRing updates inner ring members in netmap contract.
func (c *Client) UpdateInnerRing(keys keys.PublicKeys) error {
args := make([][]byte, len(keys))
for i := range args {
args[i] = keys[i].Bytes()
}
prm := client.InvokePrm{}
prm.SetMethod(c.updateInnerRing)
prm.SetArgs(args)
return c.client.Invoke(prm)
}
// InnerRingList returns public keys of inner ring members in
// netmap contract.
func (c *Client) InnerRingList() (keys.PublicKeys, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(c.innerRingList)
prms, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.innerRingList, err)
}
return irKeysFromStackItem(prms, c.innerRingList)
}
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())
}