@@ -199,8 +199,8 @@ pub struct OpenChannel {
199
199
pub first_per_commitment_point : PublicKey ,
200
200
/// The channel flags to be used
201
201
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 > ,
204
204
/// The channel type that this channel will represent
205
205
///
206
206
/// If this is `None`, we derive the channel type from the intersection of our
@@ -241,8 +241,8 @@ pub struct AcceptChannel {
241
241
pub htlc_basepoint : PublicKey ,
242
242
/// The first to-be-broadcast-by-sender transaction's per commitment point
243
243
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 > ,
246
246
/// The channel type that this channel will represent.
247
247
///
248
248
/// If this is `None`, we derive the channel type from the intersection of
@@ -946,20 +946,6 @@ pub struct CommitmentUpdate {
946
946
pub commitment_signed : CommitmentSigned ,
947
947
}
948
948
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
-
963
949
/// A trait to describe an object which can receive channel messages.
964
950
///
965
951
/// Messages MAY be called in parallel when they originate from different `their_node_ids`, however
@@ -1255,52 +1241,6 @@ impl From<io::Error> for DecodeError {
1255
1241
}
1256
1242
}
1257
1243
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
1244
#[ cfg( not( taproot) ) ]
1305
1245
impl_writeable_msg ! ( AcceptChannel , {
1306
1246
temporary_channel_id,
@@ -1317,8 +1257,8 @@ impl_writeable_msg!(AcceptChannel, {
1317
1257
delayed_payment_basepoint,
1318
1258
htlc_basepoint,
1319
1259
first_per_commitment_point,
1320
- shutdown_scriptpubkey
1321
1260
} , {
1261
+ ( 0 , shutdown_scriptpubkey, ( option, encoding: ( Script , WithoutLength ) ) ) , // Don't encode length twice.
1322
1262
( 1 , channel_type, option) ,
1323
1263
} ) ;
1324
1264
@@ -1338,8 +1278,8 @@ impl_writeable_msg!(AcceptChannel, {
1338
1278
delayed_payment_basepoint,
1339
1279
htlc_basepoint,
1340
1280
first_per_commitment_point,
1341
- shutdown_scriptpubkey
1342
1281
} , {
1282
+ ( 0 , shutdown_scriptpubkey, ( option, encoding: ( Script , WithoutLength ) ) ) , // Don't encode length twice.
1343
1283
( 1 , channel_type, option) ,
1344
1284
( 4 , next_local_nonce, option) ,
1345
1285
} ) ;
@@ -1477,8 +1417,8 @@ impl_writeable_msg!(OpenChannel, {
1477
1417
htlc_basepoint,
1478
1418
first_per_commitment_point,
1479
1419
channel_flags,
1480
- shutdown_scriptpubkey
1481
1420
} , {
1421
+ ( 0 , shutdown_scriptpubkey, ( option, encoding: ( Script , WithoutLength ) ) ) , // Don't encode length twice.
1482
1422
( 1 , channel_type, option) ,
1483
1423
} ) ;
1484
1424
@@ -2103,7 +2043,7 @@ mod tests {
2103
2043
use crate :: ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
2104
2044
use crate :: ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
2105
2045
use crate :: ln:: msgs;
2106
- use crate :: ln:: msgs:: { FinalOnionHopData , OptionalField , OnionErrorPacket , OnionHopDataFormat } ;
2046
+ use crate :: ln:: msgs:: { FinalOnionHopData , OnionErrorPacket , OnionHopDataFormat } ;
2107
2047
use crate :: routing:: gossip:: { NodeAlias , NodeId } ;
2108
2048
use crate :: util:: ser:: { Writeable , Readable , Hostname } ;
2109
2049
@@ -2422,7 +2362,7 @@ mod tests {
2422
2362
htlc_basepoint : pubkey_5,
2423
2363
first_per_commitment_point : pubkey_6,
2424
2364
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 } ,
2365
+ shutdown_scriptpubkey : if shutdown { Some ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { None } ,
2426
2366
channel_type : if incl_chan_type { Some ( ChannelTypeFeatures :: empty ( ) ) } else { None } ,
2427
2367
} ;
2428
2368
let encoded_value = open_channel. encode ( ) ;
@@ -2478,7 +2418,7 @@ mod tests {
2478
2418
delayed_payment_basepoint : pubkey_4,
2479
2419
htlc_basepoint : pubkey_5,
2480
2420
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 } ,
2421
+ shutdown_scriptpubkey : if shutdown { Some ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , inner : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { None } ,
2482
2422
channel_type : None ,
2483
2423
#[ cfg( taproot) ]
2484
2424
next_local_nonce : None ,
0 commit comments