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

lightningnetwork / lnd / 11292787765

11 Oct 2024 12:58PM UTC coverage: 49.179% (-9.5%) from 58.716%
11292787765

push

github

web-flow
Merge pull request #9168 from feelancer21/fix-lncli-wallet-proto

lnrpc: fix lncli documentation tags in walletkit.proto

97369 of 197987 relevant lines covered (49.18%)

1.04 hits per line

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

63.04
/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✔
11
        return uint8((uint64(index) >> position) & 1)
2✔
12
}
2✔
13

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

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

2✔
40
                if getBit(index, zeros) != 0 {
4✔
41
                        break
2✔
42
                }
43
        }
44

45
        return zeros
2✔
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) {
×
52
        // Return an error if hash string is too long.
×
53
        if len(s) > chainhash.MaxHashStringSize {
×
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 {
×
59
                s = "0" + s
×
60
        }
×
61

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

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

73
        return hash, nil
×
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