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

lightningnetwork / lnd / 16807123789

07 Aug 2025 02:18PM UTC coverage: 54.85% (-12.1%) from 66.947%
16807123789

Pull #10140

github

web-flow
Merge d256dafec into 2269859d9
Pull Request #10140: [2/3] lnwire: fix encoding customized TLV records

192 of 207 new or added lines in 9 files covered. (92.75%)

23859 existing lines in 288 files now uncovered.

108730 of 198233 relevant lines covered (54.85%)

22096.12 hits per line

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

61.82
/lnwire/closing_sig.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/btcutil"
8
)
9

10
// ClosingSig is sent in response to a ClosingComplete message. It carries the
11
// signatures of the closee to the closer.
12
type ClosingSig struct {
13
        // ChannelID serves to identify which channel is to be closed.
14
        ChannelID ChannelID
15

16
        // CloserScript is the script to which the channel funds will be paid
17
        // for the closer (the person sending the ClosingComplete) message.
18
        CloserScript DeliveryAddress
19

20
        // CloseeScript is the script to which the channel funds will be paid
21
        // (the person receiving the ClosingComplete message).
22
        CloseeScript DeliveryAddress
23

24
        // FeeSatoshis is the total fee in satoshis that the party to the
25
        // channel proposed for the close transaction.
26
        FeeSatoshis btcutil.Amount
27

28
        // LockTime is the locktime number to be used in the input spending the
29
        // funding transaction.
30
        LockTime uint32
31

32
        // ClosingSigs houses the 3 possible signatures that can be sent.
33
        ClosingSigs
34

35
        // ExtraData is the set of data that was appended to this message to
36
        // fill out the full maximum transport message size. These fields can
37
        // be used to specify optional data such as custom TLV fields.
38
        ExtraData ExtraOpaqueData
39
}
40

41
// Decode deserializes a serialized ClosingSig message stored in the passed
42
// io.Reader.
43
func (c *ClosingSig) Decode(r io.Reader, _ uint32) error {
154✔
44
        // First, read out all the fields that are hard coded into the message.
154✔
45
        err := ReadElements(
154✔
46
                r, &c.ChannelID, &c.CloserScript, &c.CloseeScript,
154✔
47
                &c.FeeSatoshis, &c.LockTime,
154✔
48
        )
154✔
49
        if err != nil {
207✔
50
                return err
53✔
51
        }
53✔
52

53
        // With the hard coded messages read, we'll now read out the TLV fields
54
        // of the message.
55
        var tlvRecords ExtraOpaqueData
101✔
56
        if err := ReadElements(r, &tlvRecords); err != nil {
101✔
57
                return err
×
58
        }
×
59

60
        extraData, err := decodeClosingSigs(&c.ClosingSigs, tlvRecords)
101✔
61
        if err != nil {
101✔
62
                return err
×
63
        }
×
64

65
        c.ExtraData = extraData
101✔
66

101✔
67
        return nil
101✔
68
}
69

70
// Encode serializes the target ClosingSig into the passed io.Writer.
71
func (c *ClosingSig) Encode(w *bytes.Buffer, _ uint32) error {
101✔
72
        if err := WriteChannelID(w, c.ChannelID); err != nil {
101✔
73
                return err
×
74
        }
×
75

76
        if err := WriteDeliveryAddress(w, c.CloserScript); err != nil {
101✔
77
                return err
×
78
        }
×
79
        if err := WriteDeliveryAddress(w, c.CloseeScript); err != nil {
101✔
80
                return err
×
81
        }
×
82

83
        if err := WriteSatoshi(w, c.FeeSatoshis); err != nil {
101✔
84
                return err
×
85
        }
×
86

87
        if err := WriteUint32(w, c.LockTime); err != nil {
101✔
88
                return err
×
89
        }
×
90

91
        // Get producers from extra data.
92
        producers, err := c.ExtraData.RecordProducers()
101✔
93
        if err != nil {
101✔
NEW
94
                return err
×
NEW
95
        }
×
96

97
        producers = append(producers, closingSigRecords(&c.ClosingSigs)...)
101✔
98

101✔
99
        // Pack all records into a new TLV stream.
101✔
100
        var tlvData ExtraOpaqueData
101✔
101
        err = tlvData.PackRecords(producers...)
101✔
102
        if err != nil {
101✔
103
                return err
×
104
        }
×
105

106
        return WriteBytes(w, tlvData)
101✔
107
}
108

109
// MsgType returns the uint32 code which uniquely identifies this message as a
110
// ClosingSig message on the wire.
111
//
112
// This is part of the lnwire.Message interface.
113
func (c *ClosingSig) MsgType() MessageType {
100✔
114
        return MsgClosingSig
100✔
115
}
100✔
116

117
// SerializedSize returns the serialized size of the message in bytes.
118
//
119
// This is part of the lnwire.SizeableMessage interface.
UNCOV
120
func (c *ClosingSig) SerializedSize() (uint32, error) {
×
UNCOV
121
        return MessageSerializedSize(c)
×
UNCOV
122
}
×
123

124
// A compile time check to ensure ClosingSig implements the lnwire.Message
125
// interface.
126
var _ Message = (*ClosingSig)(nil)
127

128
// A compile time check to ensure ClosingSig implements the
129
// lnwire.SizeableMessage interface.
130
var _ SizeableMessage = (*ClosingSig)(nil)
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