Commit 0c9f4a7c authored by Hector Sanjuan's avatar Hector Sanjuan

Replace DsKeyToCidV1Raw() with DsKeyToCidV1()

Allow passing in whatever codec type the user wants
parent 48143f3d
...@@ -40,11 +40,12 @@ func DsKeyToMultihash(dsKey datastore.Key) (mh.Multihash, error) { ...@@ -40,11 +40,12 @@ func DsKeyToMultihash(dsKey datastore.Key) (mh.Multihash, error) {
} }
// DsKeyToCidV1Raw converts the given Key (which should be a raw multihash // DsKeyToCidV1Raw converts the given Key (which should be a raw multihash
// key) to a Cid V1 of raw type. // key) to a Cid V1 of the given type (see
func DsKeyToCidV1Raw(dsKey datastore.Key) (cid.Cid, error) { // https://godoc.org/github.com/ipfs/go-cid#pkg-constants).
func DsKeyToCidV1(dsKey datastore.Key, codecType uint64) (cid.Cid, error) {
hash, err := DsKeyToMultihash(dsKey) hash, err := DsKeyToMultihash(dsKey)
if err != nil { if err != nil {
return cid.Cid{}, err return cid.Cid{}, err
} }
return cid.NewCidV1(cid.Raw, hash), nil return cid.NewCidV1(codecType, hash), nil
} }
...@@ -17,7 +17,7 @@ func TestKey(t *testing.T) { ...@@ -17,7 +17,7 @@ func TestKey(t *testing.T) {
t.Fatal("should have parsed the same multihash") t.Fatal("should have parsed the same multihash")
} }
c2, err := DsKeyToCidV1Raw(dsKey) c2, err := DsKeyToCidV1(dsKey, cid.Raw)
if err != nil || c.Equals(c2) || c2.Type() != cid.Raw || c2.Version() != 1 { if err != nil || c.Equals(c2) || c2.Type() != cid.Raw || c2.Version() != 1 {
t.Fatal("should have been converted to CIDv1-raw") t.Fatal("should have been converted to CIDv1-raw")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment