Skip to content

Commit c356070

Browse files
Fix rustfmt'd short Channel methods
In the previous commit we formatted a bunch of short methods. Here we clean up the default formatting that rustfmt applied by extracting code into variables.
1 parent 58337d7 commit c356070

File tree

1 file changed

+23
-36
lines changed

1 file changed

+23
-36
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,9 +1308,8 @@ impl HolderCommitmentPoint {
13081308
L::Target: Logger,
13091309
{
13101310
if let HolderCommitmentPoint::PendingNext { transaction_number, current } = self {
1311-
if let Ok(next) =
1312-
signer.as_ref().get_per_commitment_point(*transaction_number - 1, secp_ctx)
1313-
{
1311+
let next = signer.as_ref().get_per_commitment_point(*transaction_number - 1, secp_ctx);
1312+
if let Ok(next) = next {
13141313
log_trace!(
13151314
logger,
13161315
"Retrieved next per-commitment point {}",
@@ -2056,10 +2055,8 @@ impl FundingScope {
20562055
}
20572056

20582057
pub fn get_counterparty_selected_contest_delay(&self) -> Option<u16> {
2059-
self.channel_transaction_parameters
2060-
.counterparty_parameters
2061-
.as_ref()
2062-
.map(|params| params.selected_contest_delay)
2058+
let params_opt = self.channel_transaction_parameters.counterparty_parameters.as_ref();
2059+
params_opt.map(|params| params.selected_contest_delay)
20632060
}
20642061

20652062
fn get_counterparty_pubkeys(&self) -> &ChannelPublicKeys {
@@ -5496,9 +5493,10 @@ fn get_holder_max_htlc_value_in_flight_msat(
54965493
pub(crate) fn get_holder_selected_channel_reserve_satoshis(
54975494
channel_value_satoshis: u64, config: &UserConfig,
54985495
) -> u64 {
5499-
let calculated_reserve = channel_value_satoshis.saturating_mul(
5500-
config.channel_handshake_config.their_channel_reserve_proportional_millionths as u64,
5501-
) / 1_000_000;
5496+
let counterparty_chan_reserve_prop_mil =
5497+
config.channel_handshake_config.their_channel_reserve_proportional_millionths as u64;
5498+
let calculated_reserve =
5499+
channel_value_satoshis.saturating_mul(counterparty_chan_reserve_prop_mil) / 1_000_000;
55025500
cmp::min(channel_value_satoshis, cmp::max(calculated_reserve, MIN_THEIR_CHAN_RESERVE_SATOSHIS))
55035501
}
55045502

@@ -5736,6 +5734,12 @@ impl FailHTLCMessageName for msgs::UpdateFailMalformedHTLC {
57365734
}
57375735
}
57385736

5737+
type BestBlockUpdatedRes = (
5738+
Option<msgs::ChannelReady>,
5739+
Vec<(HTLCSource, PaymentHash)>,
5740+
Option<msgs::AnnouncementSignatures>,
5741+
);
5742+
57395743
impl<SP: Deref> FundedChannel<SP>
57405744
where
57415745
SP::Target: SignerProvider,
@@ -8943,14 +8947,7 @@ where
89438947
pub fn best_block_updated<NS: Deref, L: Deref>(
89448948
&mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash, node_signer: &NS,
89458949
user_config: &UserConfig, logger: &L,
8946-
) -> Result<
8947-
(
8948-
Option<msgs::ChannelReady>,
8949-
Vec<(HTLCSource, PaymentHash)>,
8950-
Option<msgs::AnnouncementSignatures>,
8951-
),
8952-
ClosureReason,
8953-
>
8950+
) -> Result<BestBlockUpdatedRes, ClosureReason>
89548951
where
89558952
NS::Target: NodeSigner,
89568953
L::Target: Logger,
@@ -12401,13 +12398,9 @@ mod tests {
1240112398

1240212399
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
1240312400
let secp_ctx = Secp256k1::signing_only();
12404-
let channel_monitor_claim_key = SecretKey::from_slice(
12405-
&<Vec<u8>>::from_hex(
12406-
"0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
12407-
)
12408-
.unwrap()[..],
12409-
)
12410-
.unwrap();
12401+
let hex = "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
12402+
let channel_monitor_claim_key =
12403+
SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap();
1241112404
let channel_monitor_claim_key_hash = WPubkeyHash::hash(
1241212405
&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize(),
1241312406
);
@@ -12419,13 +12412,9 @@ mod tests {
1241912412

1242012413
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
1242112414
let secp_ctx = Secp256k1::signing_only();
12422-
let channel_close_key = SecretKey::from_slice(
12423-
&<Vec<u8>>::from_hex(
12424-
"0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
12425-
)
12426-
.unwrap()[..],
12427-
)
12428-
.unwrap();
12415+
let hex = "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
12416+
let channel_close_key =
12417+
SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap();
1242912418
Ok(ShutdownScript::new_p2wpkh_from_pubkey(PublicKey::from_secret_key(
1243012419
&secp_ctx,
1243112420
&channel_close_key,
@@ -12438,10 +12427,8 @@ mod tests {
1243812427
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>, hex: &str,
1243912428
) -> PublicKey {
1244012429
assert!(cfg!(not(feature = "grind_signatures")));
12441-
PublicKey::from_secret_key(
12442-
&secp_ctx,
12443-
&SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap(),
12444-
)
12430+
let secret = SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap();
12431+
PublicKey::from_secret_key(&secp_ctx, &secret)
1244512432
}
1244612433

1244712434
#[test]

0 commit comments

Comments
 (0)