Skip to content

Commit

Permalink
fix: moves height check to the beginning of the func and adds its val…
Browse files Browse the repository at this point in the history
…ue to error msg
  • Loading branch information
wregulski committed Sep 22, 2023
1 parent 3d089f5 commit f3b5b03
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions p2p_beef_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func extractPathMap(hexBytes []byte, height int) (map[string]uint64, int, error)
return nil, 0, fmt.Errorf("insufficient bytes to extract Compound Merkle Path at height %d", height)
}

if height < 0 {
return nil, 0, fmt.Errorf("unexpected negative value of height %d", height)
}

nLeaves, nLeavesBytesUsed := bt.NewVarIntFromBytes(hexBytes)
bytesUsed := nLeavesBytesUsed
var pathMap = make(map[string]uint64)
Expand All @@ -189,10 +193,6 @@ func extractPathMap(hexBytes []byte, height int) (map[string]uint64, int, error)
pathMap[hash] = uint64(offsetValue)
}

if height < 0 {
return nil, 0, errors.New("unexpected negative height value")
}

return pathMap, bytesUsed, nil
}

Expand Down

0 comments on commit f3b5b03

Please sign in to comment.