Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
refactor(BUX-166): MerkleProofToBUMP simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-4chain committed Nov 29, 2023
1 parent 0f81dcf commit 1fa5829
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions model_bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,7 @@ func MerkleProofToBUMP(merkleProof *bc.MerkleProof, blockHeight uint64) BUMP {
Hash: merkleProof.TxOrID,
TxID: true,
}
txIDPath2 := BUMPLeaf{
Offset: getOffsetPair(offset),
}
if merkleProof.Nodes[0] != "*" {
txIDPath2.Hash = merkleProof.Nodes[0]
} else {
txIDPath2.Duplicate = true
}
txIDPath2 := createLeaf(getOffsetPair(offset), merkleProof.Nodes[0])

if offset < pairOffset {
txIDPath[0] = txIDPath1
Expand All @@ -389,18 +382,24 @@ func MerkleProofToBUMP(merkleProof *bc.MerkleProof, blockHeight uint64) BUMP {
p := make([]BUMPLeaf, 0)
offset = getParentOffset(offset)

leaf := BUMPLeaf{Offset: offset}

isDuplicate := merkleProof.Nodes[i] == "*"
if !isDuplicate {
leaf.Hash = merkleProof.Nodes[i]
} else {
leaf.Duplicate = true
}
leaf := createLeaf(offset, merkleProof.Nodes[i])

p = append(p, leaf)
path = append(path, p)
}
bump.Path = path
return bump
}

func createLeaf(offset uint64, node string) BUMPLeaf {
leaf := BUMPLeaf{Offset: offset}

isDuplicate := node == "*"
if !isDuplicate {
leaf.Hash = node
} else {
leaf.Duplicate = true
}

return leaf
}

0 comments on commit 1fa5829

Please sign in to comment.