2021-12-01 09:14:10 +00:00
|
|
|
package morphsubnet
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
import "github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-12-01 09:14:10 +00:00
|
|
|
|
|
|
|
// ManageNodesPrm groups parameters of node management in Subnet contract.
|
|
|
|
//
|
|
|
|
// Zero value adds node to subnet. Subnet and node IDs must be specified via setters.
|
|
|
|
type ManageNodesPrm struct {
|
|
|
|
// remove or add node
|
|
|
|
rm bool
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
args [2]any
|
2021-12-01 09:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetRemove marks node to be removed. By default, node is added.
|
|
|
|
func (x *ManageNodesPrm) SetRemove() {
|
|
|
|
x.rm = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSubnet sets identifier of the subnet in a binary NeoFS API protocol format.
|
|
|
|
func (x *ManageNodesPrm) SetSubnet(id []byte) {
|
|
|
|
x.args[0] = id
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNode sets node's public key in a binary format.
|
|
|
|
func (x *ManageNodesPrm) SetNode(id []byte) {
|
|
|
|
x.args[1] = id
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ManageNodesRes groups the resulting values of node management methods of Subnet contract.
|
2021-12-01 09:14:10 +00:00
|
|
|
type ManageNodesRes struct{}
|
|
|
|
|
|
|
|
// ManageNodes manages node list of the NeoFS subnet through Subnet contract calls.
|
|
|
|
func (x Client) ManageNodes(prm ManageNodesPrm) (*ManageNodesRes, error) {
|
|
|
|
var method string
|
|
|
|
|
|
|
|
if prm.rm {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = removeNodeMethod
|
2021-12-01 09:14:10 +00:00
|
|
|
} else {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = addNodeMethod
|
2021-12-01 09:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var prmInvoke client.InvokePrm
|
|
|
|
|
|
|
|
prmInvoke.SetMethod(method)
|
|
|
|
prmInvoke.SetArgs(prm.args[:]...)
|
|
|
|
|
|
|
|
err := x.client.Invoke(prmInvoke)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return new(ManageNodesRes), nil
|
|
|
|
}
|