Skip to content

Commit ef50e1e

Browse files
committed
Add prev_ouput to NegotiatedTxInput for SIGHASH_ALL & key-spend checks
In a following commit, We'll use the contained scriptPubKeys to validate P2WPKH and P2TR key path spends and to assist in checking that signatures in provided holder witnesses use SIGHASH_ALL to prevent funds being frozen or held ransom.
1 parent 4658ef1 commit ef50e1e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,14 @@ pub(crate) struct NegotiatedTxInput {
210210
txin: TxIn,
211211
// The weight of the input including an estimate of its witness weight.
212212
weight: Weight,
213+
prev_output: TxOut,
213214
}
214215

215216
impl_writeable_tlv_based!(NegotiatedTxInput, {
216217
(1, serial_id, required),
217218
(3, txin, required),
218219
(5, weight, required),
220+
(7, prev_output, required),
219221
});
220222

221223
impl_writeable_tlv_based!(ConstructedTransaction, {
@@ -1362,6 +1364,20 @@ impl InputOwned {
13621364
InputOwned::Shared(shared) => estimate_input_weight(&shared.prev_output),
13631365
}
13641366
}
1367+
1368+
fn into_tx_in_with_prev_output(self) -> (TxIn, TxOut) {
1369+
match self {
1370+
InputOwned::Single(single) => (single.input, single.prev_output),
1371+
InputOwned::Shared(shared) => (shared.input, shared.prev_output),
1372+
}
1373+
}
1374+
1375+
fn prev_output(&self) -> &TxOut {
1376+
match self {
1377+
InputOwned::Single(single) => &single.prev_output,
1378+
InputOwned::Shared(shared) => &shared.prev_output,
1379+
}
1380+
}
13651381
}
13661382

13671383
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -1533,7 +1549,8 @@ impl InteractiveTxInput {
15331549

15341550
fn into_negotiated_input(self) -> NegotiatedTxInput {
15351551
let weight = self.input.estimate_input_weight();
1536-
NegotiatedTxInput { serial_id: self.serial_id, txin: self.input.into_tx_in(), weight }
1552+
let (txin, prev_output) = self.input.into_tx_in_with_prev_output();
1553+
NegotiatedTxInput { serial_id: self.serial_id, txin, weight, prev_output }
15371554
}
15381555
}
15391556

0 commit comments

Comments
 (0)