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

lightningnetwork / lnd / 14193549836

01 Apr 2025 10:40AM UTC coverage: 69.046% (+0.007%) from 69.039%
14193549836

Pull #9665

github

web-flow
Merge e8825f209 into b01f4e514
Pull Request #9665: kvdb: bump etcd libs to v3.5.12

133439 of 193262 relevant lines covered (69.05%)

22119.45 hits per line

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

62.71
/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.
18
func (s SessionID) String() string {
10✔
19
        return hex.EncodeToString(s[:])
10✔
20
}
10✔
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.
47
func (b *BackupID) Encode(w io.Writer) error {
20✔
48
        return WriteElements(w,
20✔
49
                b.ChanID,
20✔
50
                b.CommitHeight,
20✔
51
        )
20✔
52
}
20✔
53

54
// Decode reads a BackupID from the passed io.Reader.
55
func (b *BackupID) Decode(r io.Reader) error {
35✔
56
        return ReadElements(r,
35✔
57
                &b.ChanID,
35✔
58
                &b.CommitHeight,
35✔
59
        )
35✔
60
}
35✔
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.
69
func WriteElements(w io.Writer, elements ...interface{}) error {
20✔
70
        for _, element := range elements {
60✔
71
                if err := WriteElement(w, element); err != nil {
40✔
72
                        return err
×
73
                }
×
74
        }
75

76
        return nil
20✔
77
}
78

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

88
        return nil
35✔
89
}
90

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

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

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

108
        return nil
40✔
109
}
110

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

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

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

128
        return nil
70✔
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