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

deprecate peer.Encode in favor of peer.ID.String #275

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (id ID) Loggable() map[string]interface{} {
}

func (id ID) String() string {
return Encode(id)
return b58.Encode([]byte(id))
}

// ShortString prints out the peer ID.
Expand Down Expand Up @@ -158,8 +158,10 @@ func Decode(s string) (ID, error) {
//
// 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 b58.Encode([]byte(id))
return id.String()
}

// FromCid converts a CID to a peer ID, if possible.
Expand Down
2 changes: 1 addition & 1 deletion peer/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestIDEncoding(t *testing.T) {
t.Fatal("failed to round trip through CID string")
}

if ks.hpkp != Encode(p1) {
if ks.hpkp != p1.String() {
t.Fatal("should always encode peer IDs as base58 by default")
}
}
Expand Down
2 changes: 1 addition & 1 deletion routing/query_serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func (qe *QueryEvent) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"ID": peer.Encode(qe.ID),
"ID": qe.ID.String(),
"Type": int(qe.Type),
"Responses": qe.Responses,
"Extra": qe.Extra,
Expand Down