• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13586005509

28 Feb 2025 10:14AM UTC coverage: 68.629% (+9.9%) from 58.77%
13586005509

Pull #9521

github

web-flow
Merge 37d3a70a5 into 8532955b3
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

129950 of 189351 relevant lines covered (68.63%)

23726.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.61
/shachain/utils.go
1
package shachain
2

3
import (
4
        "encoding/hex"
5

6
        "github.com/btcsuite/btcd/chaincfg/chainhash"
7
)
8

9
// getBit return bit on index at position.
10
func getBit(index index, position uint8) uint8 {
2,890,452✔
11
        return uint8((uint64(index) >> position) & 1)
2,890,452✔
12
}
2,890,452✔
13

14
func getPrefix(index index, position uint8) uint64 {
157,061✔
15
        //        + -------------------------- +
157,061✔
16
        //         | №  | value | mask | return |
157,061✔
17
        //        + -- + ----- + ---- + ------ +
157,061✔
18
        //        | 63 |         1   |  0   |         0   |
157,061✔
19
        //        | 62 |         0   |  0   |         0   |
157,061✔
20
        //        | 61 |   1   |  0   |         0   |
157,061✔
21
        //                ....
157,061✔
22
        //        |  4 |         1   |  0   |         0   |
157,061✔
23
        //        |  3 |   1   |  0   |         0   |
157,061✔
24
        //        |  2 |   1   |  1   |         1   | <--- position
157,061✔
25
        //        |  1 |   0   |  1   |         0   |
157,061✔
26
        //        |  0 |   1   |  1   |         1   |
157,061✔
27
        //        + -- + ----- + ---- + ------ +
157,061✔
28

157,061✔
29
        var zero uint64
157,061✔
30
        mask := (zero - 1) - uint64((1<<position)-1)
157,061✔
31
        return (uint64(index) & mask)
157,061✔
32
}
157,061✔
33

34
// countTrailingZeros counts number of trailing zero bits, this function is
35
// used to determine the number of element bucket.
36
func countTrailingZeros(index index) uint8 {
169,322✔
37
        var zeros uint8
169,322✔
38
        for ; zeros < maxHeight; zeros++ {
2,001,605✔
39

1,832,283✔
40
                if getBit(index, zeros) != 0 {
1,982,652✔
41
                        break
150,369✔
42
                }
43
        }
44

45
        return zeros
169,322✔
46
}
47

48
// hashFromString takes a hex-encoded string as input and creates an instance of
49
// chainhash.Hash. The chainhash.NewHashFromStr function not suitable because
50
// it reverse the given hash.
51
func hashFromString(s string) (*chainhash.Hash, error) {
66✔
52
        // Return an error if hash string is too long.
66✔
53
        if len(s) > chainhash.MaxHashStringSize {
66✔
54
                return nil, chainhash.ErrHashStrSize
×
55
        }
×
56

57
        // Hex decoder expects the hash to be a multiple of two.
58
        if len(s)%2 != 0 {
66✔
59
                s = "0" + s
×
60
        }
×
61

62
        // Convert string hash to bytes.
63
        buf, err := hex.DecodeString(s)
66✔
64
        if err != nil {
66✔
65
                return nil, err
×
66
        }
×
67

68
        hash, err := chainhash.NewHash(buf)
66✔
69
        if err != nil {
66✔
70
                return nil, err
×
71
        }
×
72

73
        return hash, nil
66✔
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc