forked from TrueCloudLab/frostfs-node
[#971] morph/netmap: Add optional parameters
Add optional parameters to the client call signature. Group parameters of a client call into struct to improve future codebase support. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
3114be39d0
commit
c25f5a86ae
11 changed files with 224 additions and 90 deletions
|
@ -4,23 +4,37 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
)
|
||||
|
||||
// AddPeerPrm groups parameters of AddPeer operation.
|
||||
type AddPeerPrm struct {
|
||||
nodeInfo *netmap.NodeInfo
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetNodeInfo sets new peer NodeInfo.
|
||||
func (a *AddPeerPrm) SetNodeInfo(nodeInfo *netmap.NodeInfo) {
|
||||
a.nodeInfo = nodeInfo
|
||||
}
|
||||
|
||||
// AddPeer registers peer in NeoFS network through
|
||||
// Netmap contract call.
|
||||
func (w *Wrapper) AddPeer(nodeInfo *netmap.NodeInfo) error {
|
||||
if nodeInfo == nil {
|
||||
func (w *Wrapper) AddPeer(prm AddPeerPrm) error {
|
||||
if prm.nodeInfo == nil {
|
||||
return errors.New("nil node info")
|
||||
}
|
||||
|
||||
rawNodeInfo, err := nodeInfo.Marshal()
|
||||
rawNodeInfo, err := prm.nodeInfo.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
args := netmap.AddPeerArgs{}
|
||||
args.SetInfo(rawNodeInfo)
|
||||
args.InvokePrmOptional = prm.InvokePrmOptional
|
||||
|
||||
if err := w.client.AddPeer(args); err != nil {
|
||||
return fmt.Errorf("could not invoke smart contract: %w", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue