From 3d3d30560ad28ba623af7530faa90f7fd347ac13 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 28 Sep 2021 08:06:54 +0300 Subject: [PATCH] [#645] core/client: Implement helper functions to fill NodeInfo Signed-off-by: Leonard Lyubich --- pkg/core/client/util.go | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pkg/core/client/util.go diff --git a/pkg/core/client/util.go b/pkg/core/client/util.go new file mode 100644 index 000000000..c19b0c36c --- /dev/null +++ b/pkg/core/client/util.go @@ -0,0 +1,42 @@ +package client + +import ( + "fmt" + + "github.com/nspcc-dev/neofs-node/pkg/network" +) + +func nodeInfoFromKeyAddr(dst *NodeInfo, k []byte, a network.AddressGroup) { + dst.SetPublicKey(k) + dst.SetAddressGroup(a) +} + +// NodeInfoFromRawNetmapElement fills NodeInfo structure from the interface of raw netmap member's descriptor. +// +// Args must not be nil. +func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface { + PublicKey() []byte + IterateAddresses(func(string) bool) + NumberOfAddresses() int +}) error { + var a network.AddressGroup + + err := a.FromIterator(info) + if err != nil { + return fmt.Errorf("parse network address: %w", err) + } + + nodeInfoFromKeyAddr(dst, info.PublicKey(), a) + + return nil +} + +// NodeInfoFromNetmapElement fills NodeInfo structure from the interface of parsed netmap member's descriptor. +// +// Args must not be nil. +func NodeInfoFromNetmapElement(dst *NodeInfo, info interface { + PublicKey() []byte + Addresses() network.AddressGroup +}) { + nodeInfoFromKeyAddr(dst, info.PublicKey(), info.Addresses()) +}