From ed2a47fca3168a4e20f85d56a570f57ec14ca2d5 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 9 Jan 2024 08:23:35 -0500 Subject: [PATCH] refactor: rename CID decode to CIDFromString --- encoding/cid.go | 2 +- encoding/cid_test.go | 2 +- encoding/multibase_test.go | 8 ++++---- metadata/extra.go | 2 +- protocol/signed/accounce_peers.go | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/encoding/cid.go b/encoding/cid.go index 6f665ad..4320fdb 100644 --- a/encoding/cid.go +++ b/encoding/cid.go @@ -64,7 +64,7 @@ func (cid *CID) ToBytes() []byte { return utils.ConcatBytes(cid.getPrefixBytes(), cid.Hash.fullBytes) } -func Decode(cid string) (*CID, error) { +func CIDFromString(cid string) (*CID, error) { decodedBytes, err := MultibaseDecodeString(cid) if err != nil { return nil, err diff --git a/encoding/cid_test.go b/encoding/cid_test.go index 396940b..7f94b43 100644 --- a/encoding/cid_test.go +++ b/encoding/cid_test.go @@ -342,7 +342,7 @@ func TestDecode(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := Decode(tt.args.cid) + got, err := CIDFromString(tt.args.cid) if (err != nil) != tt.wantErr { t.Errorf("DecodeCID() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/encoding/multibase_test.go b/encoding/multibase_test.go index bacfebd..f65e186 100644 --- a/encoding/multibase_test.go +++ b/encoding/multibase_test.go @@ -36,25 +36,25 @@ func TestDecodeString(t *testing.T) { { name: "TestValidMultibase_z", args: args{data: testdata.MediaBase58CID}, - wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.Decode("zabc") + wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.CIDFromString("zabc") wantErr: false, }, { name: "TestValidMultibase_f", args: args{data: testdata.MediaBase16CID}, - wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.Decode("fxyz") + wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.CIDFromString("fxyz") wantErr: false, }, { name: "TestValidMultibase_u", args: args{data: testdata.MediaBase64CID}, - wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.Decode("uhello") + wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.CIDFromString("uhello") wantErr: false, }, { name: "TestValidMultibase_b", args: args{data: testdata.MediaBase32CID}, - wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.Decode("bworld") + wantBytes: testdata.MediaCIDBytes, // Adjust this based on the expected output of multibase.CIDFromString("bworld") wantErr: false, }, /* { diff --git a/metadata/extra.go b/metadata/extra.go index 01ce340..c7f7953 100644 --- a/metadata/extra.go +++ b/metadata/extra.go @@ -105,7 +105,7 @@ func (em *ExtraMetadata) decodeItem(pair keyValue) error { if metadataKey == int(types.MetadataExtensionUpdateCID) { // Convert string to CID bytes for MetadataExtensionUpdateCID - cid, err := encoding.Decode(pair.Value.(string)) + cid, err := encoding.CIDFromString(pair.Value.(string)) if err != nil { return err } diff --git a/protocol/signed/accounce_peers.go b/protocol/signed/accounce_peers.go index dfa995b..1b18a08 100644 --- a/protocol/signed/accounce_peers.go +++ b/protocol/signed/accounce_peers.go @@ -38,7 +38,7 @@ func NewAnnouncePeers() *AnnouncePeers { } func (a *AnnouncePeers) DecodeMessage(dec *msgpack.Decoder) error { - // Decode the number of peers. + // CIDFromString the number of peers. numPeers, err := dec.DecodeInt() if err != nil { return err @@ -49,7 +49,7 @@ func (a *AnnouncePeers) DecodeMessage(dec *msgpack.Decoder) error { // Loop through each peer. for i := 0; i < numPeers; i++ { - // Decode peer ID. + // CIDFromString peer ID. peerIdBytes, err := dec.DecodeBytes() if err != nil { return err @@ -62,13 +62,13 @@ func (a *AnnouncePeers) DecodeMessage(dec *msgpack.Decoder) error { return err } - // Decode the number of connection URIs for this peer. + // CIDFromString the number of connection URIs for this peer. numUris, err := dec.DecodeInt() if err != nil { return err } - // Decode each connection URI for this peer. + // CIDFromString each connection URI for this peer. for j := 0; j < numUris; j++ { uriStr, err := dec.DecodeString() if err != nil {