Skip to content

Commit fcc37a3

Browse files
committed
Store shared output index in ConstructedTransaction
Currently, only the shared input index is stored in ConstructedTransaction. This will be used later to filter out the shared input when constructing an error during interactive tx negotiation. Store the shared output index as well so that the shared output can be filtered out as well.
1 parent 11567d3 commit fcc37a3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ pub(crate) struct ConstructedTransaction {
200200
output_metadata: Vec<TxOutMetadata>,
201201
tx: Transaction,
202202
shared_input_index: Option<u32>,
203+
shared_output_index: Option<u32>,
203204
}
204205

205206
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -244,6 +245,7 @@ impl_writeable_tlv_based!(ConstructedTransaction, {
244245
(5, output_metadata, required),
245246
(7, tx, required),
246247
(9, shared_input_index, option),
248+
(11, shared_output_index, option),
247249
});
248250

249251
impl ConstructedTransaction {
@@ -280,12 +282,18 @@ impl ConstructedTransaction {
280282
.map(|position| position as u32)
281283
});
282284

285+
let shared_output_index = output
286+
.iter()
287+
.position(|txout| *txout == context.shared_funding_output.tx_out)
288+
.map(|position| position as u32);
289+
283290
let tx = ConstructedTransaction {
284291
holder_is_initiator: context.holder_is_initiator,
285292
input_metadata,
286293
output_metadata,
287294
tx: Transaction { version: Version::TWO, lock_time, input, output },
288295
shared_input_index,
296+
shared_output_index,
289297
};
290298

291299
// The receiving node:
@@ -315,7 +323,7 @@ impl ConstructedTransaction {
315323
return Err(AbortReason::MissingFundingInput);
316324
}
317325

318-
if !tx.tx.output.iter().any(|txout| *txout == context.shared_funding_output.tx_out) {
326+
if tx.shared_output_index.is_none() {
319327
return Err(AbortReason::MissingFundingOutput);
320328
}
321329

0 commit comments

Comments
 (0)