frostfs-node/pkg/morph/client/netmap/wrapper/add_peer.go
Pavel Karpy c25f5a86ae [#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>
2021-11-19 09:58:03 +03:00

43 lines
927 B
Go

package wrapper
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(prm AddPeerPrm) error {
if prm.nodeInfo == nil {
return errors.New("nil node info")
}
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)
}
return nil
}