frostfs-node/pkg/morph/client/netmap/wrapper/add_peer.go

44 lines
927 B
Go
Raw Normal View History

2020-07-24 13:54:03 +00:00
package wrapper
import (
"errors"
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
)
2020-07-24 13:54:03 +00:00
// 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
}
2020-07-24 13:54:03 +00:00
// 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
2020-07-24 13:54:03 +00:00
}