From f330c63cb4bca553b8e8142f0dbcf5c9c2bc99f6 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Fri, 7 Sep 2018 14:53:33 -0400 Subject: [PATCH] gx update and fix code to use new Cid type --- package.json | 14 +++++++------- path.go | 8 ++++---- resolver/resolver.go | 18 +++++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 1c00738..1e5ab35 100644 --- a/package.json +++ b/package.json @@ -9,21 +9,21 @@ "gxDependencies": [ { "author": "why", - "hash": "QmNr4E8z9bGTztvHJktp7uQaMdx9p3r9Asrq6eYk7iCh4a", + "hash": "Qmc68D3Dta37BCB9yMbsWRCUdytjHiv8kRsyStSkthQzo3", "name": "go-merkledag", - "version": "1.0.14" + "version": "1.1.0" }, { "author": "whyrusleeping", - "hash": "QmX5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC", + "hash": "QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL", "name": "go-ipld-format", - "version": "0.5.8" + "version": "0.6.0" }, { "author": "whyrusleeping", - "hash": "QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb", + "hash": "QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7", "name": "go-cid", - "version": "0.8.0" + "version": "0.9.0" }, { "hash": "QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr", @@ -36,6 +36,6 @@ "license": "", "name": "go-path", "releaseCmd": "git commit -a -m \"gx publish $VERSION\"", - "version": "1.0.14" + "version": "1.0.13" } diff --git a/path.go b/path.go index 18c187b..7754ef1 100644 --- a/path.go +++ b/path.go @@ -36,7 +36,7 @@ func FromString(s string) Path { } // FromCid safely converts a cid.Cid type to a Path type. -func FromCid(c *cid.Cid) Path { +func FromCid(c cid.Cid) Path { return Path("/ipfs/" + c.String()) } @@ -160,7 +160,7 @@ func SplitList(pth string) []string { // SplitAbsPath clean up and split fpath. It extracts the first component (which // must be a Multihash) and return it separately. -func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) { +func SplitAbsPath(fpath Path) (cid.Cid, []string, error) { parts := fpath.Segments() if parts[0] == "ipfs" || parts[0] == "ipld" { parts = parts[1:] @@ -168,13 +168,13 @@ func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) { // if nothing, bail. if len(parts) == 0 { - return nil, nil, ErrNoComponents + return cid.Cid{}, nil, ErrNoComponents } c, err := cid.Decode(parts[0]) // first element in the path is a cid if err != nil { - return nil, nil, err + return cid.Cid{}, nil, err } return c, parts[1:], nil diff --git a/resolver/resolver.go b/resolver/resolver.go index f5e3862..352004f 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -25,7 +25,7 @@ var ErrNoComponents = errors.New( // ErrNoLink is returned when a link is not found in a path type ErrNoLink struct { Name string - Node *cid.Cid + Node cid.Cid } // Error implements the Error interface for ErrNoLink with a useful @@ -57,10 +57,10 @@ func NewBasicResolver(ds ipld.DAGService) *Resolver { // ResolveToLastNode walks the given path and returns the cid of the last node // referenced by the path -func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid.Cid, []string, error) { +func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid.Cid, []string, error) { c, p, err := path.SplitAbsPath(fpath) if err != nil { - return nil, nil, err + return cid.Cid{}, nil, err } if len(p) == 0 { @@ -69,7 +69,7 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid nd, err := r.DAG.Get(ctx, c) if err != nil { - return nil, nil, err + return cid.Cid{}, nil, err } for len(p) > 0 { @@ -83,12 +83,12 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid } if err != nil { - return nil, nil, err + return cid.Cid{}, nil, err } next, err := lnk.GetNode(ctx, r.DAG) if err != nil { - return nil, nil, err + return cid.Cid{}, nil, err } nd = next p = rest @@ -101,15 +101,15 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid // Confirm the path exists within the object val, rest, err := nd.Resolve(p) if err != nil { - return nil, nil, err + return cid.Cid{}, nil, err } if len(rest) > 0 { - return nil, nil, errors.New("path failed to resolve fully") + return cid.Cid{}, nil, errors.New("path failed to resolve fully") } switch val.(type) { case *ipld.Link: - return nil, nil, errors.New("inconsistent ResolveOnce / nd.Resolve") + return cid.Cid{}, nil, errors.New("inconsistent ResolveOnce / nd.Resolve") default: return nd.Cid(), p, nil }