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

lightningnetwork / lnd / 14193549836

01 Apr 2025 10:40AM UTC coverage: 69.046% (+0.007%) from 69.039%
14193549836

Pull #9665

github

web-flow
Merge e8825f209 into b01f4e514
Pull Request #9665: kvdb: bump etcd libs to v3.5.12

133439 of 193262 relevant lines covered (69.05%)

22119.45 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,879,142✔
11
        return uint8((uint64(index) >> position) & 1)
2,879,142✔
12
}
2,879,142✔
13

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

156,904✔
29
        var zero uint64
156,904✔
30
        mask := (zero - 1) - uint64((1<<position)-1)
156,904✔
31
        return (uint64(index) & mask)
156,904✔
32
}
156,904✔
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,127✔
37
        var zeros uint8
169,127✔
38
        for ; zeros < maxHeight; zeros++ {
1,995,693✔
39

1,826,566✔
40
                if getBit(index, zeros) != 0 {
1,976,854✔
41
                        break
150,288✔
42
                }
43
        }
44

45
        return zeros
169,127✔
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