fix: use multiaddres instead of strings

This commit is contained in:
Richard Ramos 2021-09-27 14:16:06 -04:00
parent cfcfb52a58
commit 9416077adf
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
1 changed files with 7 additions and 5 deletions

View File

@ -6,12 +6,14 @@ import (
"github.com/ethereum/go-ethereum/p2p/dnsdisc"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"
)
// RetrieveNodes returns a list of multiaddress given a url to a DNS discoverable
// ENR tree
func RetrieveNodes(url string) ([]string, error) {
var multiAddrs []string
func RetrieveNodes(url string) ([]ma.Multiaddr, error) {
var multiAddrs []ma.Multiaddr
client := dnsdisc.NewClient(dnsdisc.Config{})
@ -33,11 +35,11 @@ func RetrieveNodes(url string) ([]string, error) {
return multiAddrs, nil
}
func enodeToMultiAddr(node *enode.Node) (string, error) {
func enodeToMultiAddr(node *enode.Node) (ma.Multiaddr, error) {
peerID, err := peer.IDFromPublicKey(&ECDSAPublicKey{node.Pubkey()})
if err != nil {
return "", err
return nil, err
}
return fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", node.IP(), node.TCP(), peerID), nil
return ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", node.IP(), node.TCP(), peerID))
}