@@ -3,6 +3,8 @@ package lnwire
3
3
import (
4
4
"bytes"
5
5
"io"
6
+
7
+ "github.com/lightningnetwork/lnd/tlv"
6
8
)
7
9
8
10
// AnnounceSignatures2 is a direct message between two endpoints of a
@@ -14,27 +16,40 @@ type AnnounceSignatures2 struct {
14
16
// Channel id is better for users and debugging and short channel id is
15
17
// used for quick test on existence of the particular utxo inside the
16
18
// blockchain, because it contains information about block.
17
- ChannelID ChannelID
19
+ ChannelID tlv. RecordT [tlv. TlvType0 , ChannelID ]
18
20
19
21
// ShortChannelID is the unique description of the funding transaction.
20
22
// It is constructed with the most significant 3 bytes as the block
21
23
// height, the next 3 bytes indicating the transaction index within the
22
24
// block, and the least significant two bytes indicating the output
23
25
// index which pays to the channel.
24
- ShortChannelID ShortChannelID
26
+ ShortChannelID tlv. RecordT [tlv. TlvType2 , ShortChannelID ]
25
27
26
28
// PartialSignature is the combination of the partial Schnorr signature
27
29
// created for the node's bitcoin key with the partial signature created
28
30
// for the node's node ID key.
29
- PartialSignature PartialSig
30
-
31
- // ExtraOpaqueData is the set of data that was appended to this
32
- // message, some of which we may not actually know how to iterate or
33
- // parse. By holding onto this data, we ensure that we're able to
34
- // properly validate the set of signatures that cover these new fields,
35
- // and ensure we're able to make upgrades to the network in a forwards
36
- // compatible manner.
37
- ExtraOpaqueData ExtraOpaqueData
31
+ PartialSignature tlv.RecordT [tlv.TlvType4 , PartialSig ]
32
+
33
+ // Any extra fields in the signed range that we do not yet know about,
34
+ // but we need to keep them for signature validation and to produce a
35
+ // valid message.
36
+ ExtraFieldsInSignedRange map [uint64 ][]byte
37
+ }
38
+
39
+ // NewAnnSigs2 is a constructor for AnnounceSignatures2.
40
+ func NewAnnSigs2 (chanID ChannelID , scid ShortChannelID ,
41
+ partialSig PartialSig ) * AnnounceSignatures2 {
42
+
43
+ return & AnnounceSignatures2 {
44
+ ChannelID : tlv.NewRecordT [tlv.TlvType0 , ChannelID ](chanID ),
45
+ ShortChannelID : tlv.NewRecordT [tlv.TlvType2 , ShortChannelID ](
46
+ scid ,
47
+ ),
48
+ PartialSignature : tlv.NewRecordT [tlv.TlvType4 , PartialSig ](
49
+ partialSig ,
50
+ ),
51
+ ExtraFieldsInSignedRange : make (map [uint64 ][]byte , 0 ),
52
+ }
38
53
}
39
54
40
55
// A compile time check to ensure AnnounceSignatures2 implements the
@@ -46,32 +61,29 @@ var _ Message = (*AnnounceSignatures2)(nil)
46
61
//
47
62
// This is part of the lnwire.Message interface.
48
63
func (a * AnnounceSignatures2 ) Decode (r io.Reader , _ uint32 ) error {
49
- return ReadElements (r ,
50
- & a .ChannelID ,
51
- & a .ShortChannelID ,
52
- & a .PartialSignature ,
53
- & a .ExtraOpaqueData ,
54
- )
55
- }
56
-
57
- // Encode serializes the target AnnounceSignatures2 into the passed io.Writer
58
- // observing the protocol version specified.
59
- //
60
- // This is part of the lnwire.Message interface.
61
- func (a * AnnounceSignatures2 ) Encode (w * bytes.Buffer , _ uint32 ) error {
62
- if err := WriteChannelID (w , a .ChannelID ); err != nil {
64
+ stream , err := tlv .NewStream (ProduceRecordsSorted (
65
+ & a .ChannelID , & a .ShortChannelID , & a .PartialSignature ,
66
+ )... )
67
+ if err != nil {
63
68
return err
64
69
}
65
70
66
- if err := WriteShortChannelID (w , a .ShortChannelID ); err != nil {
71
+ typeMap , err := stream .DecodeWithParsedTypesP2P (r )
72
+ if err != nil {
67
73
return err
68
74
}
69
75
70
- if err := WriteElement (w , a .PartialSignature ); err != nil {
71
- return err
72
- }
76
+ a .ExtraFieldsInSignedRange = ExtraSignedFieldsFromTypeMap (typeMap )
77
+
78
+ return nil
79
+ }
73
80
74
- return WriteBytes (w , a .ExtraOpaqueData )
81
+ // Encode serializes the target AnnounceSignatures2 into the passed io.Writer
82
+ // observing the protocol version specified.
83
+ //
84
+ // This is part of the lnwire.Message interface.
85
+ func (a * AnnounceSignatures2 ) Encode (w * bytes.Buffer , _ uint32 ) error {
86
+ return EncodePureTLVMessage (a , w )
75
87
}
76
88
77
89
// MsgType returns the integer uniquely identifying this message type on the
@@ -82,16 +94,34 @@ func (a *AnnounceSignatures2) MsgType() MessageType {
82
94
return MsgAnnounceSignatures2
83
95
}
84
96
97
+ // AllRecords returns all the TLV records for the message. This will include all
98
+ // the records we know about along with any that we don't know about but that
99
+ // fall in the signed TLV range.
100
+ //
101
+ // NOTE: this is part of the PureTLVMessage interface.
102
+ func (a * AnnounceSignatures2 ) AllRecords () []tlv.Record {
103
+ recordProducers := []tlv.RecordProducer {
104
+ & a .ChannelID , & a .ShortChannelID ,
105
+ & a .PartialSignature ,
106
+ }
107
+
108
+ recordProducers = append (recordProducers , RecordsAsProducers (
109
+ tlv .MapToRecords (a .ExtraFieldsInSignedRange ),
110
+ )... )
111
+
112
+ return ProduceRecordsSorted (recordProducers ... )
113
+ }
114
+
85
115
// SCID returns the ShortChannelID of the channel.
86
116
//
87
117
// NOTE: this is part of the AnnounceSignatures interface.
88
118
func (a * AnnounceSignatures2 ) SCID () ShortChannelID {
89
- return a .ShortChannelID
119
+ return a .ShortChannelID . Val
90
120
}
91
121
92
122
// ChanID returns the ChannelID identifying the channel.
93
123
//
94
124
// NOTE: this is part of the AnnounceSignatures interface.
95
125
func (a * AnnounceSignatures2 ) ChanID () ChannelID {
96
- return a .ChannelID
126
+ return a .ChannelID . Val
97
127
}
0 commit comments