@@ -189,6 +189,18 @@ pub(crate) struct ConstructedTransaction {
189189 holder_sends_tx_signatures_first : bool ,
190190}
191191
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+
192204impl ConstructedTransaction {
193205 fn new ( context : NegotiationContext ) -> Self {
194206 let local_inputs_value_satoshis = context
@@ -309,25 +321,32 @@ impl ConstructedTransaction {
309321/// https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#sharing-funding-signatures-tx_signatures
310322#[ derive( Debug , Clone , PartialEq ) ]
311323pub ( crate ) struct InteractiveTxSigningSession {
312- pub unsigned_tx : ConstructedTransaction ,
324+ unsigned_tx : ConstructedTransaction ,
313325 holder_sends_tx_signatures_first : bool ,
314- received_commitment_signed : bool ,
326+ has_received_commitment_signed : bool ,
315327 holder_tx_signatures : Option < TxSignatures > ,
316- counterparty_sent_tx_signatures : bool ,
317328}
318329
319330impl 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
327345 }
328346
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 {
331350 self . holder_tx_signatures . clone ( )
332351 } else {
333352 None
@@ -352,7 +371,6 @@ impl InteractiveTxSigningSession {
352371 return Err ( ( ) ) ;
353372 }
354373 self . unsigned_tx . add_remote_witnesses ( tx_signatures. witnesses . clone ( ) ) ;
355- self . counterparty_sent_tx_signatures = true ;
356374
357375 let holder_tx_signatures = if !self . holder_sends_tx_signatures_first {
358376 self . holder_tx_signatures . clone ( )
@@ -433,6 +451,13 @@ impl InteractiveTxSigningSession {
433451 }
434452}
435453
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+
436461#[ derive( Debug ) ]
437462struct NegotiationContext {
438463 holder_node_id : PublicKey ,
@@ -1008,9 +1033,8 @@ macro_rules! define_state_transitions {
10081033 let signing_session = InteractiveTxSigningSession {
10091034 holder_sends_tx_signatures_first: tx. holder_sends_tx_signatures_first,
10101035 unsigned_tx: tx,
1011- received_commitment_signed : false ,
1036+ has_received_commitment_signed : false ,
10121037 holder_tx_signatures: None ,
1013- counterparty_sent_tx_signatures: false ,
10141038 } ;
10151039 Ok ( NegotiationComplete ( signing_session) )
10161040 }
@@ -1157,6 +1181,11 @@ enum AddingRole {
11571181 Remote ,
11581182}
11591183
1184+ impl_writeable_tlv_based_enum ! ( AddingRole ,
1185+ ( 1 , Local ) => { } ,
1186+ ( 3 , Remote ) => { } ,
1187+ ) ;
1188+
11601189/// Represents an input -- local or remote (both have the same fields)
11611190#[ derive( Clone , Debug , Eq , PartialEq ) ]
11621191pub struct LocalOrRemoteInput {
@@ -1165,19 +1194,35 @@ pub struct LocalOrRemoteInput {
11651194 prev_output : TxOut ,
11661195}
11671196
1197+ impl_writeable_tlv_based ! ( LocalOrRemoteInput , {
1198+ ( 1 , serial_id, required) ,
1199+ ( 3 , input, required) ,
1200+ ( 5 , prev_output, required) ,
1201+ } ) ;
1202+
11681203#[ derive( Clone , Debug , Eq , PartialEq ) ]
11691204pub ( crate ) enum InteractiveTxInput {
11701205 Local ( LocalOrRemoteInput ) ,
11711206 Remote ( LocalOrRemoteInput ) ,
11721207 // TODO(splicing) SharedInput should be added
11731208}
11741209
1210+ impl_writeable_tlv_based_enum ! ( InteractiveTxInput ,
1211+ { 1 , Local } => ( ) ,
1212+ { 3 , Remote } => ( ) ,
1213+ ) ;
1214+
11751215#[ derive( Clone , Debug , Eq , PartialEq ) ]
11761216pub ( super ) struct SharedOwnedOutput {
11771217 tx_out : TxOut ,
11781218 local_owned : u64 ,
11791219}
11801220
1221+ impl_writeable_tlv_based ! ( SharedOwnedOutput , {
1222+ ( 1 , tx_out, required) ,
1223+ ( 3 , local_owned, required) ,
1224+ } ) ;
1225+
11811226impl SharedOwnedOutput {
11821227 pub fn new ( tx_out : TxOut , local_owned : u64 ) -> SharedOwnedOutput {
11831228 debug_assert ! (
@@ -1205,6 +1250,11 @@ pub(super) enum OutputOwned {
12051250 Shared ( SharedOwnedOutput ) ,
12061251}
12071252
1253+ impl_writeable_tlv_based_enum ! ( OutputOwned ,
1254+ { 1 , Single } => ( ) ,
1255+ { 3 , Shared } => ( ) ,
1256+ ) ;
1257+
12081258impl OutputOwned {
12091259 pub fn tx_out ( & self ) -> & TxOut {
12101260 match self {
@@ -1259,6 +1309,12 @@ pub(crate) struct InteractiveTxOutput {
12591309 output : OutputOwned ,
12601310}
12611311
1312+ impl_writeable_tlv_based ! ( InteractiveTxOutput , {
1313+ ( 1 , serial_id, required) ,
1314+ ( 3 , added_by, required) ,
1315+ ( 5 , output, required) ,
1316+ } ) ;
1317+
12621318impl InteractiveTxOutput {
12631319 pub fn tx_out ( & self ) -> & TxOut {
12641320 self . output . tx_out ( )
0 commit comments