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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 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 {
123✔
86
        if channelID == nil {
194✔
87
                return fmt.Sprintf("%v:%v", LabelVersionZero, labelType)
71✔
88
        }
71✔
89

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