Skip to content

Commit 1c74bc5

Browse files
committedJul 21, 2015
include hash of resolved object in object stat output
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent d37ecbb commit 1c74bc5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎merkledag/merkledag_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,19 @@ func SubtestNodeStat(t *testing.T, n *Node) {
109109
return
110110
}
111111

112+
k, err := n.Key()
113+
if err != nil {
114+
t.Error("n.Key() failed")
115+
return
116+
}
117+
112118
expected := NodeStat{
113119
NumLinks: len(n.Links),
114120
BlockSize: len(enc),
115121
LinksSize: len(enc) - len(n.Data), // includes framing.
116122
DataSize: len(n.Data),
117123
CumulativeSize: int(cumSize),
124+
Hash: k.B58String(),
118125
}
119126

120127
actual, err := n.Stat()
@@ -124,7 +131,7 @@ func SubtestNodeStat(t *testing.T, n *Node) {
124131
}
125132

126133
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)
128135
} else {
129136
fmt.Printf("n.Stat correct: %s\n", actual)
130137
}

‎merkledag/node.go

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Node struct {
2323

2424
// NodeStat is a statistics object for a Node. Mostly sizes.
2525
type NodeStat struct {
26+
Hash string
2627
NumLinks int // number of links in link table
2728
BlockSize int // size of the raw, encoded data
2829
LinksSize int // size of the links segment
@@ -201,7 +202,13 @@ func (n *Node) Stat() (*NodeStat, error) {
201202
return nil, err
202203
}
203204

205+
key, err := n.Key()
206+
if err != nil {
207+
return nil, err
208+
}
209+
204210
return &NodeStat{
211+
Hash: key.B58String(),
205212
NumLinks: len(n.Links),
206213
BlockSize: len(enc),
207214
LinksSize: len(enc) - len(n.Data), // includes framing.

0 commit comments

Comments
 (0)
Please sign in to comment.