@@ -199,8 +199,8 @@ pub struct OpenChannel {
199199 pub first_per_commitment_point : PublicKey ,
200200 /// The channel flags to be used
201201 pub channel_flags : u8 ,
202- /// Optionally, a request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close
203- pub shutdown_scriptpubkey : OptionalField < Script > ,
202+ /// A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close
203+ pub shutdown_scriptpubkey : Option < Script > ,
204204 /// The channel type that this channel will represent
205205 ///
206206 /// If this is `None`, we derive the channel type from the intersection of our
@@ -241,8 +241,8 @@ pub struct AcceptChannel {
241241 pub htlc_basepoint : PublicKey ,
242242 /// The first to-be-broadcast-by-sender transaction's per commitment point
243243 pub first_per_commitment_point : PublicKey ,
244- /// Optionally, a request to pre-set the to-sender output's scriptPubkey for when we collaboratively close
245- pub shutdown_scriptpubkey : OptionalField < Script > ,
244+ /// A request to pre-set the to-sender output's scriptPubkey for when we collaboratively close
245+ pub shutdown_scriptpubkey : Option < Script > ,
246246 /// The channel type that this channel will represent.
247247 ///
248248 /// If this is `None`, we derive the channel type from the intersection of
@@ -946,20 +946,6 @@ pub struct CommitmentUpdate {
946946 pub commitment_signed : CommitmentSigned ,
947947}
948948
949- /// Messages could have optional fields to use with extended features
950- /// As we wish to serialize these differently from `Option<T>`s (`Options` get a tag byte, but
951- /// [`OptionalField`] simply gets `Present` if there are enough bytes to read into it), we have a
952- /// separate enum type for them.
953- ///
954- /// This is not exported to bindings users due to a free generic in `T`
955- #[ derive( Clone , Debug , PartialEq , Eq ) ]
956- pub enum OptionalField < T > {
957- /// Optional field is included in message
958- Present ( T ) ,
959- /// Optional field is absent in message
960- Absent
961- }
962-
963949/// A trait to describe an object which can receive channel messages.
964950///
965951/// Messages MAY be called in parallel when they originate from different `their_node_ids`, however
@@ -1255,53 +1241,6 @@ impl From<io::Error> for DecodeError {
12551241 }
12561242}
12571243
1258- impl Writeable for OptionalField < Script > {
1259- fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
1260- match * self {
1261- OptionalField :: Present ( ref script) => {
1262- // Note that Writeable for script includes the 16-bit length tag for us
1263- script. write ( w) ?;
1264- } ,
1265- OptionalField :: Absent => { }
1266- }
1267- Ok ( ( ) )
1268- }
1269- }
1270-
1271- impl Readable for OptionalField < Script > {
1272- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
1273- match <u16 as Readable >:: read ( r) {
1274- Ok ( len) => {
1275- let mut buf = vec ! [ 0 ; len as usize ] ;
1276- r. read_exact ( & mut buf) ?;
1277- Ok ( OptionalField :: Present ( Script :: from ( buf) ) )
1278- } ,
1279- Err ( DecodeError :: ShortRead ) => Ok ( OptionalField :: Absent ) ,
1280- Err ( e) => Err ( e)
1281- }
1282- }
1283- }
1284-
1285- impl Writeable for OptionalField < u64 > {
1286- fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
1287- match * self {
1288- OptionalField :: Present ( ref value) => {
1289- value. write ( w) ?;
1290- } ,
1291- OptionalField :: Absent => { }
1292- }
1293- Ok ( ( ) )
1294- }
1295- }
1296-
1297- impl Readable for OptionalField < u64 > {
1298- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
1299- let value: u64 = Readable :: read ( r) ?;
1300- Ok ( OptionalField :: Present ( value) )
1301- }
1302- }
1303-
1304- #[ cfg( not( taproot) ) ]
13051244impl_writeable_msg ! ( AcceptChannel , {
13061245 temporary_channel_id,
13071246 dust_limit_satoshis,
@@ -1317,8 +1256,8 @@ impl_writeable_msg!(AcceptChannel, {
13171256 delayed_payment_basepoint,
13181257 htlc_basepoint,
13191258 first_per_commitment_point,
1320- shutdown_scriptpubkey
13211259} , {
1260+ ( 0 , shutdown_scriptpubkey, option_without_length) ,
13221261 ( 1 , channel_type, option) ,
13231262} ) ;
13241263
@@ -1338,8 +1277,8 @@ impl_writeable_msg!(AcceptChannel, {
13381277 delayed_payment_basepoint,
13391278 htlc_basepoint,
13401279 first_per_commitment_point,
1341- shutdown_scriptpubkey
13421280} , {
1281+ ( 0 , shutdown_scriptpubkey, option_without_length) ,
13431282 ( 1 , channel_type, option) ,
13441283 ( 4 , next_local_nonce, option) ,
13451284} ) ;
@@ -1477,8 +1416,8 @@ impl_writeable_msg!(OpenChannel, {
14771416 htlc_basepoint,
14781417 first_per_commitment_point,
14791418 channel_flags,
1480- shutdown_scriptpubkey
14811419} , {
1420+ ( 0 , shutdown_scriptpubkey, option_without_length) , // We don't want to encode length twice.
14821421 ( 1 , channel_type, option) ,
14831422} ) ;
14841423
@@ -2103,7 +2042,7 @@ mod tests {
21032042 use crate :: ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
21042043 use crate :: ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
21052044 use crate :: ln:: msgs;
2106- use crate :: ln:: msgs:: { FinalOnionHopData , OptionalField , OnionErrorPacket , OnionHopDataFormat } ;
2045+ use crate :: ln:: msgs:: { FinalOnionHopData , OnionErrorPacket , OnionHopDataFormat } ;
21072046 use crate :: routing:: gossip:: { NodeAlias , NodeId } ;
21082047 use crate :: util:: ser:: { Writeable , Readable , Hostname } ;
21092048
@@ -2422,7 +2361,7 @@ mod tests {
24222361 htlc_basepoint : pubkey_5,
24232362 first_per_commitment_point : pubkey_6,
24242363 channel_flags : if random_bit { 1 << 5 } else { 0 } ,
2425- shutdown_scriptpubkey : if shutdown { OptionalField :: Present ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { OptionalField :: Absent } ,
2364+ shutdown_scriptpubkey : if shutdown { Some ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { None } ,
24262365 channel_type : if incl_chan_type { Some ( ChannelTypeFeatures :: empty ( ) ) } else { None } ,
24272366 } ;
24282367 let encoded_value = open_channel. encode ( ) ;
@@ -2478,7 +2417,7 @@ mod tests {
24782417 delayed_payment_basepoint : pubkey_4,
24792418 htlc_basepoint : pubkey_5,
24802419 first_per_commitment_point : pubkey_6,
2481- shutdown_scriptpubkey : if shutdown { OptionalField :: Present ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { OptionalField :: Absent } ,
2420+ shutdown_scriptpubkey : if shutdown { Some ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { None } ,
24822421 channel_type : None ,
24832422 #[ cfg( taproot) ]
24842423 next_local_nonce : None ,
0 commit comments