Skip to content

Commit 85185d8

Browse files
authored
Merge pull request #3724 from tnull/2025-04-rustfmt-misc
`rustfmt`: Run on some smaller files in `lightning/ln`
2 parents ef0fcab + 8df643d commit 85185d8

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

lightning/src/ln/features.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99

1010
//! Implementations of extensions on features.
1111
12-
use lightning_types::features::{InitFeatures, NodeFeatures, ChannelFeatures};
13-
use lightning_types::features::{Bolt11InvoiceFeatures, OfferFeatures, InvoiceRequestFeatures};
14-
use lightning_types::features::{Bolt12InvoiceFeatures, BlindedHopFeatures};
1512
use lightning_types::features::ChannelTypeFeatures;
13+
use lightning_types::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
14+
use lightning_types::features::{Bolt11InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures};
15+
use lightning_types::features::{ChannelFeatures, InitFeatures, NodeFeatures};
1616

1717
#[allow(unused_imports)]
1818
use crate::prelude::*;
1919

20-
use crate::{io, io_extras};
2120
use crate::ln::msgs::DecodeError;
22-
use crate::util::ser::{Writer, Readable, Writeable, WithoutLength};
21+
use crate::util::ser::{Readable, WithoutLength, Writeable, Writer};
22+
use crate::{io, io_extras};
2323

2424
fn write_be<W: Writer>(w: &mut W, le_flags: &[u8]) -> Result<(), io::Error> {
25-
for f in le_flags.iter().rev() { // Swap back to big-endian
25+
// Swap back to big-endian
26+
for f in le_flags.iter().rev() {
2627
f.write(w)?;
2728
}
2829
Ok(())
@@ -42,7 +43,7 @@ macro_rules! impl_feature_len_prefixed_write {
4243
Ok(Self::from_be_bytes(Vec::<u8>::read(r)?))
4344
}
4445
}
45-
}
46+
};
4647
}
4748
impl_feature_len_prefixed_write!(InitFeatures);
4849
impl_feature_len_prefixed_write!(ChannelFeatures);
@@ -64,7 +65,7 @@ macro_rules! impl_feature_tlv_write {
6465
Ok(WithoutLength::<Self>::read(r)?.0)
6566
}
6667
}
67-
}
68+
};
6869
}
6970

7071
impl_feature_tlv_write!(ChannelTypeFeatures);
@@ -86,7 +87,7 @@ macro_rules! impl_feature_write_without_length {
8687
Ok(WithoutLength($features::from_be_bytes(v)))
8788
}
8889
}
89-
}
90+
};
9091
}
9192

9293
impl_feature_write_without_length!(Bolt12InvoiceFeatures);

lightning/src/ln/script.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//! Abstractions for scripts used in the Lightning Network.
22
3-
use bitcoin::{WitnessProgram, WPubkeyHash, WScriptHash};
3+
use bitcoin::hashes::Hash;
44
use bitcoin::opcodes::all::OP_PUSHBYTES_0 as SEGWIT_V0;
55
use bitcoin::script::{Script, ScriptBuf};
6-
use bitcoin::hashes::Hash;
76
use bitcoin::secp256k1::PublicKey;
7+
use bitcoin::{WPubkeyHash, WScriptHash, WitnessProgram};
88

99
use crate::ln::channelmanager;
10-
use crate::types::features::InitFeatures;
1110
use crate::ln::msgs::DecodeError;
11+
use crate::types::features::InitFeatures;
12+
use crate::util::config::UserConfig;
1213
use crate::util::ser::{Readable, Writeable, Writer};
1314

1415
use crate::io;
@@ -28,7 +29,7 @@ pub struct InvalidShutdownScript {
2829
/// The script that did not meet the requirements from [BOLT #2].
2930
///
3031
/// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
31-
pub script: ScriptBuf
32+
pub script: ScriptBuf,
3233
}
3334

3435
#[derive(Clone, PartialEq, Eq)]
@@ -82,7 +83,9 @@ impl ShutdownScript {
8283
/// # Errors
8384
///
8485
/// This function may return an error if `program` is invalid for the segwit `version`.
85-
pub fn new_witness_program(witness_program: &WitnessProgram) -> Result<Self, InvalidShutdownScript> {
86+
pub fn new_witness_program(
87+
witness_program: &WitnessProgram,
88+
) -> Result<Self, InvalidShutdownScript> {
8689
Self::try_from(ScriptBuf::new_witness_program(witness_program))
8790
}
8891

@@ -128,7 +131,8 @@ impl TryFrom<ScriptBuf> for ShutdownScript {
128131
type Error = InvalidShutdownScript;
129132

130133
fn try_from(script: ScriptBuf) -> Result<Self, Self::Error> {
131-
Self::try_from((script, &channelmanager::provided_init_features(&crate::util::config::UserConfig::default())))
134+
let features = channelmanager::provided_init_features(&UserConfig::default());
135+
Self::try_from((script, &features))
132136
}
133137
}
134138

@@ -149,14 +153,15 @@ impl TryFrom<(ScriptBuf, &InitFeatures)> for ShutdownScript {
149153
impl Into<ScriptBuf> for ShutdownScript {
150154
fn into(self) -> ScriptBuf {
151155
match self.0 {
152-
ShutdownScriptImpl::Legacy(pubkey) =>
153-
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&pubkey.serialize())),
156+
ShutdownScriptImpl::Legacy(pubkey) => {
157+
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&pubkey.serialize()))
158+
},
154159
ShutdownScriptImpl::Bolt2(script_pubkey) => script_pubkey,
155160
}
156161
}
157162
}
158163

159-
impl core::fmt::Display for ShutdownScript{
164+
impl core::fmt::Display for ShutdownScript {
160165
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
161166
match &self.0 {
162167
ShutdownScriptImpl::Legacy(_) => self.clone().into_inner().fmt(f),
@@ -169,18 +174,22 @@ impl core::fmt::Display for ShutdownScript{
169174
mod shutdown_script_tests {
170175
use super::ShutdownScript;
171176

172-
use bitcoin::{WitnessProgram, WitnessVersion};
173177
use bitcoin::opcodes;
174178
use bitcoin::script::{Builder, ScriptBuf};
175179
use bitcoin::secp256k1::Secp256k1;
176180
use bitcoin::secp256k1::{PublicKey, SecretKey};
181+
use bitcoin::{WitnessProgram, WitnessVersion};
177182

178-
use crate::types::features::InitFeatures;
179183
use crate::prelude::*;
184+
use crate::types::features::InitFeatures;
180185

181186
fn pubkey() -> bitcoin::key::PublicKey {
182187
let secp_ctx = Secp256k1::signing_only();
183-
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]).unwrap();
188+
let secret_key = SecretKey::from_slice(&[
189+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
190+
0, 0, 1,
191+
])
192+
.unwrap();
184193
bitcoin::key::PublicKey::new(PublicKey::from_secret_key(&secp_ctx, &secret_key))
185194
}
186195

rustfmt_excluded_files

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ lightning/src/ln/blinded_payment_tests.rs
1313
lightning/src/ln/chan_utils.rs
1414
lightning/src/ln/chanmon_update_fail_tests.rs
1515
lightning/src/ln/channel.rs
16-
lightning/src/ln/channel_id.rs
1716
lightning/src/ln/channelmanager.rs
18-
lightning/src/ln/features.rs
1917
lightning/src/ln/functional_test_utils.rs
2018
lightning/src/ln/functional_tests.rs
2119
lightning/src/ln/inbound_payment.rs
@@ -34,7 +32,6 @@ lightning/src/ln/peer_handler.rs
3432
lightning/src/ln/priv_short_conf_tests.rs
3533
lightning/src/ln/reload_tests.rs
3634
lightning/src/ln/reorg_tests.rs
37-
lightning/src/ln/script.rs
3835
lightning/src/ln/shutdown_tests.rs
3936
lightning/src/routing/mod.rs
4037
lightning/src/routing/router.rs

0 commit comments

Comments
 (0)