Skip to content

Commit c7e91d3

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 f7e05f6 commit c7e91d3

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, {
@@ -1358,6 +1360,20 @@ impl InputOwned {
13581360
InputOwned::Shared(shared) => estimate_input_weight(&shared.prev_output),
13591361
}
13601362
}
1363+
1364+
fn into_tx_in_with_prev_output(self) -> (TxIn, TxOut) {
1365+
match self {
1366+
InputOwned::Single(single) => (single.input, single.prev_output),
1367+
InputOwned::Shared(shared) => (shared.input, shared.prev_output),
1368+
}
1369+
}
1370+
1371+
fn prev_output(&self) -> &TxOut {
1372+
match self {
1373+
InputOwned::Single(single) => &single.prev_output,
1374+
InputOwned::Shared(shared) => &shared.prev_output,
1375+
}
1376+
}
13611377
}
13621378

13631379
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -1529,7 +1545,8 @@ impl InteractiveTxInput {
15291545

15301546
fn into_negotiated_input(self) -> NegotiatedTxInput {
15311547
let weight = self.input.estimate_input_weight();
1532-
NegotiatedTxInput { serial_id: self.serial_id, txin: self.input.into_tx_in(), weight }
1548+
let (txin, prev_output) = self.input.into_tx_in_with_prev_output();
1549+
NegotiatedTxInput { serial_id: self.serial_id, txin, weight, prev_output }
15331550
}
15341551
}
15351552

0 commit comments

Comments
 (0)