• 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

87.18
/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 {
493,840✔
39
        return ShortChannelID{
493,840✔
40
                BlockHeight: uint32(chanID >> 40),
493,840✔
41
                TxIndex:     uint32(chanID>>16) & 0xFFFFFF,
493,840✔
42
                TxPosition:  uint16(chanID),
493,840✔
43
        }
493,840✔
44
}
493,840✔
45

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

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

59
// Record returns a TLV record that can be used to encode/decode a
60
// ShortChannelID to/from a TLV stream.
61
func (c *ShortChannelID) Record() tlv.Record {
16,645✔
62
        return tlv.MakeStaticRecord(
16,645✔
63
                AliasScidRecordType, c, 8, EShortChannelID, DShortChannelID,
16,645✔
64
        )
16,645✔
65
}
16,645✔
66

67
// IsDefault returns true if the ShortChannelID represents the zero value for
68
// its type.
UNCOV
69
func (c ShortChannelID) IsDefault() bool {
×
UNCOV
70
        return c == ShortChannelID{}
×
UNCOV
71
}
×
72

73
// EShortChannelID is an encoder for ShortChannelID. It is exported so other
74
// packages can use the encoding scheme.
75
func EShortChannelID(w io.Writer, val interface{}, buf *[8]byte) error {
4,902✔
76
        if v, ok := val.(*ShortChannelID); ok {
9,804✔
77
                return tlv.EUint64T(w, v.ToUint64(), buf)
4,902✔
78
        }
4,902✔
79
        return tlv.NewTypeForEncodingErr(val, "lnwire.ShortChannelID")
×
80
}
81

82
// DShortChannelID is a decoder for ShortChannelID. It is exported so other
83
// packages can use the decoding scheme.
84
func DShortChannelID(r io.Reader, val interface{}, buf *[8]byte,
85
        l uint64) error {
11,619✔
86

11,619✔
87
        if v, ok := val.(*ShortChannelID); ok {
23,238✔
88
                var scid uint64
11,619✔
89
                err := tlv.DUint64(r, &scid, buf, 8)
11,619✔
90
                if err != nil {
11,621✔
91
                        return err
2✔
92
                }
2✔
93

94
                *v = NewShortChanIDFromInt(scid)
11,617✔
95
                return nil
11,617✔
96
        }
97
        return tlv.NewTypeForDecodingErr(val, "lnwire.ShortChannelID", l, 8)
×
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