@@ -4316,9 +4316,9 @@ impl PersistenceNotifier {
4316
4316
const SERIALIZATION_VERSION : u8 = 1 ;
4317
4317
const MIN_SERIALIZATION_VERSION : u8 = 1 ;
4318
4318
4319
- impl Writeable for PendingHTLCInfo {
4319
+ impl Writeable for PendingHTLCRouting {
4320
4320
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
4321
- match & self . routing {
4321
+ match & self {
4322
4322
& PendingHTLCRouting :: Forward { ref onion_packet, ref short_channel_id } => {
4323
4323
0u8 . write ( writer) ?;
4324
4324
onion_packet. write ( writer) ?;
@@ -4331,39 +4331,37 @@ impl Writeable for PendingHTLCInfo {
4331
4331
incoming_cltv_expiry. write ( writer) ?;
4332
4332
} ,
4333
4333
}
4334
- self . incoming_shared_secret . write ( writer) ?;
4335
- self . payment_hash . write ( writer) ?;
4336
- self . amt_to_forward . write ( writer) ?;
4337
- self . outgoing_cltv_value . write ( writer) ?;
4338
4334
Ok ( ( ) )
4339
4335
}
4340
4336
}
4341
4337
4342
- impl Readable for PendingHTLCInfo {
4343
- fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < PendingHTLCInfo , DecodeError > {
4344
- Ok ( PendingHTLCInfo {
4345
- routing : match Readable :: read ( reader) ? {
4346
- 0u8 => PendingHTLCRouting :: Forward {
4347
- onion_packet : Readable :: read ( reader) ?,
4348
- short_channel_id : Readable :: read ( reader) ?,
4349
- } ,
4350
- 1u8 => PendingHTLCRouting :: Receive {
4351
- payment_data : msgs:: FinalOnionHopData {
4352
- payment_secret : Readable :: read ( reader) ?,
4353
- total_msat : Readable :: read ( reader) ?,
4354
- } ,
4355
- incoming_cltv_expiry : Readable :: read ( reader) ?,
4338
+ impl Readable for PendingHTLCRouting {
4339
+ fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < PendingHTLCRouting , DecodeError > {
4340
+ match Readable :: read ( reader) ? {
4341
+ 0u8 => Ok ( PendingHTLCRouting :: Forward {
4342
+ onion_packet : Readable :: read ( reader) ?,
4343
+ short_channel_id : Readable :: read ( reader) ?,
4344
+ } ) ,
4345
+ 1u8 => Ok ( PendingHTLCRouting :: Receive {
4346
+ payment_data : msgs:: FinalOnionHopData {
4347
+ payment_secret : Readable :: read ( reader) ?,
4348
+ total_msat : Readable :: read ( reader) ?,
4356
4349
} ,
4357
- _ => return Err ( DecodeError :: InvalidValue ) ,
4358
- } ,
4359
- incoming_shared_secret : Readable :: read ( reader) ?,
4360
- payment_hash : Readable :: read ( reader) ?,
4361
- amt_to_forward : Readable :: read ( reader) ?,
4362
- outgoing_cltv_value : Readable :: read ( reader) ?,
4363
- } )
4350
+ incoming_cltv_expiry : Readable :: read ( reader) ?,
4351
+ } ) ,
4352
+ _ => Err ( DecodeError :: InvalidValue ) ,
4353
+ }
4364
4354
}
4365
4355
}
4366
4356
4357
+ impl_writeable_tlv_based ! ( PendingHTLCInfo , {
4358
+ ( 0 , routing, PendingHTLCRouting :: Receive { payment_data: msgs:: FinalOnionHopData { payment_secret: PaymentSecret ( [ 0 ; 32 ] ) , total_msat: 0 } , incoming_cltv_expiry: 0 } ) ,
4359
+ ( 2 , incoming_shared_secret, [ 0 ; 32 ] ) ,
4360
+ ( 4 , payment_hash, PaymentHash ( [ 0 ; 32 ] ) ) ,
4361
+ ( 6 , amt_to_forward, 0 ) ,
4362
+ ( 8 , outgoing_cltv_value, 0 )
4363
+ } , { } , { } ) ;
4364
+
4367
4365
impl Writeable for HTLCFailureMsg {
4368
4366
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
4369
4367
match self {
@@ -4416,33 +4414,52 @@ impl Readable for PendingHTLCStatus {
4416
4414
}
4417
4415
}
4418
4416
4419
- impl_writeable ! ( HTLCPreviousHopData , 0 , {
4420
- short_channel_id,
4421
- outpoint,
4422
- htlc_id,
4423
- incoming_packet_shared_secret
4424
- } ) ;
4417
+ impl_writeable_tlv_based ! ( HTLCPreviousHopData , {
4418
+ ( 0 , short_channel_id, 0 ) ,
4419
+ ( 2 , outpoint, OutPoint :: null ( ) ) ,
4420
+ ( 4 , htlc_id, 0 ) ,
4421
+ ( 6 , incoming_packet_shared_secret, [ 0 ; 32 ] )
4422
+ } , { } , { } ) ;
4425
4423
4426
4424
impl Writeable for ClaimableHTLC {
4427
4425
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
4428
- self . prev_hop . write ( writer) ?;
4429
- self . value . write ( writer) ?;
4430
- self . payment_data . payment_secret . write ( writer) ?;
4431
- self . payment_data . total_msat . write ( writer) ?;
4432
- self . cltv_expiry . write ( writer)
4426
+ write_tlv_fields ! ( writer, {
4427
+ ( 0 , self . prev_hop) ,
4428
+ ( 2 , self . value) ,
4429
+ ( 4 , self . payment_data. payment_secret) ,
4430
+ ( 6 , self . payment_data. total_msat) ,
4431
+ ( 8 , self . cltv_expiry)
4432
+ } , { } ) ;
4433
+ Ok ( ( ) )
4433
4434
}
4434
4435
}
4435
4436
4436
4437
impl Readable for ClaimableHTLC {
4437
4438
fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
4439
+ let mut prev_hop = HTLCPreviousHopData {
4440
+ short_channel_id : 0 , htlc_id : 0 ,
4441
+ incoming_packet_shared_secret : [ 0 ; 32 ] ,
4442
+ outpoint : OutPoint :: null ( ) ,
4443
+ } ;
4444
+ let mut value = 0 ;
4445
+ let mut payment_secret = PaymentSecret ( [ 0 ; 32 ] ) ;
4446
+ let mut total_msat = 0 ;
4447
+ let mut cltv_expiry = 0 ;
4448
+ read_tlv_fields ! ( reader, {
4449
+ ( 0 , prev_hop) ,
4450
+ ( 2 , value) ,
4451
+ ( 4 , payment_secret) ,
4452
+ ( 6 , total_msat) ,
4453
+ ( 8 , cltv_expiry)
4454
+ } , { } ) ;
4438
4455
Ok ( ClaimableHTLC {
4439
- prev_hop : Readable :: read ( reader ) ? ,
4440
- value : Readable :: read ( reader ) ? ,
4456
+ prev_hop,
4457
+ value,
4441
4458
payment_data : msgs:: FinalOnionHopData {
4442
- payment_secret : Readable :: read ( reader ) ? ,
4443
- total_msat : Readable :: read ( reader ) ? ,
4459
+ payment_secret,
4460
+ total_msat,
4444
4461
} ,
4445
- cltv_expiry : Readable :: read ( reader ) ? ,
4462
+ cltv_expiry,
4446
4463
} )
4447
4464
}
4448
4465
}
0 commit comments