@cryptotaxi247 / kubo / commits / 1c74bc57d

include hash of resolved object in object stat output

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jul 21, 2015 at 07:55 UTC 1c74bc57d779d368674ab1601dec062c09f57c2c
2 files changed +15 -1
merkledag/merkledag_test.go
+8 -1
@@ -109,12 +109,19 @@ func SubtestNodeStat(t *testing.T, n *Node) {
109 return
110 }
111
112 + k, err := n.Key()
113 + if err != nil {
114 + t.Error("n.Key() failed")
115 + return
116 + }
117 +
118 expected := NodeStat{
119 NumLinks: len(n.Links),
120 BlockSize: len(enc),
121 LinksSize: len(enc) - len(n.Data), // includes framing.
122 DataSize: len(n.Data),
123 CumulativeSize: int(cumSize),
124 + Hash: k.B58String(),
125 }
126
127 actual, err := n.Stat()
@@ -124,7 +131,7 @@ func SubtestNodeStat(t *testing.T, n *Node) {
131 }
132
133 if expected != *actual {
127 - t.Error("n.Stat incorrect.\nexpect: %s\nactual: %s", expected, actual)
134 + t.Errorf("n.Stat incorrect.\nexpect: %s\nactual: %s", expected, actual)
135 } else {
136 fmt.Printf("n.Stat correct: %s\n", actual)
137 }
merkledag/node.go
+7
@@ -23,6 +23,7 @@ type Node struct {
23
24 // NodeStat is a statistics object for a Node. Mostly sizes.
25 type NodeStat struct {
26 + Hash string
27 NumLinks int // number of links in link table
28 BlockSize int // size of the raw, encoded data
29 LinksSize int // size of the links segment
@@ -201,7 +202,13 @@ func (n *Node) Stat() (*NodeStat, error) {
202 return nil, err
203 }
204
205 + key, err := n.Key()
206 + if err != nil {
207 + return nil, err
208 + }
209 +
210 return &NodeStat{
211 + Hash: key.B58String(),
212 NumLinks: len(n.Links),
213 BlockSize: len(enc),
214 LinksSize: len(enc) - len(n.Data), // includes framing.