Browse Source

core/peer: remove deprecated Encode function (#2566)

pull/2571/head
Marten Seemann 1 year ago
committed by GitHub
parent
commit
fd2a1ede9c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      core/peer/addrinfo.go
  2. 2
      core/peer/addrinfo_test.go
  3. 10
      core/peer/peer.go
  4. 4
      core/peer/peer_serde.go

2
core/peer/addrinfo.go

@ -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
}

2
core/peer/addrinfo_test.go

@ -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)
}

10
core/peer/peer.go

@ -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())

4
core/peer/peer_serde.go

@ -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) {
@ -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.

Loading…
Cancel
Save