@@ -10,7 +10,6 @@ import (
1010 "sort"
1111
1212 "github.com/bitcoin-sv/go-sdk/chainhash"
13- crypto "github.com/bitcoin-sv/go-sdk/primitives/hash"
1413 "github.com/bitcoin-sv/go-sdk/transaction/chaintracker"
1514 "github.com/pkg/errors"
1615)
@@ -41,17 +40,14 @@ func (ip IndexedPath) GetOffsetLeaf(layer int, offset uint64) *PathElement {
4140 left := ip .GetOffsetLeaf (layer - 1 , prevOffset )
4241 right := ip .GetOffsetLeaf (layer - 1 , prevOffset + 1 )
4342 if left != nil && right != nil {
44- var digest []byte
45- if right .Duplicate != nil && * right .Duplicate {
46- digest = append (left .Hash .CloneBytes (), left .Hash .CloneBytes ()... )
47- } else {
48- digest = append (left .Hash .CloneBytes (), right .Hash .CloneBytes ()... )
49- }
50-
5143 pathElement := & PathElement {
5244 Offset : offset ,
5345 }
54- pathElement .Hash , _ = chainhash .NewHash (crypto .Sha256d (digest ))
46+ if right .Duplicate != nil && * right .Duplicate {
47+ pathElement .Hash = MerkleTreeParent (left .Hash , left .Hash )
48+ } else {
49+ pathElement .Hash = MerkleTreeParent (left .Hash , right .Hash )
50+ }
5551 return pathElement
5652 }
5753 return nil
@@ -253,20 +249,16 @@ func (mp *MerklePath) ComputeRoot(txid *chainhash.Hash) (*chainhash.Hash, error)
253249 if leaf == nil {
254250 return nil , fmt .Errorf ("we do not have a hash for this index at height: %v" , height )
255251 }
256- var digest []byte
257-
258252 if leaf .Duplicate != nil && * leaf .Duplicate {
259- digest = append (workingHash . CloneBytes () , workingHash . CloneBytes () ... )
253+ workingHash = MerkleTreeParent (workingHash , workingHash )
260254 } else {
261255 leafBytes := leaf .Hash
262256 if (offset % 2 ) != 0 {
263- digest = append (workingHash . CloneBytes () , leafBytes . CloneBytes () ... )
257+ workingHash = MerkleTreeParent (workingHash , leafBytes )
264258 } else {
265- digest = append (leafBytes . CloneBytes () , workingHash . CloneBytes () ... )
259+ workingHash = MerkleTreeParent (leafBytes , workingHash )
266260 }
267261 }
268-
269- workingHash , _ = chainhash .NewHash (crypto .Sha256d (digest ))
270262 }
271263 return workingHash , nil
272264}
0 commit comments