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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

0.0
/watchtower/wtdb/migration4/codec.go
1
package migration4
2

3
import (
4
        "encoding/binary"
5
        "encoding/hex"
6
        "fmt"
7
        "io"
8
)
9

10
// SessionIDSize is 33-bytes; it is a serialized, compressed public key.
11
const SessionIDSize = 33
12

13
// SessionID is created from the remote public key of a client, and serves as a
14
// unique identifier and authentication for sending state updates.
15
type SessionID [SessionIDSize]byte
16

17
// String returns a hex encoding of the session id.
UNCOV
18
func (s SessionID) String() string {
×
UNCOV
19
        return hex.EncodeToString(s[:])
×
UNCOV
20
}
×
21

22
// ChannelID is a series of 32-bytes that uniquely identifies all channels
23
// within the network. The ChannelID is computed using the outpoint of the
24
// funding transaction (the txid, and output index). Given a funding output the
25
// ChannelID can be calculated by XOR'ing the big-endian serialization of the
26
// txid and the big-endian serialization of the output index, truncated to
27
// 2 bytes.
28
type ChannelID [32]byte
29

30
// String returns the string representation of the ChannelID. This is just the
31
// hex string encoding of the ChannelID itself.
32
func (c ChannelID) String() string {
×
33
        return hex.EncodeToString(c[:])
×
34
}
×
35

36
// BackupID identifies a particular revoked, remote commitment by channel id and
37
// commitment height.
38
type BackupID struct {
39
        // ChanID is the channel id of the revoked commitment.
40
        ChanID ChannelID
41

42
        // CommitHeight is the commitment height of the revoked commitment.
43
        CommitHeight uint64
44
}
45

46
// Encode writes the BackupID from the passed io.Writer.
UNCOV
47
func (b *BackupID) Encode(w io.Writer) error {
×
UNCOV
48
        return WriteElements(w,
×
UNCOV
49
                b.ChanID,
×
UNCOV
50
                b.CommitHeight,
×
UNCOV
51
        )
×
UNCOV
52
}
×
53

54
// Decode reads a BackupID from the passed io.Reader.
UNCOV
55
func (b *BackupID) Decode(r io.Reader) error {
×
UNCOV
56
        return ReadElements(r,
×
UNCOV
57
                &b.ChanID,
×
UNCOV
58
                &b.CommitHeight,
×
UNCOV
59
        )
×
UNCOV
60
}
×
61

62
// String returns a human-readable encoding of a BackupID.
63
func (b BackupID) String() string {
×
64
        return fmt.Sprintf("backup(%v, %d)", b.ChanID, b.CommitHeight)
×
65
}
×
66

67
// WriteElements serializes a variadic list of elements into the given
68
// io.Writer.
UNCOV
69
func WriteElements(w io.Writer, elements ...interface{}) error {
×
UNCOV
70
        for _, element := range elements {
×
UNCOV
71
                if err := WriteElement(w, element); err != nil {
×
72
                        return err
×
73
                }
×
74
        }
75

UNCOV
76
        return nil
×
77
}
78

79
// ReadElements deserializes the provided io.Reader into a variadic list of
80
// target elements.
UNCOV
81
func ReadElements(r io.Reader, elements ...interface{}) error {
×
UNCOV
82
        for _, element := range elements {
×
UNCOV
83
                if err := ReadElement(r, element); err != nil {
×
84
                        return err
×
85
                }
×
86
        }
87

UNCOV
88
        return nil
×
89
}
90

91
// WriteElement serializes a single element into the provided io.Writer.
UNCOV
92
func WriteElement(w io.Writer, element interface{}) error {
×
UNCOV
93
        switch e := element.(type) {
×
UNCOV
94
        case ChannelID:
×
UNCOV
95
                if _, err := w.Write(e[:]); err != nil {
×
96
                        return err
×
97
                }
×
98

UNCOV
99
        case uint64:
×
UNCOV
100
                if err := binary.Write(w, byteOrder, e); err != nil {
×
101
                        return err
×
102
                }
×
103

104
        default:
×
105
                return fmt.Errorf("unexpected type")
×
106
        }
107

UNCOV
108
        return nil
×
109
}
110

111
// ReadElement deserializes a single element from the provided io.Reader.
UNCOV
112
func ReadElement(r io.Reader, element interface{}) error {
×
UNCOV
113
        switch e := element.(type) {
×
UNCOV
114
        case *ChannelID:
×
UNCOV
115
                if _, err := io.ReadFull(r, e[:]); err != nil {
×
116
                        return err
×
117
                }
×
118

UNCOV
119
        case *uint64:
×
UNCOV
120
                if err := binary.Read(r, byteOrder, e); err != nil {
×
121
                        return err
×
122
                }
×
123

124
        default:
×
125
                return fmt.Errorf("unexpected type")
×
126
        }
127

UNCOV
128
        return nil
×
129
}
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