Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

add a helper function to go directly from a string to an AddrInfo #184

Merged
merged 2 commits into from Feb 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions peer/addrinfo.go
Expand Up @@ -3,6 +3,7 @@ package peer
import (
"fmt"

"github.com/multiformats/go-multiaddr"
ma "github.com/multiformats/go-multiaddr"
)

Expand Down Expand Up @@ -61,6 +62,16 @@ func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID) {
return transport, id
}

// AddrInfoFromString builds an AddrInfo from the string representation of a Multiaddr
func AddrInfoFromString(s string) (*AddrInfo, error) {
whyrusleeping marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure you don't want AddrInfosFromStrings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk, this seems good enough for now? im happy with whatever

a, err := multiaddr.NewMultiaddr(s)
if err != nil {
return nil, err
}

return AddrInfoFromP2pAddr(a)
}

// AddrInfoFromP2pAddr converts a Multiaddr to an AddrInfo.
func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) {
transport, id := SplitAddr(m)
Expand Down