2022-10-19 23:23:11 +03:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2022-12-18 21:15:13 +02:00
|
|
|
peer "github.com/libp2p/go-libp2p/core/peer"
|
2022-10-19 23:23:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// PeersToStrings Encodes a list of peers.
|
|
|
|
func PeersToStrings(peers []peer.ID) []string {
|
|
|
|
strs := make([]string, len(peers))
|
|
|
|
for i, p := range peers {
|
|
|
|
if p != "" {
|
2022-12-18 21:15:13 +02:00
|
|
|
strs[i] = p.String()
|
2022-10-19 23:23:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return strs
|
|
|
|
}
|
|
|
|
|
|
|
|
// StringsToPeers decodes peer.IDs from strings.
|
|
|
|
func StringsToPeers(strs []string) []peer.ID {
|
|
|
|
peers := []peer.ID{}
|
|
|
|
for _, p := range strs {
|
|
|
|
pid, err := peer.Decode(p)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
peers = append(peers, pid)
|
|
|
|
}
|
|
|
|
return peers
|
|
|
|
}
|