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

Commit

Permalink
add a helper function to go directly from a string to an AddrInfo (#184)
Browse files Browse the repository at this point in the history
* add a helper function to go directly from a string to an AddrInfo

* Update peer/addrinfo.go

Co-authored-by: Will <[email protected]>

Co-authored-by: Will <[email protected]>
  • Loading branch information
whyrusleeping and willscott authored Feb 22, 2021
1 parent ca38e17 commit 11f3c3a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions peer/addrinfo.go
Original file line number Diff line number Diff line change
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) {
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

0 comments on commit 11f3c3a

Please sign in to comment.