From aa98592ac44ea8865715ac903d53bc8b5289184d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 8 Sep 2020 16:14:22 +0300 Subject: [PATCH] [#15] Fix wrapper for add peer contract method Signed-off-by: Alex Vanin --- cmd/neofs-node/morph.go | 11 +++++---- pkg/morph/client/netmap/wrapper/add_peer.go | 25 +++++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index c899bbcce..0c5063c0a 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -5,6 +5,7 @@ import ( crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" + "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" ) func initMorphComponents(c *cfg) { @@ -25,17 +26,15 @@ func bootstrapNode(c *cfg) { cli, err := netmap.New(staticClient) fatalOnErr(err) + cliWrapper, err := wrapper.New(cli) + fatalOnErr(err) + peerInfo := new(netmap.NodeInfo) peerInfo.SetAddress(c.cfgNodeInfo.address) peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey)) // todo: add attributes as opts - rawInfo, err := peerInfo.StableMarshal(nil) - fatalOnErr(err) - - args := new(netmap.AddPeerArgs) - args.SetInfo(rawInfo) - err = cli.AddPeer(*args) + err = cliWrapper.AddPeer(peerInfo) fatalOnErr(err) } } diff --git a/pkg/morph/client/netmap/wrapper/add_peer.go b/pkg/morph/client/netmap/wrapper/add_peer.go index 4644c9aa6..14e7d7272 100644 --- a/pkg/morph/client/netmap/wrapper/add_peer.go +++ b/pkg/morph/client/netmap/wrapper/add_peer.go @@ -1,10 +1,27 @@ package wrapper -// NodeInfo groups information about NeoFS storage node. -type NodeInfo struct{} +import ( + "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" + "github.com/pkg/errors" +) // AddPeer registers peer in NeoFS network through // Netmap contract call. -func (w *Wrapper) AddPeer(nodeInfo NodeInfo) error { - panic("implement me") +func (w *Wrapper) AddPeer(nodeInfo *netmap.NodeInfo) error { + if nodeInfo == nil { + return errors.New("nil node info") + } + + rawNodeInfo, err := nodeInfo.StableMarshal(nil) + if err != nil { + return err + } + + args := netmap.AddPeerArgs{} + args.SetInfo(rawNodeInfo) + + return errors.Wrap( + w.client.AddPeer(args), + "could not invoke smart contract", + ) }