Skip to content

Commit

Permalink
core/peer: remove deprecated Encode function (#2566)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Sep 14, 2023
1 parent d08bcd9 commit fd2a1ed
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/peer/addrinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) {

// AddrInfoToP2pAddrs converts an AddrInfo to a list of Multiaddrs.
func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error) {
p2ppart, err := ma.NewComponent("p2p", Encode(pi.ID))
p2ppart, err := ma.NewComponent("p2p", pi.ID.String())
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/peer/addrinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
if err != nil {
panic(err)
}
maddrPeer = ma.StringCast("/p2p/" + Encode(testID))
maddrPeer = ma.StringCast("/p2p/" + testID.String())
maddrTpt = ma.StringCast("/ip4/127.0.0.1/tcp/1234")
maddrFull = maddrTpt.Encapsulate(maddrPeer)
}
Expand Down
10 changes: 0 additions & 10 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,6 @@ func Decode(s string) (ID, error) {
return FromCid(c)
}

// Encode encodes a peer ID as a string.
//
// At the moment, it base58 encodes the peer ID but, in the future, it will
// switch to encoding it as a CID by default.
//
// Deprecated: use id.String instead.
func Encode(id ID) string {
return id.String()
}

// FromCid converts a CID to a peer ID, if possible.
func FromCid(c cid.Cid) (ID, error) {
code := mc.Code(c.Type())
Expand Down
4 changes: 2 additions & 2 deletions core/peer/peer_serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (id ID) Size() int {
}

func (id ID) MarshalJSON() ([]byte, error) {
return json.Marshal(Encode(id))
return json.Marshal(id.String())
}

func (id *ID) UnmarshalJSON(data []byte) (err error) {
Expand All @@ -59,7 +59,7 @@ func (id *ID) UnmarshalJSON(data []byte) (err error) {

// MarshalText returns the text encoding of the ID.
func (id ID) MarshalText() ([]byte, error) {
return []byte(Encode(id)), nil
return []byte(id.String()), nil
}

// UnmarshalText restores the ID from its text encoding.
Expand Down

0 comments on commit fd2a1ed

Please sign in to comment.