diff --git a/claim/hash.go b/claim/hash.go index 69c4102..e4d40ca 100644 --- a/claim/hash.go +++ b/claim/hash.go @@ -9,7 +9,7 @@ import ( "github.com/btcsuite/btcd/wire" ) -func calNodeHash(op wire.OutPoint, tookover Height) chainhash.Hash { +func calNodeHash(op wire.OutPoint, tookover Height) *chainhash.Hash { txHash := chainhash.DoubleHashH(op.Hash[:]) nOut := []byte(strconv.Itoa(int(op.Index))) @@ -24,5 +24,6 @@ func calNodeHash(op wire.OutPoint, tookover Height) chainhash.Hash { h = append(h, nOutHash[:]...) h = append(h, heightHash[:]...) - return chainhash.DoubleHashH(h) + hh := chainhash.DoubleHashH(h) + return &hh } diff --git a/claim/node.go b/claim/node.go index 54252ea..c091392 100644 --- a/claim/node.go +++ b/claim/node.go @@ -165,9 +165,9 @@ func (n *Node) FindNextUpdateHeight() Height { } // Hash calculates the Hash value based on the OutPoint and at which height it tookover. -func (n *Node) Hash() chainhash.Hash { +func (n *Node) Hash() *chainhash.Hash { if n.BestClaim() == nil { - return chainhash.Hash{} + return nil } return calNodeHash(n.BestClaim().OutPoint, n.Tookover()) } diff --git a/cmd/claimtrie/main.go b/cmd/claimtrie/main.go index 01cda98..a18d323 100644 --- a/cmd/claimtrie/main.go +++ b/cmd/claimtrie/main.go @@ -223,7 +223,7 @@ func (a *args) all() bool { var showNode = func(showJSON bool) trie.Visit { return func(prefix trie.Key, val trie.Value) error { - if val == nil { + if val == nil || val.Hash() == nil { fmt.Printf("%-8s:\n", prefix) return nil } diff --git a/trie/cmd/triesh/main.go b/trie/cmd/triesh/main.go index b71503b..c0c914b 100644 --- a/trie/cmd/triesh/main.go +++ b/trie/cmd/triesh/main.go @@ -103,8 +103,9 @@ func main() { type strValue string -func (s strValue) Hash() chainhash.Hash { - return chainhash.DoubleHashH([]byte(s)) +func (s strValue) Hash() *chainhash.Hash { + h := chainhash.DoubleHashH([]byte(s)) + return &h } var ( diff --git a/trie/node.go b/trie/node.go index b6ef714..1c0fbd5 100644 --- a/trie/node.go +++ b/trie/node.go @@ -84,8 +84,9 @@ func merkle(n *node) *chainhash.Hash { } } if n.value != nil { - h := n.value.Hash() - buf = append(buf, h[:]...) + if h := n.value.Hash(); h != nil { + buf = append(buf, h[:]...) + } } if len(buf) != 0 { diff --git a/trie/test.go b/trie/test.go index 60a3ae0..b92e01d 100644 --- a/trie/test.go +++ b/trie/test.go @@ -10,8 +10,9 @@ import ( type strValue string -func (s strValue) Hash() chainhash.Hash { - return chainhash.DoubleHashH([]byte(s)) +func (s strValue) Hash() *chainhash.Hash { + h := chainhash.DoubleHashH([]byte(s)) + return &h } func dump(prefix Key, value Value) error { diff --git a/trie/trie.go b/trie/trie.go index 355325f..21a5410 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -16,7 +16,7 @@ type Key []byte // Value implements value for the MerkleTrie. type Value interface { - Hash() chainhash.Hash + Hash() *chainhash.Hash } // MerkleTrie implements a 256-way prefix tree, which takes Key as key and any value that implements the Value interface.