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

lightningnetwork / lnd / 19155841408

07 Nov 2025 02:03AM UTC coverage: 66.675% (-0.04%) from 66.712%
19155841408

Pull #10352

github

web-flow
Merge e4313eba8 into 096ab65b1
Pull Request #10352: [WIP] chainrpc: return Unavailable while notifier starts

137328 of 205965 relevant lines covered (66.68%)

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

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

157,516✔
29
        var zero uint64
157,516✔
30
        mask := (zero - 1) - uint64((1<<position)-1)
157,516✔
31
        return (uint64(index) & mask)
157,516✔
32
}
157,516✔
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,835✔
37
        var zeros uint8
169,835✔
38
        for ; zeros < maxHeight; zeros++ {
2,022,129✔
39

1,852,294✔
40
                if getBit(index, zeros) != 0 {
2,002,764✔
41
                        break
150,470✔
42
                }
43
        }
44

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