[#15] Fix wrapper for add peer contract method
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
ee9551992c
commit
aa98592ac4
2 changed files with 26 additions and 10 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
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"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
"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) {
|
func initMorphComponents(c *cfg) {
|
||||||
|
@ -25,17 +26,15 @@ func bootstrapNode(c *cfg) {
|
||||||
cli, err := netmap.New(staticClient)
|
cli, err := netmap.New(staticClient)
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
|
cliWrapper, err := wrapper.New(cli)
|
||||||
|
fatalOnErr(err)
|
||||||
|
|
||||||
peerInfo := new(netmap.NodeInfo)
|
peerInfo := new(netmap.NodeInfo)
|
||||||
peerInfo.SetAddress(c.cfgNodeInfo.address)
|
peerInfo.SetAddress(c.cfgNodeInfo.address)
|
||||||
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
|
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
|
||||||
// todo: add attributes as opts
|
// todo: add attributes as opts
|
||||||
|
|
||||||
rawInfo, err := peerInfo.StableMarshal(nil)
|
err = cliWrapper.AddPeer(peerInfo)
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
args := new(netmap.AddPeerArgs)
|
|
||||||
args.SetInfo(rawInfo)
|
|
||||||
err = cli.AddPeer(*args)
|
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,27 @@
|
||||||
package wrapper
|
package wrapper
|
||||||
|
|
||||||
// NodeInfo groups information about NeoFS storage node.
|
import (
|
||||||
type NodeInfo struct{}
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
// AddPeer registers peer in NeoFS network through
|
// AddPeer registers peer in NeoFS network through
|
||||||
// Netmap contract call.
|
// Netmap contract call.
|
||||||
func (w *Wrapper) AddPeer(nodeInfo NodeInfo) error {
|
func (w *Wrapper) AddPeer(nodeInfo *netmap.NodeInfo) error {
|
||||||
panic("implement me")
|
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",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue