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

lightningnetwork / lnd / 9915780197

13 Jul 2024 12:30AM UTC coverage: 49.268% (-9.1%) from 58.413%
9915780197

push

github

web-flow
Merge pull request #8653 from ProofOfKeags/fn-prim

DynComms [0/n]: `fn` package additions

92837 of 188433 relevant lines covered (49.27%)

1.55 hits per line

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

76.92
/lnwire/shutdown.go
1
package lnwire
2

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

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

10
type (
11
        // ShutdownNonceType is the type of the shutdown nonce TLV record.
12
        ShutdownNonceType = tlv.TlvType8
13

14
        // ShutdownNonceTLV is the TLV record that contains the shutdown nonce.
15
        ShutdownNonceTLV = tlv.OptionalRecordT[ShutdownNonceType, Musig2Nonce]
16
)
17

18
// SomeShutdownNonce returns a ShutdownNonceTLV with the given nonce.
19
func SomeShutdownNonce(nonce Musig2Nonce) ShutdownNonceTLV {
3✔
20
        return tlv.SomeRecordT(
3✔
21
                tlv.NewRecordT[ShutdownNonceType, Musig2Nonce](nonce),
3✔
22
        )
3✔
23
}
3✔
24

25
// Shutdown is sent by either side in order to initiate the cooperative closure
26
// of a channel. This message is sparse as both sides implicitly have the
27
// information necessary to construct a transaction that will send the settled
28
// funds of both parties to the final delivery addresses negotiated during the
29
// funding workflow.
30
type Shutdown struct {
31
        // ChannelID serves to identify which channel is to be closed.
32
        ChannelID ChannelID
33

34
        // Address is the script to which the channel funds will be paid.
35
        Address DeliveryAddress
36

37
        // ShutdownNonce is the nonce the sender will use to sign the first
38
        // co-op sign offer.
39
        ShutdownNonce ShutdownNonceTLV
40

41
        // ExtraData is the set of data that was appended to this message to
42
        // fill out the full maximum transport message size. These fields can
43
        // be used to specify optional data such as custom TLV fields.
44
        ExtraData ExtraOpaqueData
45
}
46

47
// NewShutdown creates a new Shutdown message.
48
func NewShutdown(cid ChannelID, addr DeliveryAddress) *Shutdown {
3✔
49
        return &Shutdown{
3✔
50
                ChannelID: cid,
3✔
51
                Address:   addr,
3✔
52
        }
3✔
53
}
3✔
54

55
// A compile-time check to ensure Shutdown implements the lnwire.Message
56
// interface.
57
var _ Message = (*Shutdown)(nil)
58

59
// Decode deserializes a serialized Shutdown stored in the passed io.Reader
60
// observing the specified protocol version.
61
//
62
// This is part of the lnwire.Message interface.
63
func (s *Shutdown) Decode(r io.Reader, pver uint32) error {
3✔
64
        err := ReadElements(r, &s.ChannelID, &s.Address)
3✔
65
        if err != nil {
3✔
66
                return err
×
67
        }
×
68

69
        var tlvRecords ExtraOpaqueData
3✔
70
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
71
                return err
×
72
        }
×
73

74
        musigNonce := s.ShutdownNonce.Zero()
3✔
75
        typeMap, err := tlvRecords.ExtractRecords(&musigNonce)
3✔
76
        if err != nil {
3✔
77
                return err
×
78
        }
×
79

80
        // Set the corresponding TLV types if they were included in the stream.
81
        if val, ok := typeMap[s.ShutdownNonce.TlvType()]; ok && val == nil {
6✔
82
                s.ShutdownNonce = tlv.SomeRecordT(musigNonce)
3✔
83
        }
3✔
84

85
        if len(tlvRecords) != 0 {
6✔
86
                s.ExtraData = tlvRecords
3✔
87
        }
3✔
88

89
        return nil
3✔
90
}
91

92
// Encode serializes the target Shutdown into the passed io.Writer observing
93
// the protocol version specified.
94
//
95
// This is part of the lnwire.Message interface.
96
func (s *Shutdown) Encode(w *bytes.Buffer, pver uint32) error {
3✔
97
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
98
        s.ShutdownNonce.WhenSome(
3✔
99
                func(nonce tlv.RecordT[ShutdownNonceType, Musig2Nonce]) {
6✔
100
                        recordProducers = append(recordProducers, &nonce)
3✔
101
                },
3✔
102
        )
103
        err := EncodeMessageExtraData(&s.ExtraData, recordProducers...)
3✔
104
        if err != nil {
3✔
105
                return err
×
106
        }
×
107

108
        if err := WriteChannelID(w, s.ChannelID); err != nil {
3✔
109
                return err
×
110
        }
×
111

112
        if err := WriteDeliveryAddress(w, s.Address); err != nil {
3✔
113
                return err
×
114
        }
×
115

116
        return WriteBytes(w, s.ExtraData)
3✔
117
}
118

119
// MsgType returns the integer uniquely identifying this message type on the
120
// wire.
121
//
122
// This is part of the lnwire.Message interface.
123
func (s *Shutdown) MsgType() MessageType {
3✔
124
        return MsgShutdown
3✔
125
}
3✔
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