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

lightningnetwork / lnd / 13236757158

10 Feb 2025 08:39AM UTC coverage: 57.649% (-1.2%) from 58.815%
13236757158

Pull #9493

github

ziggie1984
lncli: for some cmds we don't replace the data of the response.

For some cmds it is not very practical to replace the json output
because we might pipe it into other commands. For example when
creating the route we want to pipe it into sendtoRoute.
Pull Request #9493: For some lncli cmds we should not replace the content with other data

0 of 9 new or added lines in 2 files covered. (0.0%)

19535 existing lines in 252 files now uncovered.

103517 of 179563 relevant lines covered (57.65%)

24878.49 hits per line

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

73.33
/labels/labels.go
1
// Package labels contains labels used to label transactions broadcast by lnd.
2
// These labels are used across packages, so they are declared in a separate
3
// package to avoid dependency issues.
4
//
5
// Labels for transactions broadcast by lnd have two set fields followed by an
6
// optional set labelled data values, all separated by colons.
7
//   - Label version: an integer that indicates the version lnd used
8
//   - Label type: the type of transaction we are labelling
9
//   - {field name}-{value}: a named field followed by its value, these items are
10
//     optional, and there may be more than field present.
11
//
12
// For version 0 we have the following optional data fields defined:
13
//   - shortchanid: the short channel ID that a transaction is associated with,
14
//     with its value set to the uint64 short channel id.
15
package labels
16

17
import (
18
        "fmt"
19

20
        "github.com/btcsuite/btcwallet/wtxmgr"
21
        "github.com/lightningnetwork/lnd/lnwire"
22
)
23

24
// External labels a transaction as user initiated via the api. This
25
// label is only used when a custom user provided label is not given.
26
const External = "external"
27

28
// ValidateAPI returns the generic api label if the label provided is empty.
29
// This allows us to label all transactions published by the api, even if
30
// no label is provided. If a label is provided, it is validated against
31
// the known restrictions.
32
func ValidateAPI(label string) (string, error) {
4✔
33
        if len(label) > wtxmgr.TxLabelLimit {
4✔
34
                return "", fmt.Errorf("label length: %v exceeds "+
×
35
                        "limit of %v", len(label), wtxmgr.TxLabelLimit)
×
36
        }
×
37

38
        // If no label was provided by the user, add the generic user
39
        // send label.
40
        if len(label) == 0 {
8✔
41
                return External, nil
4✔
42
        }
4✔
43

UNCOV
44
        return label, nil
×
45
}
46

47
// LabelVersion versions our labels so they can be easily update to contain
48
// new data while still easily string matched.
49
type LabelVersion uint8
50

51
// LabelVersionZero is the label version for labels that contain label type and
52
// channel ID (where available).
53
const LabelVersionZero LabelVersion = iota
54

55
// LabelType indicates the type of label we are creating. It is a string rather
56
// than an int for easy string matching and human-readability.
57
type LabelType string
58

59
const (
60
        // LabelTypeChannelOpen is used to label channel opens.
61
        LabelTypeChannelOpen LabelType = "openchannel"
62

63
        // LabelTypeChannelClose is used to label channel closes.
64
        LabelTypeChannelClose LabelType = "closechannel"
65

66
        // LabelTypeJusticeTransaction is used to label justice transactions.
67
        LabelTypeJusticeTransaction LabelType = "justicetx"
68

69
        // LabelTypeSweepTransaction is used to label sweeps.
70
        LabelTypeSweepTransaction LabelType = "sweep"
71
)
72

73
// LabelField is used to tag a value within a label.
74
type LabelField string
75

76
const (
77
        // ShortChanID is used to tag short channel id values in our labels.
78
        ShortChanID LabelField = "shortchanid"
79
)
80

81
// MakeLabel creates a label with the provided type and short channel id. If
82
// our short channel ID is not known, we simply return version:label_type. If
83
// we do have a short channel ID set, the label will also contain its value:
84
// shortchanid-{int64 chan ID}.
85
func MakeLabel(labelType LabelType, channelID *lnwire.ShortChannelID) string {
128✔
86
        if channelID == nil {
199✔
87
                return fmt.Sprintf("%v:%v", LabelVersionZero, labelType)
71✔
88
        }
71✔
89

90
        return fmt.Sprintf("%v:%v:%v-%v", LabelVersionZero, labelType,
57✔
91
                ShortChanID, channelID.ToUint64())
57✔
92
}
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