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

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 hits per line

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

14.75
/lnrpc/walletrpc/walletkit_util.go
1
package walletrpc
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "strconv"
7
        "strings"
8

9
        "github.com/btcsuite/btcd/chaincfg/chainhash"
10
        "github.com/btcsuite/btcd/wire"
11
        "github.com/lightningnetwork/lnd/lnrpc"
12
)
13

14
// AccountsToWatchOnly converts the accounts returned by the walletkit's
15
// ListAccounts RPC into a struct that can be used to create a watch-only
16
// wallet.
17
func AccountsToWatchOnly(exported []*Account) ([]*lnrpc.WatchOnlyAccount,
18
        error) {
×
19

×
20
        result := make([]*lnrpc.WatchOnlyAccount, len(exported))
×
21
        for idx, acct := range exported {
×
22
                parsedPath, err := parseDerivationPath(acct.DerivationPath)
×
23
                if err != nil {
×
24
                        return nil, fmt.Errorf("error parsing derivation path "+
×
25
                                "of account %d: %v", idx, err)
×
26
                }
×
27
                if len(parsedPath) < 3 {
×
28
                        return nil, fmt.Errorf("derivation path of account %d "+
×
29
                                "has invalid derivation path, need at least "+
×
30
                                "path of depth 3, instead has depth %d", idx,
×
31
                                len(parsedPath))
×
32
                }
×
33

34
                result[idx] = &lnrpc.WatchOnlyAccount{
×
35
                        Purpose:  parsedPath[0],
×
36
                        CoinType: parsedPath[1],
×
37
                        Account:  parsedPath[2],
×
38
                        Xpub:     acct.ExtendedPublicKey,
×
39
                }
×
40
        }
41

42
        return result, nil
×
43
}
44

45
// parseDerivationPath parses a path in the form of m/x'/y'/z'/a/b into a slice
46
// of [x, y, z, a, b], meaning that the apostrophe is ignored and 2^31 is _not_
47
// added to the numbers.
UNCOV
48
func parseDerivationPath(path string) ([]uint32, error) {
×
UNCOV
49
        path = strings.TrimSpace(path)
×
UNCOV
50
        if len(path) == 0 {
×
UNCOV
51
                return nil, fmt.Errorf("path cannot be empty")
×
UNCOV
52
        }
×
UNCOV
53
        if !strings.HasPrefix(path, "m/") {
×
UNCOV
54
                return nil, fmt.Errorf("path must start with m/")
×
UNCOV
55
        }
×
56

57
        // Just the root key, no path was provided. This is valid but not useful
58
        // in most cases.
UNCOV
59
        rest := strings.ReplaceAll(path, "m/", "")
×
UNCOV
60
        if rest == "" {
×
UNCOV
61
                return []uint32{}, nil
×
UNCOV
62
        }
×
63

UNCOV
64
        parts := strings.Split(rest, "/")
×
UNCOV
65
        indices := make([]uint32, len(parts))
×
UNCOV
66
        for i := 0; i < len(parts); i++ {
×
UNCOV
67
                part := parts[i]
×
UNCOV
68
                if strings.Contains(parts[i], "'") {
×
UNCOV
69
                        part = strings.TrimRight(parts[i], "'")
×
UNCOV
70
                }
×
UNCOV
71
                parsed, err := strconv.ParseInt(part, 10, 32)
×
UNCOV
72
                if err != nil {
×
UNCOV
73
                        return nil, fmt.Errorf("could not parse part \"%s\": "+
×
UNCOV
74
                                "%v", part, err)
×
UNCOV
75
                }
×
UNCOV
76
                indices[i] = uint32(parsed)
×
77
        }
UNCOV
78
        return indices, nil
×
79
}
80

81
// doubleHashMessage creates the double hash (sha256) of a message
82
// prepended with a specified prefix.
83
func doubleHashMessage(prefix string, msg string) ([]byte, error) {
3✔
84
        var buf bytes.Buffer
3✔
85
        err := wire.WriteVarString(&buf, 0, prefix)
3✔
86
        if err != nil {
3✔
87
                return nil, err
×
88
        }
×
89

90
        err = wire.WriteVarString(&buf, 0, msg)
3✔
91
        if err != nil {
3✔
92
                return nil, err
×
93
        }
×
94

95
        digest := chainhash.DoubleHashB(buf.Bytes())
3✔
96

3✔
97
        return digest, nil
3✔
98
}
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