Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use string instead of struct backing #47

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cid-fmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func usage() {

const fmtRef = `
%% literal %
%b multibase name
%b multibase name
%B multibase code
%v version string
%V version number
Expand All @@ -46,7 +46,7 @@ func main() {
usage()
}
newBase := mb.Encoding(-1)
var verConv func(cid *c.Cid) (*c.Cid, error)
var verConv func(cid c.Cid) (c.Cid, error)
args := os.Args[1:]
outer:
for {
Expand Down Expand Up @@ -132,23 +132,23 @@ func errorMsg(fmtStr string, a ...interface{}) {
exitCode = 1
}

func decode(v string) (mb.Encoding, *c.Cid, error) {
func decode(v string) (mb.Encoding, c.Cid, error) {
if len(v) < 2 {
return 0, nil, c.ErrCidTooShort
return 0, c.EmptyCid, c.ErrCidTooShort
}

if len(v) == 46 && v[:2] == "Qm" {
hash, err := mh.FromB58String(v)
if err != nil {
return 0, nil, err
return 0, c.EmptyCid, err
}

return mb.Base58BTC, c.NewCidV0(hash), nil
}

base, data, err := mb.Decode(v)
if err != nil {
return 0, nil, err
return 0, c.EmptyCid, err
}

cid, err := c.Cast(data)
Expand All @@ -158,7 +158,7 @@ func decode(v string) (mb.Encoding, *c.Cid, error) {

const ERR_STR = "!ERROR!"

func fmtCid(fmtStr string, base mb.Encoding, cid *c.Cid) (string, error) {
func fmtCid(fmtStr string, base mb.Encoding, cid c.Cid) (string, error) {
p := cid.Prefix()
out := new(bytes.Buffer)
var err error
Expand Down Expand Up @@ -265,13 +265,13 @@ func encode(base mb.Encoding, data []byte, strip bool) string {
return str
}

func toCidV0(cid *c.Cid) (*c.Cid, error) {
func toCidV0(cid c.Cid) (c.Cid, error) {
if cid.Type() != c.DagProtobuf {
return nil, fmt.Errorf("can't convert non-protobuf nodes to cidv0")
return c.EmptyCid, fmt.Errorf("can't convert non-protobuf nodes to cidv0")
}
return c.NewCidV0(cid.Hash()), nil
}

func toCidV1(cid *c.Cid) (*c.Cid, error) {
func toCidV1(cid c.Cid) (c.Cid, error) {
return c.NewCidV1(cid.Type(), cid.Hash()), nil
}
Loading