Skip to content

Commit

Permalink
morph: add method for container's members updates
Browse files Browse the repository at this point in the history
Follows nspcc-dev/neofs-contract#438.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Dec 11, 2024
1 parent 8f125a0 commit f36e9ca
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/morph/client/container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (

// putNamedMethod is method name for container put with an alias. It is exported to provide custom fee.
putNamedMethod = "putNamed"

addNextEpochNodes = "addNextEpochNodes"
commitContainerListUpdate = "commitContainerListUpdate"
)

var (
Expand Down
50 changes: 50 additions & 0 deletions pkg/morph/client/container/nodes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package container

import (
"fmt"

"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)

// AddNextEpochNodes registers public keys as a container's placement vector
// with specified index. Registration must be finished with final
// [Client.CommitContainerListUpdate] call. Always sends a notary request with
// Alphabet multi-signature.
func (c *Client) AddNextEpochNodes(cid []byte, placementIndex int, nodesKeys [][]byte) error {
if len(cid) == 0 || len(nodesKeys) == 0 {
return errNilArgument
}

prm := client.InvokePrm{}
prm.SetMethod(addNextEpochNodes)
prm.SetArgs(cid, placementIndex, nodesKeys)
prm.RequireAlphabetSignature()

err := c.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", addNextEpochNodes, err)
}

return nil
}

// CommitContainerListUpdate finishes container placement updates for the current
// epoch made by former [Client.AddNextEpochNodes] calls. Always sends a notary
// request with Alphabet multi-signature.
func (c *Client) CommitContainerListUpdate(cid []byte, replicas []uint32) error {
if len(cid) == 0 || len(replicas) == 0 {
return errNilArgument
}

prm := client.InvokePrm{}
prm.SetMethod(commitContainerListUpdate)
prm.SetArgs(cid, replicas)
prm.RequireAlphabetSignature()

err := c.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", commitContainerListUpdate, err)
}

return nil
}

0 comments on commit f36e9ca

Please sign in to comment.