@@ -3,6 +3,8 @@ package lnwire
33import  (
44	"bytes" 
55	"io" 
6+ 
7+ 	"github.com/lightningnetwork/lnd/tlv" 
68)
79
810// AnnounceSignatures2 is a direct message between two endpoints of a 
@@ -14,27 +16,40 @@ type AnnounceSignatures2 struct {
1416	// Channel id is better for users and debugging and short channel id is 
1517	// used for quick test on existence of the particular utxo inside the 
1618	// blockchain, because it contains information about block. 
17- 	ChannelID  ChannelID 
19+ 	ChannelID  tlv. RecordT [tlv. TlvType0 ,  ChannelID ] 
1820
1921	// ShortChannelID is the unique description of the funding transaction. 
2022	// It is constructed with the most significant 3 bytes as the block 
2123	// height, the next 3 bytes indicating the transaction index within the 
2224	// block, and the least significant two bytes indicating the output 
2325	// index which pays to the channel. 
24- 	ShortChannelID  ShortChannelID 
26+ 	ShortChannelID  tlv. RecordT [tlv. TlvType2 ,  ShortChannelID ] 
2527
2628	// PartialSignature is the combination of the partial Schnorr signature 
2729	// created for the node's bitcoin key with the partial signature created 
2830	// 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+ 	ExtraSignedFields 
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+ 		ExtraSignedFields : make (ExtraSignedFields ),
52+ 	}
3853}
3954
4055// A compile time check to ensure AnnounceSignatures2 implements the 
@@ -45,37 +60,38 @@ var _ Message = (*AnnounceSignatures2)(nil)
4560// lnwire.SizeableMessage interface. 
4661var  _  SizeableMessage  =  (* AnnounceSignatures2 )(nil )
4762
63+ // A compile time check to ensure ChannelAnnouncement2 implements the 
64+ // lnwire.PureTLVMessage interface. 
65+ var  _  PureTLVMessage  =  (* AnnounceSignatures2 )(nil )
66+ 
4867// Decode deserializes a serialized AnnounceSignatures2 stored in the passed 
4968// io.Reader observing the specified protocol version. 
5069// 
5170// This is part of the lnwire.Message interface. 
5271func  (a  * AnnounceSignatures2 ) Decode (r  io.Reader , _  uint32 ) error  {
53- 	return  ReadElements (r ,
54- 		& a .ChannelID ,
55- 		& a .ShortChannelID ,
56- 		& a .PartialSignature ,
57- 		& a .ExtraOpaqueData ,
58- 	)
59- }
60- 
61- // Encode serializes the target AnnounceSignatures2 into the passed io.Writer 
62- // observing the protocol version specified. 
63- // 
64- // This is part of the lnwire.Message interface. 
65- func  (a  * AnnounceSignatures2 ) Encode (w  * bytes.Buffer , _  uint32 ) error  {
66- 	if  err  :=  WriteChannelID (w , a .ChannelID ); err  !=  nil  {
72+ 	stream , err  :=  tlv .NewStream (ProduceRecordsSorted (
73+ 		& a .ChannelID , & a .ShortChannelID , & a .PartialSignature ,
74+ 	)... )
75+ 	if  err  !=  nil  {
6776		return  err 
6877	}
6978
70- 	if  err  :=  WriteShortChannelID (w , a .ShortChannelID ); err  !=  nil  {
79+ 	typeMap , err  :=  stream .DecodeWithParsedTypesP2P (r )
80+ 	if  err  !=  nil  {
7181		return  err 
7282	}
7383
74- 	if  err  :=  WriteElement (w , a .PartialSignature ); err  !=  nil  {
75- 		return  err 
76- 	}
84+ 	a .ExtraSignedFields  =  ExtraSignedFieldsFromTypeMap (typeMap )
85+ 
86+ 	return  nil 
87+ }
7788
78- 	return  WriteBytes (w , a .ExtraOpaqueData )
89+ // Encode serializes the target AnnounceSignatures2 into the passed io.Writer 
90+ // observing the protocol version specified. 
91+ // 
92+ // This is part of the lnwire.Message interface. 
93+ func  (a  * AnnounceSignatures2 ) Encode (w  * bytes.Buffer , _  uint32 ) error  {
94+ 	return  EncodePureTLVMessage (a , w )
7995}
8096
8197// MsgType returns the integer uniquely identifying this message type on the 
@@ -93,16 +109,34 @@ func (a *AnnounceSignatures2) SerializedSize() (uint32, error) {
93109	return  MessageSerializedSize (a )
94110}
95111
112+ // AllRecords returns all the TLV records for the message. This will include all 
113+ // the records we know about along with any that we don't know about but that 
114+ // fall in the signed TLV range. 
115+ // 
116+ // NOTE: this is part of the PureTLVMessage interface. 
117+ func  (a  * AnnounceSignatures2 ) AllRecords () []tlv.Record  {
118+ 	recordProducers  :=  []tlv.RecordProducer {
119+ 		& a .ChannelID , & a .ShortChannelID ,
120+ 		& a .PartialSignature ,
121+ 	}
122+ 
123+ 	recordProducers  =  append (recordProducers , RecordsAsProducers (
124+ 		tlv .MapToRecords (a .ExtraSignedFields ),
125+ 	)... )
126+ 
127+ 	return  ProduceRecordsSorted (recordProducers ... )
128+ }
129+ 
96130// SCID returns the ShortChannelID of the channel. 
97131// 
98132// NOTE: this is part of the AnnounceSignatures interface. 
99133func  (a  * AnnounceSignatures2 ) SCID () ShortChannelID  {
100- 	return  a .ShortChannelID 
134+ 	return  a .ShortChannelID . Val 
101135}
102136
103137// ChanID returns the ChannelID identifying the channel. 
104138// 
105139// NOTE: this is part of the AnnounceSignatures interface. 
106140func  (a  * AnnounceSignatures2 ) ChanID () ChannelID  {
107- 	return  a .ChannelID 
141+ 	return  a .ChannelID . Val 
108142}
0 commit comments