Skip to content

Commit 7378e06

Browse files
authored
Merge pull request #3614 from TheBlueMatt/2025-02-rustfmt-wire-types
2 parents c9a7bfe + 136cac6 commit 7378e06

File tree

4 files changed

+177
-199
lines changed

4 files changed

+177
-199
lines changed

lightning-types/src/features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
//! - `DnsResolver` - supports resolving DNS names to TXT DNSSEC proofs for BIP 353 payments
7474
//! (see [bLIP 32](https://github.com/lightning/blips/blob/master/blip-0032.md) for more information).
7575
//! - `ProvideStorage` - Indicates that we offer the capability to store data of our peers
76-
//! (see https://github.com/lightning/bolts/pull/1110 for more info).
76+
//! (see [BOLT PR #1110](https://github.com/lightning/bolts/pull/1110) for more info).
7777
//! - `Quiescence` - protocol to quiesce a channel by indicating that "SomeThing Fundamental is Underway"
7878
//! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#channel-quiescence) for more information).
7979
//!

lightning/src/ln/types.rs

+33-31
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@
99

1010
//! Various wrapper types (most around 32-byte arrays) for use in lightning.
1111
12+
use super::channel_keys::RevocationBasepoint;
13+
1214
use crate::chain::transaction::OutPoint;
1315
use crate::io;
1416
use crate::ln::msgs::DecodeError;
1517
use crate::sign::EntropySource;
1618
use crate::util::ser::{Readable, Writeable, Writer};
17-
use super::channel_keys::RevocationBasepoint;
1819

1920
#[allow(unused_imports)]
2021
use crate::prelude::*;
2122

22-
use bitcoin::hashes::{
23-
Hash as _,
24-
HashEngine as _,
25-
sha256::Hash as Sha256,
26-
};
23+
use bitcoin::hashes::{sha256::Hash as Sha256, Hash as _, HashEngine as _};
2724
use bitcoin::hex::display::impl_fmt_traits;
25+
2826
use core::borrow::Borrow;
2927
use core::ops::Deref;
3028

@@ -56,7 +54,9 @@ impl ChannelId {
5654

5755
/// Create a _temporary_ channel ID randomly, based on an entropy source.
5856
pub fn temporary_from_entropy_source<ES: Deref>(entropy_source: &ES) -> Self
59-
where ES::Target: EntropySource {
57+
where
58+
ES::Target: EntropySource,
59+
{
6060
Self(entropy_source.get_secure_random_bytes())
6161
}
6262

@@ -80,16 +80,11 @@ impl ChannelId {
8080
/// revocation basepoint and hashing the result. The basepoints will be concatenated in increasing
8181
/// sorted order.
8282
pub fn v2_from_revocation_basepoints(
83-
ours: &RevocationBasepoint,
84-
theirs: &RevocationBasepoint,
83+
ours: &RevocationBasepoint, theirs: &RevocationBasepoint,
8584
) -> Self {
8685
let ours = ours.0.serialize();
8786
let theirs = theirs.0.serialize();
88-
let (lesser, greater) = if ours < theirs {
89-
(ours, theirs)
90-
} else {
91-
(theirs, ours)
92-
};
87+
let (lesser, greater) = if ours < theirs { (ours, theirs) } else { (theirs, ours) };
9388
let mut engine = Sha256::engine();
9489
engine.input(&lesser[..]);
9590
engine.input(&greater[..]);
@@ -98,8 +93,11 @@ impl ChannelId {
9893

9994
/// Create temporary _v2_ channel ID by concatenating a zeroed out basepoint with the holder
10095
/// revocation basepoint and hashing the result.
101-
pub fn temporary_v2_from_revocation_basepoint(our_revocation_basepoint: &RevocationBasepoint) -> Self {
102-
Self(Sha256::hash(&[[0u8; 33], our_revocation_basepoint.0.serialize()].concat()).to_byte_array())
96+
pub fn temporary_v2_from_revocation_basepoint(
97+
our_revocation_basepoint: &RevocationBasepoint,
98+
) -> Self {
99+
let our_revocation_point_bytes = our_revocation_basepoint.0.serialize();
100+
Self(Sha256::hash(&[[0u8; 33], our_revocation_point_bytes].concat()).to_byte_array())
103101
}
104102
}
105103

@@ -130,26 +128,25 @@ impl_fmt_traits! {
130128

131129
#[cfg(test)]
132130
mod tests {
133-
use bitcoin::hashes::{
134-
Hash as _,
135-
HashEngine as _,
136-
hex::FromHex as _,
137-
sha256::Hash as Sha256,
138-
};
139-
use bitcoin::secp256k1::PublicKey;
131+
use bitcoin::hashes::{sha256::Hash as Sha256, Hash as _, HashEngine as _};
140132
use bitcoin::hex::DisplayHex;
133+
use bitcoin::secp256k1::PublicKey;
141134

142135
use super::ChannelId;
136+
137+
use crate::io;
143138
use crate::ln::channel_keys::RevocationBasepoint;
139+
use crate::prelude::*;
144140
use crate::util::ser::{Readable, Writeable};
145141
use crate::util::test_utils;
146-
use crate::prelude::*;
147-
use crate::io;
142+
143+
use core::str::FromStr;
148144

149145
#[test]
150146
fn test_channel_id_v1_from_funding_txid() {
151147
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
152-
assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203");
148+
let expected = "0202020202020202020202020202020202020202020202020202020202020203";
149+
assert_eq!(channel_id.0.as_hex().to_string(), expected);
153150
}
154151

155152
#[test]
@@ -184,14 +181,17 @@ mod tests {
184181
#[test]
185182
fn test_channel_id_display() {
186183
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
187-
assert_eq!(format!("{}", &channel_id), "0202020202020202020202020202020202020202020202020202020202020203");
184+
let expected = "0202020202020202020202020202020202020202020202020202020202020203";
185+
assert_eq!(format!("{}", &channel_id), expected);
188186
}
189187

190188
#[test]
191189
fn test_channel_id_v2_from_basepoints() {
192190
// Ours greater than theirs
193-
let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap());
194-
let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
191+
let our_pk = "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c";
192+
let ours = RevocationBasepoint(PublicKey::from_str(&our_pk).unwrap());
193+
let their_pk = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619";
194+
let theirs = RevocationBasepoint(PublicKey::from_str(&their_pk).unwrap());
195195

196196
let mut engine = Sha256::engine();
197197
engine.input(&theirs.0.serialize());
@@ -201,8 +201,10 @@ mod tests {
201201
assert_eq!(ChannelId::v2_from_revocation_basepoints(&ours, &theirs), expected_id);
202202

203203
// Theirs greater than ours
204-
let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap());
205-
let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
204+
let our_pk = "027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007";
205+
let ours = RevocationBasepoint(PublicKey::from_str(&our_pk).unwrap());
206+
let their_pk = "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619";
207+
let theirs = RevocationBasepoint(PublicKey::from_str(&their_pk).unwrap());
206208

207209
let mut engine = Sha256::engine();
208210
engine.input(&ours.0.serialize());

0 commit comments

Comments
 (0)