This repository was archived by the owner on Sep 6, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ require (
14
14
github.com/minio/sha256-simd v0.1.1
15
15
github.com/mr-tron/base58 v1.2.0
16
16
github.com/multiformats/go-multiaddr v0.4.1
17
+ github.com/multiformats/go-multicodec v0.4.1
17
18
github.com/multiformats/go-multihash v0.0.14
18
19
github.com/multiformats/go-varint v0.0.6
19
20
github.com/stretchr/testify v1.7.0
Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ github.com/multiformats/go-multiaddr v0.4.1 h1:Pq37uLx3hsyNlTDir7FZyU8+cFCTqd5y1
50
50
github.com/multiformats/go-multiaddr v0.4.1 /go.mod h1:3afI9HfVW8csiF8UZqtpYRiDyew8pRX7qLIGHu9FLuM =
51
51
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk =
52
52
github.com/multiformats/go-multibase v0.0.3 /go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc =
53
+ github.com/multiformats/go-multicodec v0.4.1 h1:BSJbf+zpghcZMZrwTYBGwy0CPcVZGWiC72Cp8bBd4R4 =
54
+ github.com/multiformats/go-multicodec v0.4.1 /go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ =
53
55
github.com/multiformats/go-multihash v0.0.13 /go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc =
54
56
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I =
55
57
github.com/multiformats/go-multihash v0.0.14 /go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc =
Original file line number Diff line number Diff line change 9
9
"github.com/ipfs/go-cid"
10
10
ic "github.com/libp2p/go-libp2p-core/crypto"
11
11
b58 "github.com/mr-tron/base58/base58"
12
+ mc "github.com/multiformats/go-multicodec"
12
13
mh "github.com/multiformats/go-multihash"
13
14
)
14
15
@@ -162,13 +163,9 @@ func Encode(id ID) string {
162
163
163
164
// FromCid converts a CID to a peer ID, if possible.
164
165
func FromCid (c cid.Cid ) (ID , error ) {
165
- ty := c .Type ()
166
- if ty != cid .Libp2pKey {
167
- s := cid .CodecToStr [ty ]
168
- if s == "" {
169
- s = fmt .Sprintf ("[unknown multicodec %d]" , ty )
170
- }
171
- return "" , fmt .Errorf ("can't convert CID of type %s to a peer ID" , s )
166
+ code := mc .Code (c .Type ())
167
+ if code != mc .Libp2pKey {
168
+ return "" , fmt .Errorf ("can't convert CID of type %s to a peer ID" , code .String ())
172
169
}
173
170
return ID (c .Hash ()), nil
174
171
}
You can’t perform that action at this time.
0 commit comments