c25f5a86ae
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>
43 lines
927 B
Go
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
|
|
}
|