• 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

88.1
/lnwire/short_channel_id.go
1
package lnwire
2

3
import (
4
        "fmt"
5
        "io"
6

7
        "github.com/lightningnetwork/lnd/tlv"
8
)
9

10
const (
11
        // AliasScidRecordType is the type of the experimental record to denote
12
        // the alias being used in an option_scid_alias channel.
13
        AliasScidRecordType tlv.Type = 1
14
)
15

16
// ShortChannelID represents the set of data which is needed to retrieve all
17
// necessary data to validate the channel existence.
18
type ShortChannelID struct {
19
        // BlockHeight is the height of the block where funding transaction
20
        // located.
21
        //
22
        // NOTE: This field is limited to 3 bytes.
23
        BlockHeight uint32
24

25
        // TxIndex is a position of funding transaction within a block.
26
        //
27
        // NOTE: This field is limited to 3 bytes.
28
        TxIndex uint32
29

30
        // TxPosition indicating transaction output which pays to the channel.
31
        TxPosition uint16
32
}
33

34
// NewShortChanIDFromInt returns a new ShortChannelID which is the decoded
35
// version of the compact channel ID encoded within the uint64. The format of
36
// the compact channel ID is as follows: 3 bytes for the block height, 3 bytes
37
// for the transaction index, and 2 bytes for the output index.
38
func NewShortChanIDFromInt(chanID uint64) ShortChannelID {
671,445✔
39
        return ShortChannelID{
671,445✔
40
                BlockHeight: uint32(chanID >> 40),
671,445✔
41
                TxIndex:     uint32(chanID>>16) & 0xFFFFFF,
671,445✔
42
                TxPosition:  uint16(chanID),
671,445✔
43
        }
671,445✔
44
}
671,445✔
45

46
// ToUint64 converts the ShortChannelID into a compact format encoded within a
47
// uint64 (8 bytes).
48
func (c ShortChannelID) ToUint64() uint64 {
11,667,217✔
49
        // TODO(roasbeef): explicit error on overflow?
11,667,217✔
50
        return ((uint64(c.BlockHeight) << 40) | (uint64(c.TxIndex) << 16) |
11,667,217✔
51
                (uint64(c.TxPosition)))
11,667,217✔
52
}
11,667,217✔
53

54
// String generates a human-readable representation of the channel ID.
55
func (c ShortChannelID) String() string {
4,791✔
56
        return fmt.Sprintf("%d:%d:%d", c.BlockHeight, c.TxIndex, c.TxPosition)
4,791✔
57
}
4,791✔
58

59
// AltString generates a human-readable representation of the channel ID
60
// with 'x' as a separator.
61
func (c ShortChannelID) AltString() string {
2✔
62
        return fmt.Sprintf("%dx%dx%d", c.BlockHeight, c.TxIndex, c.TxPosition)
2✔
63
}
2✔
64

65
// Record returns a TLV record that can be used to encode/decode a
66
// ShortChannelID to/from a TLV stream.
67
func (c *ShortChannelID) Record() tlv.Record {
11,391✔
68
        return tlv.MakeStaticRecord(
11,391✔
69
                AliasScidRecordType, c, 8, EShortChannelID, DShortChannelID,
11,391✔
70
        )
11,391✔
71
}
11,391✔
72

73
// IsDefault returns true if the ShortChannelID represents the zero value for
74
// its type.
UNCOV
75
func (c ShortChannelID) IsDefault() bool {
×
UNCOV
76
        return c == ShortChannelID{}
×
UNCOV
77
}
×
78

79
// EShortChannelID is an encoder for ShortChannelID. It is exported so other
80
// packages can use the encoding scheme.
81
func EShortChannelID(w io.Writer, val interface{}, buf *[8]byte) error {
3,593✔
82
        if v, ok := val.(*ShortChannelID); ok {
7,186✔
83
                return tlv.EUint64T(w, v.ToUint64(), buf)
3,593✔
84
        }
3,593✔
85
        return tlv.NewTypeForEncodingErr(val, "lnwire.ShortChannelID")
×
86
}
87

88
// DShortChannelID is a decoder for ShortChannelID. It is exported so other
89
// packages can use the decoding scheme.
90
func DShortChannelID(r io.Reader, val interface{}, buf *[8]byte,
91
        l uint64) error {
7,506✔
92

7,506✔
93
        if v, ok := val.(*ShortChannelID); ok {
15,012✔
94
                var scid uint64
7,506✔
95
                err := tlv.DUint64(r, &scid, buf, 8)
7,506✔
96
                if err != nil {
7,510✔
97
                        return err
4✔
98
                }
4✔
99

100
                *v = NewShortChanIDFromInt(scid)
7,502✔
101
                return nil
7,502✔
102
        }
103
        return tlv.NewTypeForDecodingErr(val, "lnwire.ShortChannelID", l, 8)
×
104
}
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