• 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

100.0
/lntypes/hash.go
1
package lntypes
2

3
import (
4
        "encoding/hex"
5
        "fmt"
6
)
7

8
// HashSize of array used to store hashes.
9
const HashSize = 32
10

11
// ZeroHash is a predefined hash containing all zeroes.
12
var ZeroHash Hash
13

14
// Hash is used in several of the lightning messages and common structures. It
15
// typically represents a payment hash.
16
type Hash [HashSize]byte
17

18
// String returns the Hash as a hexadecimal string.
19
func (hash Hash) String() string {
353✔
20
        return hex.EncodeToString(hash[:])
353✔
21
}
353✔
22

23
// MakeHash returns a new Hash from a byte slice.  An error is returned if
24
// the number of bytes passed in is not HashSize.
25
func MakeHash(newHash []byte) (Hash, error) {
22,874✔
26
        nhlen := len(newHash)
22,874✔
27
        if nhlen != HashSize {
22,876✔
28
                return Hash{}, fmt.Errorf("invalid hash length of %v, want %v",
2✔
29
                        nhlen, HashSize)
2✔
30
        }
2✔
31

32
        var hash Hash
22,872✔
33
        copy(hash[:], newHash)
22,872✔
34

22,872✔
35
        return hash, nil
22,872✔
36
}
37

38
// MakeHashFromStr creates a Hash from a hex hash string.
39
func MakeHashFromStr(newHash string) (Hash, error) {
40✔
40
        // Return error if hash string is of incorrect length.
40✔
41
        if len(newHash) != HashSize*2 {
43✔
42
                return Hash{}, fmt.Errorf("invalid hash string length of %v, "+
3✔
43
                        "want %v", len(newHash), HashSize*2)
3✔
44
        }
3✔
45

46
        hash, err := hex.DecodeString(newHash)
40✔
47
        if err != nil {
43✔
48
                return Hash{}, err
3✔
49
        }
3✔
50

51
        return MakeHash(hash)
40✔
52
}
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