Skip to content

Commit 531a8d9

Browse files
committed
f - clean-up and rustfmt
1 parent 7798325 commit 531a8d9

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

lightning/src/events/bump_transaction/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -876,15 +876,15 @@ where
876876
// add witness_utxo to anchor input
877877
anchor_psbt.inputs[0].witness_utxo = Some(anchor_descriptor.previous_utxo());
878878
// add witness_utxo to remaining inputs
879-
for (idx, ConfirmedUtxo { utxo, .. }) in coin_selection.confirmed_utxos.into_iter().enumerate() {
879+
for (idx, utxo) in coin_selection.confirmed_utxos.into_iter().enumerate() {
880880
// add 1 to skip the anchor input
881881
let index = idx + 1;
882882
debug_assert_eq!(
883883
anchor_psbt.unsigned_tx.input[index].previous_output,
884-
utxo.outpoint
884+
utxo.outpoint()
885885
);
886-
if utxo.output.script_pubkey.is_witness_program() {
887-
anchor_psbt.inputs[index].witness_utxo = Some(utxo.output);
886+
if utxo.output().script_pubkey.is_witness_program() {
887+
anchor_psbt.inputs[index].witness_utxo = Some(utxo.into_output());
888888
}
889889
}
890890

@@ -1138,12 +1138,15 @@ where
11381138
}
11391139

11401140
// add witness_utxo to remaining inputs
1141-
for (idx, ConfirmedUtxo { utxo, .. }) in coin_selection.confirmed_utxos.into_iter().enumerate() {
1141+
for (idx, utxo) in coin_selection.confirmed_utxos.into_iter().enumerate() {
11421142
// offset to skip the htlc inputs
11431143
let index = idx + selected_htlcs.len();
1144-
debug_assert_eq!(htlc_psbt.unsigned_tx.input[index].previous_output, utxo.outpoint);
1145-
if utxo.output.script_pubkey.is_witness_program() {
1146-
htlc_psbt.inputs[index].witness_utxo = Some(utxo.output);
1144+
debug_assert_eq!(
1145+
htlc_psbt.unsigned_tx.input[index].previous_output,
1146+
utxo.outpoint()
1147+
);
1148+
if utxo.output().script_pubkey.is_witness_program() {
1149+
htlc_psbt.inputs[index].witness_utxo = Some(utxo.into_output());
11471150
}
11481151
}
11491152

@@ -1353,10 +1356,7 @@ mod tests {
13531356
version: Version::TWO,
13541357
lock_time: LockTime::ZERO,
13551358
input: vec![],
1356-
output: vec![TxOut {
1357-
value: Amount::from_sat(200),
1358-
script_pubkey: ScriptBuf::new()
1359-
}],
1359+
output: vec![TxOut { value: Amount::from_sat(200), script_pubkey: ScriptBuf::new() }],
13601360
};
13611361

13621362
let broadcaster = TestBroadcaster::new(Network::Testnet);

lightning/src/ln/funding.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ impl FundingTxInput {
226226
self.utxo.outpoint
227227
}
228228

229+
/// The unspent output.
230+
pub fn output(&self) -> &TxOut {
231+
&self.utxo.output
232+
}
233+
229234
/// The sequence number to use in the [`TxIn`].
230235
///
231236
/// [`TxIn`]: bitcoin::TxIn
@@ -240,8 +245,13 @@ impl FundingTxInput {
240245
self.utxo.sequence = sequence;
241246
}
242247

243-
/// Converts the [`FundingTxInput`] into a [`Utxo`] for coin selection.
248+
/// Converts the [`FundingTxInput`] into a [`Utxo`].
244249
pub fn into_utxo(self) -> Utxo {
245250
self.utxo
246251
}
252+
253+
/// Converts the [`FundingTxInput`] into a [`TxOut`].
254+
pub fn into_output(self) -> TxOut {
255+
self.utxo.output
256+
}
247257
}

lightning/src/util/test_utils.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,13 +2237,13 @@ impl TestWalletSource {
22372237
) -> Result<Transaction, bitcoin::sighash::P2wpkhError> {
22382238
let utxos = self.utxos.lock().unwrap();
22392239
for i in 0..tx.input.len() {
2240-
if let Some(ConfirmedUtxo { utxo, .. }) =
2240+
if let Some(utxo) =
22412241
utxos.iter().find(|utxo| utxo.outpoint() == tx.input[i].previous_output)
22422242
{
22432243
let sighash = SighashCache::new(&tx).p2wpkh_signature_hash(
22442244
i,
2245-
&utxo.output.script_pubkey,
2246-
utxo.output.value,
2245+
&utxo.output().script_pubkey,
2246+
utxo.output().value,
22472247
EcdsaSighashType::All,
22482248
)?;
22492249
#[cfg(not(feature = "grind_signatures"))]
@@ -2268,7 +2268,13 @@ impl TestWalletSource {
22682268

22692269
impl WalletSourceSync for TestWalletSource {
22702270
fn list_confirmed_utxos(&self) -> Result<Vec<Utxo>, ()> {
2271-
Ok(self.utxos.lock().unwrap().iter().map(|ConfirmedUtxo { utxo, .. }| utxo.clone()).collect())
2271+
Ok(self
2272+
.utxos
2273+
.lock()
2274+
.unwrap()
2275+
.iter()
2276+
.map(|ConfirmedUtxo { utxo, .. }| utxo.clone())
2277+
.collect())
22722278
}
22732279

22742280
fn get_prevtx(&self, utxo: &Utxo) -> Result<Transaction, ()> {

0 commit comments

Comments
 (0)