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

lightningnetwork / lnd / 13423774416

19 Feb 2025 10:39PM UTC coverage: 49.338% (-9.5%) from 58.794%
13423774416

Pull #9484

github

Abdulkbk
lnutils: add createdir util function

This utility function replaces repetitive logic patterns
throughout LND.
Pull Request #9484: lnutils: add createDir util function

0 of 13 new or added lines in 1 file covered. (0.0%)

27149 existing lines in 431 files now uncovered.

100732 of 204168 relevant lines covered (49.34%)

1.54 hits per line

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

74.58
/netann/node_announcement.go
1
package netann
2

3
import (
4
        "image/color"
5
        "net"
6
        "time"
7

8
        "github.com/lightningnetwork/lnd/keychain"
9
        "github.com/lightningnetwork/lnd/lnwallet"
10
        "github.com/lightningnetwork/lnd/lnwire"
11
)
12

13
// NodeAnnModifier is a closure that makes in-place modifications to an
14
// lnwire.NodeAnnouncement.
15
type NodeAnnModifier func(*lnwire.NodeAnnouncement)
16

17
// NodeAnnSetAlias is a functional option that sets the alias of the
18
// given node announcement.
19
func NodeAnnSetAlias(alias lnwire.NodeAlias) func(*lnwire.NodeAnnouncement) {
20
        return func(nodeAnn *lnwire.NodeAnnouncement) {
21
                nodeAnn.Alias = alias
22
        }
23
}
3✔
24

6✔
25
// NodeAnnSetAddrs is a functional option that allows updating the addresses of
3✔
26
// the given node announcement.
3✔
27
func NodeAnnSetAddrs(addrs []net.Addr) func(*lnwire.NodeAnnouncement) {
28
        return func(nodeAnn *lnwire.NodeAnnouncement) {
29
                nodeAnn.Addresses = addrs
30
        }
31
}
3✔
32

6✔
33
// NodeAnnSetColor is a functional option that sets the color of the
3✔
34
// given node announcement.
3✔
35
func NodeAnnSetColor(newColor color.RGBA) func(*lnwire.NodeAnnouncement) {
36
        return func(nodeAnn *lnwire.NodeAnnouncement) {
37
                nodeAnn.RGBColor = newColor
38
        }
39
}
3✔
40

6✔
41
// NodeAnnSetFeatures is a functional option that allows updating the features of
3✔
42
// the given node announcement.
3✔
43
func NodeAnnSetFeatures(features *lnwire.RawFeatureVector) func(*lnwire.NodeAnnouncement) {
44
        return func(nodeAnn *lnwire.NodeAnnouncement) {
45
                nodeAnn.Features = features
46
        }
47
}
3✔
48

6✔
49
// NodeAnnSetTimestamp is a functional option that sets the timestamp of the
3✔
50
// announcement to the current time, or increments it if the timestamp is
3✔
51
// already in the future.
52
func NodeAnnSetTimestamp(nodeAnn *lnwire.NodeAnnouncement) {
53
        newTimestamp := uint32(time.Now().Unix())
54
        if newTimestamp <= nodeAnn.Timestamp {
55
                // Increment the prior value to  ensure the timestamp
56
                // monotonically increases, otherwise the announcement won't
3✔
57
                // propagate.
3✔
58
                newTimestamp = nodeAnn.Timestamp + 1
6✔
59
        }
3✔
60
        nodeAnn.Timestamp = newTimestamp
3✔
61
}
3✔
62

3✔
63
// SignNodeAnnouncement signs the lnwire.NodeAnnouncement provided, which
3✔
64
// should be the most recent, valid update, otherwise the timestamp may not
3✔
65
// monotonically increase from the prior.
66
func SignNodeAnnouncement(signer lnwallet.MessageSigner,
67
        keyLoc keychain.KeyLocator, nodeAnn *lnwire.NodeAnnouncement) error {
68

69
        // Create the DER-encoded ECDSA signature over the message digest.
70
        sig, err := SignAnnouncement(signer, keyLoc, nodeAnn)
71
        if err != nil {
3✔
72
                return err
3✔
73
        }
3✔
74

3✔
75
        // Parse the DER-encoded signature into a fixed-size 64-byte array.
3✔
76
        nodeAnn.Signature, err = lnwire.NewSigFromSignature(sig)
×
77
        return err
×
78
}
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