@@ -189,6 +189,18 @@ pub(crate) struct ConstructedTransaction {
189
189
holder_sends_tx_signatures_first : bool ,
190
190
}
191
191
192
+ impl_writeable_tlv_based ! ( ConstructedTransaction , {
193
+ ( 1 , holder_is_initiator, required) ,
194
+ ( 3 , inputs, required) ,
195
+ ( 5 , outputs, required) ,
196
+ ( 7 , local_inputs_value_satoshis, required) ,
197
+ ( 9 , local_outputs_value_satoshis, required) ,
198
+ ( 11 , remote_inputs_value_satoshis, required) ,
199
+ ( 13 , remote_outputs_value_satoshis, required) ,
200
+ ( 15 , lock_time, required) ,
201
+ ( 17 , holder_sends_tx_signatures_first, required) ,
202
+ } ) ;
203
+
192
204
impl ConstructedTransaction {
193
205
fn new ( context : NegotiationContext ) -> Self {
194
206
let local_inputs_value_satoshis = context
@@ -309,25 +321,32 @@ impl ConstructedTransaction {
309
321
/// https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#sharing-funding-signatures-tx_signatures
310
322
#[ derive( Debug , Clone , PartialEq ) ]
311
323
pub ( crate ) struct InteractiveTxSigningSession {
312
- pub unsigned_tx : ConstructedTransaction ,
324
+ unsigned_tx : ConstructedTransaction ,
313
325
holder_sends_tx_signatures_first : bool ,
314
- received_commitment_signed : bool ,
326
+ has_received_commitment_signed : bool ,
315
327
holder_tx_signatures : Option < TxSignatures > ,
316
- counterparty_sent_tx_signatures : bool ,
317
328
}
318
329
319
330
impl InteractiveTxSigningSession {
320
- pub fn received_commitment_signed ( & mut self ) -> Option < TxSignatures > {
321
- self . received_commitment_signed = true ;
322
- if self . holder_sends_tx_signatures_first {
323
- self . holder_tx_signatures . clone ( )
324
- } else {
325
- None
326
- }
331
+ pub fn unsigned_tx ( & self ) -> & ConstructedTransaction {
332
+ & self . unsigned_tx
333
+ }
334
+
335
+ pub fn holder_sends_tx_signatures_first ( & self ) -> bool {
336
+ self . holder_sends_tx_signatures_first
337
+ }
338
+
339
+ pub fn has_received_commitment_signed ( & self ) -> bool {
340
+ self . has_received_commitment_signed
341
+ }
342
+
343
+ pub fn holder_tx_signatures ( & self ) -> & Option < TxSignatures > {
344
+ & self . holder_tx_signatures
327
345
}
328
346
329
- pub fn get_tx_signatures ( & self ) -> Option < TxSignatures > {
330
- if self . received_commitment_signed {
347
+ pub fn received_commitment_signed ( & mut self ) -> Option < TxSignatures > {
348
+ self . has_received_commitment_signed = true ;
349
+ if self . holder_sends_tx_signatures_first {
331
350
self . holder_tx_signatures . clone ( )
332
351
} else {
333
352
None
@@ -352,7 +371,6 @@ impl InteractiveTxSigningSession {
352
371
return Err ( ( ) ) ;
353
372
}
354
373
self . unsigned_tx . add_remote_witnesses ( tx_signatures. witnesses . clone ( ) ) ;
355
- self . counterparty_sent_tx_signatures = true ;
356
374
357
375
let holder_tx_signatures = if !self . holder_sends_tx_signatures_first {
358
376
self . holder_tx_signatures . clone ( )
@@ -433,6 +451,13 @@ impl InteractiveTxSigningSession {
433
451
}
434
452
}
435
453
454
+ impl_writeable_tlv_based ! ( InteractiveTxSigningSession , {
455
+ ( 1 , unsigned_tx, required) ,
456
+ ( 3 , holder_sends_tx_signatures_first, required) ,
457
+ ( 5 , has_received_commitment_signed, required) ,
458
+ ( 7 , holder_tx_signatures, required) ,
459
+ } ) ;
460
+
436
461
#[ derive( Debug ) ]
437
462
struct NegotiationContext {
438
463
holder_node_id : PublicKey ,
@@ -1008,9 +1033,8 @@ macro_rules! define_state_transitions {
1008
1033
let signing_session = InteractiveTxSigningSession {
1009
1034
holder_sends_tx_signatures_first: tx. holder_sends_tx_signatures_first,
1010
1035
unsigned_tx: tx,
1011
- received_commitment_signed : false ,
1036
+ has_received_commitment_signed : false ,
1012
1037
holder_tx_signatures: None ,
1013
- counterparty_sent_tx_signatures: false ,
1014
1038
} ;
1015
1039
Ok ( NegotiationComplete ( signing_session) )
1016
1040
}
@@ -1157,6 +1181,11 @@ enum AddingRole {
1157
1181
Remote ,
1158
1182
}
1159
1183
1184
+ impl_writeable_tlv_based_enum ! ( AddingRole ,
1185
+ ( 1 , Local ) => { } ,
1186
+ ( 3 , Remote ) => { } ,
1187
+ ) ;
1188
+
1160
1189
/// Represents an input -- local or remote (both have the same fields)
1161
1190
#[ derive( Clone , Debug , Eq , PartialEq ) ]
1162
1191
pub struct LocalOrRemoteInput {
@@ -1165,19 +1194,35 @@ pub struct LocalOrRemoteInput {
1165
1194
prev_output : TxOut ,
1166
1195
}
1167
1196
1197
+ impl_writeable_tlv_based ! ( LocalOrRemoteInput , {
1198
+ ( 1 , serial_id, required) ,
1199
+ ( 3 , input, required) ,
1200
+ ( 5 , prev_output, required) ,
1201
+ } ) ;
1202
+
1168
1203
#[ derive( Clone , Debug , Eq , PartialEq ) ]
1169
1204
pub ( crate ) enum InteractiveTxInput {
1170
1205
Local ( LocalOrRemoteInput ) ,
1171
1206
Remote ( LocalOrRemoteInput ) ,
1172
1207
// TODO(splicing) SharedInput should be added
1173
1208
}
1174
1209
1210
+ impl_writeable_tlv_based_enum ! ( InteractiveTxInput ,
1211
+ { 1 , Local } => ( ) ,
1212
+ { 3 , Remote } => ( ) ,
1213
+ ) ;
1214
+
1175
1215
#[ derive( Clone , Debug , Eq , PartialEq ) ]
1176
1216
pub ( super ) struct SharedOwnedOutput {
1177
1217
tx_out : TxOut ,
1178
1218
local_owned : u64 ,
1179
1219
}
1180
1220
1221
+ impl_writeable_tlv_based ! ( SharedOwnedOutput , {
1222
+ ( 1 , tx_out, required) ,
1223
+ ( 3 , local_owned, required) ,
1224
+ } ) ;
1225
+
1181
1226
impl SharedOwnedOutput {
1182
1227
pub fn new ( tx_out : TxOut , local_owned : u64 ) -> SharedOwnedOutput {
1183
1228
debug_assert ! (
@@ -1205,6 +1250,11 @@ pub(super) enum OutputOwned {
1205
1250
Shared ( SharedOwnedOutput ) ,
1206
1251
}
1207
1252
1253
+ impl_writeable_tlv_based_enum ! ( OutputOwned ,
1254
+ { 1 , Single } => ( ) ,
1255
+ { 3 , Shared } => ( ) ,
1256
+ ) ;
1257
+
1208
1258
impl OutputOwned {
1209
1259
pub fn tx_out ( & self ) -> & TxOut {
1210
1260
match self {
@@ -1259,6 +1309,12 @@ pub(crate) struct InteractiveTxOutput {
1259
1309
output : OutputOwned ,
1260
1310
}
1261
1311
1312
+ impl_writeable_tlv_based ! ( InteractiveTxOutput , {
1313
+ ( 1 , serial_id, required) ,
1314
+ ( 3 , added_by, required) ,
1315
+ ( 5 , output, required) ,
1316
+ } ) ;
1317
+
1262
1318
impl InteractiveTxOutput {
1263
1319
pub fn tx_out ( & self ) -> & TxOut {
1264
1320
self . output . tx_out ( )
0 commit comments