mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-29 06:55:33 +00:00
27 lines
477 B
Go
27 lines
477 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
"github.com/multiformats/go-multiaddr"
|
|
)
|
|
|
|
type DialError struct {
|
|
Err error
|
|
PeerID peer.ID
|
|
}
|
|
|
|
// GetPeerID is used to extract the peerID from a multiaddress
|
|
func GetPeerID(m multiaddr.Multiaddr) (peer.ID, error) {
|
|
peerIDStr, err := m.ValueForProtocol(multiaddr.P_P2P)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
peerID, err := peer.Decode(peerIDStr)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return peerID, nil
|
|
}
|