refactor: rename CID decode to CIDFromString
This commit is contained in:
parent
58cc6153bd
commit
ed2a47fca3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
/* {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue