2020-07-24 13:54:03 +00:00
|
|
|
package wrapper
|
|
|
|
|
2020-09-08 13:14:22 +00:00
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2021-11-10 10:44:19 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2020-09-08 13:14:22 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
|
|
|
)
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2021-11-10 10:44:19 +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.
|
2021-11-10 10:44:19 +00:00
|
|
|
func (w *Wrapper) AddPeer(prm AddPeerPrm) error {
|
|
|
|
if prm.nodeInfo == nil {
|
2020-09-08 13:14:22 +00:00
|
|
|
return errors.New("nil node info")
|
|
|
|
}
|
|
|
|
|
2021-11-10 10:44:19 +00:00
|
|
|
rawNodeInfo, err := prm.nodeInfo.Marshal()
|
2020-09-08 13:14:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
args := netmap.AddPeerArgs{}
|
|
|
|
args.SetInfo(rawNodeInfo)
|
2021-11-10 10:44:19 +00:00
|
|
|
args.InvokePrmOptional = prm.InvokePrmOptional
|
2020-09-08 13:14:22 +00:00
|
|
|
|
2021-05-18 08:12:51 +00:00
|
|
|
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
|
|
|
}
|