Skip to content

Commit 1b96fd1

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 2e3aa68 commit 1b96fd1

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,
@@ -8946,14 +8950,7 @@ where
89468950
pub fn best_block_updated<NS: Deref, L: Deref>(
89478951
&mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash, node_signer: &NS,
89488952
user_config: &UserConfig, logger: &L,
8949-
) -> Result<
8950-
(
8951-
Option<msgs::ChannelReady>,
8952-
Vec<(HTLCSource, PaymentHash)>,
8953-
Option<msgs::AnnouncementSignatures>,
8954-
),
8955-
ClosureReason,
8956-
>
8953+
) -> Result<BestBlockUpdatedRes, ClosureReason>
89578954
where
89588955
NS::Target: NodeSigner,
89598956
L::Target: Logger,
@@ -12404,13 +12401,9 @@ mod tests {
1240412401

1240512402
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
1240612403
let secp_ctx = Secp256k1::signing_only();
12407-
let channel_monitor_claim_key = SecretKey::from_slice(
12408-
&<Vec<u8>>::from_hex(
12409-
"0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
12410-
)
12411-
.unwrap()[..],
12412-
)
12413-
.unwrap();
12404+
let hex = "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
12405+
let channel_monitor_claim_key =
12406+
SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap();
1241412407
let channel_monitor_claim_key_hash = WPubkeyHash::hash(
1241512408
&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize(),
1241612409
);
@@ -12422,13 +12415,9 @@ mod tests {
1242212415

1242312416
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
1242412417
let secp_ctx = Secp256k1::signing_only();
12425-
let channel_close_key = SecretKey::from_slice(
12426-
&<Vec<u8>>::from_hex(
12427-
"0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
12428-
)
12429-
.unwrap()[..],
12430-
)
12431-
.unwrap();
12418+
let hex = "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
12419+
let channel_close_key =
12420+
SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap();
1243212421
Ok(ShutdownScript::new_p2wpkh_from_pubkey(PublicKey::from_secret_key(
1243312422
&secp_ctx,
1243412423
&channel_close_key,
@@ -12441,10 +12430,8 @@ mod tests {
1244112430
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>, hex: &str,
1244212431
) -> PublicKey {
1244312432
assert!(cfg!(not(feature = "grind_signatures")));
12444-
PublicKey::from_secret_key(
12445-
&secp_ctx,
12446-
&SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap(),
12447-
)
12433+
let secret = SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap();
12434+
PublicKey::from_secret_key(&secp_ctx, &secret)
1244812435
}
1244912436

1245012437
#[test]

0 commit comments

Comments
 (0)