Commit 2bc018ba authored by Kevin Atkinson's avatar Kevin Atkinson

Replace DecodeV2 with ExtractEncoding

parent eb97b6f3
...@@ -69,15 +69,16 @@ outer: ...@@ -69,15 +69,16 @@ outer:
} }
} }
for _, cidStr := range args[1:] { for _, cidStr := range args[1:] {
base, cid, err := c.DecodeV2(cidStr) cid, err := c.Decode(cidStr)
if err != nil { if err != nil {
fmt.Fprintf(os.Stdout, "!INVALID_CID!\n") fmt.Fprintf(os.Stdout, "!INVALID_CID!\n")
errorMsg("%s: %v", cidStr, err) errorMsg("%s: %v", cidStr, err)
// Don't abort on a bad cid // Don't abort on a bad cid
continue continue
} }
if newBase != -1 { base := newBase
base = newBase if newBase == -1 {
base, _ = c.ExtractEncoding(cidStr)
} }
if verConv != nil { if verConv != nil {
cid, err = verConv(cid) cid, err = verConv(cid)
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
func TestCidConv(t *testing.T) { func TestCidConv(t *testing.T) {
cidv0 := "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" cidv0 := "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"
cidv1 := "zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi" cidv1 := "zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi"
_, cid, err := c.DecodeV2(cidv0) cid, err := c.Decode(cidv0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -34,7 +34,7 @@ func TestCidConv(t *testing.T) { ...@@ -34,7 +34,7 @@ func TestCidConv(t *testing.T) {
func TestBadCidConv(t *testing.T) { func TestBadCidConv(t *testing.T) {
// this cid is a raw leaf and should not be able to convert to cidv0 // this cid is a raw leaf and should not be able to convert to cidv0
cidv1 := "zb2rhhzX7uSKrtQ2ZZXFAabKiKFYZrJqKY2KE1cJ8yre2GSWZ" cidv1 := "zb2rhhzX7uSKrtQ2ZZXFAabKiKFYZrJqKY2KE1cJ8yre2GSWZ"
_, cid, err := c.DecodeV2(cidv1) cid, err := c.Decode(cidv1)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -55,13 +55,14 @@ func TestFmt(t *testing.T) { ...@@ -55,13 +55,14 @@ func TestFmt(t *testing.T) {
} }
func testFmt(t *testing.T, cidStr string, newBase mb.Encoding, fmtStr string, result string) { func testFmt(t *testing.T, cidStr string, newBase mb.Encoding, fmtStr string, result string) {
base, cid, err := DecodeV2(cidStr) cid, err := Decode(cidStr)
if newBase != -1 {
base = newBase
}
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
base := newBase
if newBase == -1 {
base, _ = ExtractEncoding(cidStr)
}
str, err := Format(fmtStr, base, cid) str, err := Format(fmtStr, base, cid)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -70,4 +71,3 @@ func testFmt(t *testing.T, cidStr string, newBase mb.Encoding, fmtStr string, re ...@@ -70,4 +71,3 @@ func testFmt(t *testing.T, cidStr string, newBase mb.Encoding, fmtStr string, re
t.Error(fmt.Sprintf("expected: %s; but got: %s", result, str)) t.Error(fmt.Sprintf("expected: %s; but got: %s", result, str))
} }
} }
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