Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/go-ipld-cbor
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cb4b1f0612683fd1fa5afaa9dea7ee8b4bf614d0
Choose a base ref
..
head repository: ipfs/go-ipld-cbor
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a1a7802fa5dd65695021578d7a7bb66352c07cd8
Choose a head ref
Showing with 31 additions and 39 deletions.
  1. +1 −1 .gx/lastpubver
  2. +6 −13 node.go
  3. +10 −17 node_test.go
  4. +14 −8 package.json
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.2: QmcWjuCqrfAdtwChsnpHe9L1gvdYToCy8xLDY2KCdiTQiZ
1.3.0: QmPrv66vmh2P7vLJMpYx6DWLTNKvVB4Jdkyxs6V3QvWKvf
19 changes: 6 additions & 13 deletions node.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ type Node struct {
tree []string
links []*node.Link
raw []byte
cid *cid.Cid
cid cid.Cid
}

// Compile time check to make sure Node implements the node.Node interface
@@ -176,23 +176,16 @@ func (n *Node) Resolve(path []string) (interface{}, []string, error) {
}

cur = curv[n]
case *cid.Cid:
return &node.Link{Cid: curv}, path[i:], nil
case cid.Cid:
return &node.Link{Cid: &curv}, path[i:], nil
return &node.Link{Cid: curv}, path[i:], nil
default:
return nil, nil, ErrNoLinks
}
}

lnkp, ok := cur.(*cid.Cid)
if ok {
return &node.Link{Cid: lnkp}, nil, nil
}

lnk, ok := cur.(cid.Cid)
if ok {
return &node.Link{Cid: &lnk}, nil, nil
return &node.Link{Cid: lnk}, nil, nil
}

jsonish, err := convertToJSONIsh(cur)
@@ -321,7 +314,7 @@ func compLinks(obj interface{}) ([]*node.Link, error) {
var out []*node.Link
err := traverse(obj, "", func(name string, val interface{}) error {
if lnk, ok := val.(cid.Cid); ok {
out = append(out, &node.Link{Cid: &lnk})
out = append(out, &node.Link{Cid: lnk})
}
return nil
})
@@ -377,7 +370,7 @@ func (n *Node) RawData() []byte {
}

// Cid returns the canonical Cid of the NOde.
func (n *Node) Cid() *cid.Cid {
func (n *Node) Cid() cid.Cid {
return n.cid
}

@@ -555,7 +548,7 @@ func castBytesToCid(x []byte) (cid.Cid, error) {
return cid.Cid{}, ErrInvalidLink
}

return *c, nil
return c, nil
}

func castCidToBytes(link cid.Cid) ([]byte, error) {
27 changes: 10 additions & 17 deletions node_test.go
Original file line number Diff line number Diff line change
@@ -14,18 +14,11 @@ import (

blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
u "github.com/ipfs/go-ipfs-util"
mh "github.com/multiformats/go-multihash"
)

func Hash(data []byte) mh.Multihash {
h, err := mh.Sum(data, mh.SHA2_256, -1)
if err != nil {
panic("multihash failed to hash using SHA2_256.")
}
return h
}

func assertCid(c *cid.Cid, exp string) error {
func assertCid(c cid.Cid, exp string) error {
if c.String() != exp {
return fmt.Errorf("expected cid of %s, got %s", exp, c)
}
@@ -85,7 +78,7 @@ func TestDecodeIntoNonObject(t *testing.T) {
}

func TestBasicMarshal(t *testing.T) {
c := cid.NewCidV0(Hash([]byte("something")))
c := cid.NewCidV0(u.Hash([]byte("something")))

obj := map[string]interface{}{
"name": "foo",
@@ -128,9 +121,9 @@ func TestBasicMarshal(t *testing.T) {
}

func TestMarshalRoundtrip(t *testing.T) {
c1 := cid.NewCidV0(Hash([]byte("something1")))
c2 := cid.NewCidV0(Hash([]byte("something2")))
c3 := cid.NewCidV0(Hash([]byte("something3")))
c1 := cid.NewCidV0(u.Hash([]byte("something1")))
c2 := cid.NewCidV0(u.Hash([]byte("something2")))
c3 := cid.NewCidV0(u.Hash([]byte("something3")))

obj := map[string]interface{}{
"foo": "bar",
@@ -211,10 +204,10 @@ func assertStringsEqual(t *testing.T, a, b []string) {
}

func TestTree(t *testing.T) {
c1 := cid.NewCidV0(Hash([]byte("something1")))
c2 := cid.NewCidV0(Hash([]byte("something2")))
c3 := cid.NewCidV0(Hash([]byte("something3")))
c4 := cid.NewCidV0(Hash([]byte("something4")))
c1 := cid.NewCidV0(u.Hash([]byte("something1")))
c2 := cid.NewCidV0(u.Hash([]byte("something2")))
c3 := cid.NewCidV0(u.Hash([]byte("something3")))
c4 := cid.NewCidV0(u.Hash([]byte("something4")))

obj := map[string]interface{}{
"foo": c1,
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -9,15 +9,21 @@
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb",
"hash": "QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL",
"name": "go-ipld-format",
"version": "0.5.4"
"version": "0.6.0"
},
{
"author": "whyrusleeping",
"hash": "QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB",
"hash": "QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7",
"name": "go-cid",
"version": "0.7.21"
"version": "0.9.0"
},
{
"author": "whyrusleeping",
"hash": "QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A",
"name": "go-ipfs-util",
"version": "1.2.8"
},
{
"author": "whyrusleeping",
@@ -27,15 +33,15 @@
},
{
"author": "stebalien",
"hash": "QmTRCUvZLiir12Qr6MV3HKfKMHX8Nf1Vddn6t2g5nsQSb9",
"hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM",
"name": "go-block-format",
"version": "0.1.7"
"version": "0.2.0"
},
{
"author": "multiformats",
"hash": "QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8",
"name": "go-multihash",
"version": "1.0.8"
"version": "1.0.7"
},
{
"author": "why",
@@ -49,6 +55,6 @@
"license": "",
"name": "go-ipld-cbor",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.3.2"
"version": "1.3.0"
}