Skip to content

Commit 64befee

Browse files
committed
More wide rust formatting rules
1 parent 48ff998 commit 64befee

29 files changed

+412
-1097
lines changed

.rustfmt.toml

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
max_width = 80
1+
max_width = 100
2+
format_code_in_doc_comments = true
3+
fn_single_line = true
4+
format_macro_matchers = true
5+
format_strings = true
6+
merge_derives = false
7+
imports_granularity = "Module"
8+
overflow_delimited_expr = true
9+
group_imports = "StdExternalCrate"
10+
use_field_init_shorthand = true
11+
use_try_shorthand = true
212
wrap_comments = true
13+
comment_width = 100
14+
use_small_heuristics = "Max"
15+
unstable_features = true
316
license_template_path = "license_header.txt"
4-
format_code_in_doc_comments = true

build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ extern crate amplify;
1818
extern crate clap;
1919

2020
use clap::IntoApp;
21-
use clap_generate::{generate_to, generators::*};
21+
use clap_generate::generate_to;
22+
use clap_generate::generators::*;
2223

2324
pub mod opts {
2425
include!("src/opts.rs");

src/bin/lnp-cli.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ fn main() {
3636
debug!("MSG RPC socket {}", &config.msg_endpoint);
3737
debug!("CTL RPC socket {}", &config.ctl_endpoint);
3838

39-
let mut client = Client::with(config, opts.shared.chain)
40-
.expect("Error initializing client");
39+
let mut client = Client::with(config, opts.shared.chain).expect("Error initializing client");
4140

4241
trace!("Executing command: {:?}", opts.command);
43-
opts.command
44-
.exec(&mut client)
45-
.unwrap_or_else(|err| eprintln!("{}", err.err()));
42+
opts.command.exec(&mut client).unwrap_or_else(|err| eprintln!("{}", err.err()));
4643
}

src/bin/lnpd.rs

+17-57
Original file line numberDiff line numberDiff line change
@@ -71,69 +71,45 @@ fn main() -> Result<(), Error> {
7171
}
7272

7373
fn init(config: &Config) -> Result<(), Error> {
74+
use std::fs;
75+
use std::process::exit;
76+
use std::str::FromStr;
77+
7478
use bitcoin::secp256k1::Secp256k1;
7579
use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey};
76-
use bitcoin_hd::{
77-
SegmentIndexes, TerminalStep, TrackingAccount, UnhardenedIndex,
78-
};
80+
use bitcoin_hd::{SegmentIndexes, TerminalStep, TrackingAccount, UnhardenedIndex};
7981
use lnp_node::lnpd::funding_wallet::{FundingWallet, WalletData};
8082
use lnp_node::opts::{LNP_NODE_FUNDING_WALLET, LNP_NODE_MASTER_WALLET};
8183
use miniscript::descriptor::{Descriptor, Wpkh};
8284
use psbt::sign::MemorySigningAccount;
83-
use std::fs;
84-
use std::process::exit;
85-
use std::str::FromStr;
8685

8786
let secp = Secp256k1::new();
8887

8988
println!("\n{}", "Initializing node data".progress());
9089

9190
if !config.data_dir.exists() {
92-
println!(
93-
"Data directory '{}' ... {}",
94-
config.data_dir.display(),
95-
"creating".action()
96-
);
91+
println!("Data directory '{}' ... {}", config.data_dir.display(), "creating".action());
9792
fs::create_dir_all(&config.data_dir)?;
9893
} else {
99-
println!(
100-
"Data directory '{}' ... {}",
101-
config.data_dir.display(),
102-
"found".progress()
103-
);
94+
println!("Data directory '{}' ... {}", config.data_dir.display(), "found".progress());
10495
}
10596

10697
let mut wallet_path = config.data_dir.clone();
10798
wallet_path.push(LNP_NODE_MASTER_WALLET);
10899
let signing_account = if !wallet_path.exists() {
109-
println!(
110-
"Signing account '{}' ... {}",
111-
LNP_NODE_MASTER_WALLET,
112-
"creating".action()
113-
);
114-
let xpriv = rpassword::read_password_from_tty(Some(
115-
"Please enter your master xpriv: ",
116-
))?;
100+
println!("Signing account '{}' ... {}", LNP_NODE_MASTER_WALLET, "creating".action());
101+
let xpriv = rpassword::read_password_from_tty(Some("Please enter your master xpriv: "))?;
117102
let xpriv = ExtendedPrivKey::from_str(&xpriv)?;
118-
let derivation = DerivationPath::from_str("m/10046h")
119-
.expect("hardcoded derivation path");
103+
let derivation = DerivationPath::from_str("m/10046h").expect("hardcoded derivation path");
120104
let xpriv_account = xpriv.derive_priv(&secp, &derivation)?;
121105
let fingerprint = xpriv.identifier(&secp);
122-
let signing_account = MemorySigningAccount::with(
123-
&secp,
124-
fingerprint,
125-
derivation,
126-
xpriv_account,
127-
);
106+
let signing_account =
107+
MemorySigningAccount::with(&secp, fingerprint, derivation, xpriv_account);
128108
let file = fs::File::create(wallet_path)?;
129109
signing_account.write(file)?;
130110
signing_account
131111
} else {
132-
println!(
133-
"Signing account '{}' ... {}",
134-
LNP_NODE_MASTER_WALLET,
135-
"found".progress()
136-
);
112+
println!("Signing account '{}' ... {}", LNP_NODE_MASTER_WALLET, "found".progress());
137113
MemorySigningAccount::read(&secp, fs::File::open(wallet_path)?)?
138114
};
139115
println!(
@@ -149,11 +125,7 @@ fn init(config: &Config) -> Result<(), Error> {
149125
let mut wallet_path = config.data_dir.clone();
150126
wallet_path.push(LNP_NODE_FUNDING_WALLET);
151127
let funding_wallet = if !wallet_path.exists() {
152-
println!(
153-
"Funding wallet '{}' ... {}",
154-
LNP_NODE_FUNDING_WALLET,
155-
"creating".action()
156-
);
128+
println!("Funding wallet '{}' ... {}", LNP_NODE_FUNDING_WALLET, "creating".action());
157129
let account_path = &[10046_u16, 0, 2][..];
158130
let node_xpriv = signing_account.account_xpriv();
159131
let account_xpriv = node_xpriv.derive_priv(
@@ -179,24 +151,12 @@ fn init(config: &Config) -> Result<(), Error> {
179151
last_change_index: UnhardenedIndex::zero(),
180152
last_rgb_index: Default::default(),
181153
};
182-
FundingWallet::new(
183-
&config.chain,
184-
wallet_path,
185-
wallet_data,
186-
&config.electrum_url,
187-
)?
154+
FundingWallet::new(&config.chain, wallet_path, wallet_data, &config.electrum_url)?
188155
} else {
189-
println!(
190-
"Funding wallet '{}' ... {}",
191-
LNP_NODE_FUNDING_WALLET,
192-
"found".progress()
193-
);
156+
println!("Funding wallet '{}' ... {}", LNP_NODE_FUNDING_WALLET, "found".progress());
194157
FundingWallet::with(&config.chain, wallet_path, &config.electrum_url)?
195158
};
196-
println!(
197-
"Funding wallet: {}",
198-
funding_wallet.wallet_data().descriptor.promo()
199-
);
159+
println!("Funding wallet: {}", funding_wallet.wallet_data().descriptor.promo());
200160

201161
println!("{}", "Node initialization complete\n".ended());
202162

src/bin/peerd.rs

+24-52
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@
5959
//! The overall program logic thus is the following:
6060
//!
6161
//! In the process starting from `main()`:
62-
//! - Parse cli arguments into a config. There is no config file, since the
63-
//! daemon can be started only from another control process (`lnpd`) or by
64-
//! forking itself.
65-
//! - If `--listen` argument is present, start a listening version as described
66-
//! above and open TCP port in listening mode; wait for incoming connections
62+
//! - Parse cli arguments into a config. There is no config file, since the daemon can be started
63+
//! only from another control process (`lnpd`) or by forking itself.
64+
//! - If `--listen` argument is present, start a listening version as described above and open TCP
65+
//! port in listening mode; wait for incoming connections
6766
//! - If `--connect` argument is present, connect to the remote TCP peer
6867
//!
6968
//! In forked/spawned version:
@@ -73,8 +72,7 @@
7372
//! launched from the control process:
7473
//! - Split TCP socket and related transcoders into reading and writing parts
7574
//! - Create bridge ZMQ PAIR socket
76-
//! - Put both TCP socket reading ZMQ bridge write PAIR parts into a thread
77-
//! ("bridge")
75+
//! - Put both TCP socket reading ZMQ bridge write PAIR parts into a thread ("bridge")
7876
//! - Open control interface socket
7977
//! - Create run loop in the main thread for polling three ZMQ sockets:
8078
//! * control interface
@@ -93,21 +91,18 @@ extern crate log;
9391
#[macro_use]
9492
extern crate amplify;
9593

96-
use clap::Parser;
97-
use internet2::addr::InetSocketAddr;
98-
use nix::unistd::{fork, ForkResult};
9994
use std::convert::TryFrom;
100-
use std::net::TcpListener;
101-
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
95+
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener};
10296
use std::time::Duration;
10397

10498
use bitcoin::secp256k1::PublicKey;
105-
use internet2::{
106-
session, FramingProtocol, NodeAddr, RemoteNodeAddr, RemoteSocketAddr,
107-
};
99+
use clap::Parser;
100+
use internet2::addr::InetSocketAddr;
101+
use internet2::{session, FramingProtocol, NodeAddr, RemoteNodeAddr, RemoteSocketAddr};
108102
use lnp_node::peerd::{self, Opts};
109103
use lnp_node::{Config, LogStyle};
110104
use microservices::peer::PeerConnection;
105+
use nix::unistd::{fork, ForkResult};
111106

112107
/*
113108
mod internal {
@@ -142,21 +137,15 @@ impl From<Opts> for PeerSocket {
142137
Self::Connect(peer_addr)
143138
} else if let Some(bind_addr) = opts.listen {
144139
Self::Listen(match opts.overlay {
145-
FramingProtocol::FramedRaw => {
146-
RemoteSocketAddr::Ftcp(InetSocketAddr {
147-
address: bind_addr
148-
.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
149-
.into(),
150-
port: opts.port,
151-
})
152-
}
140+
FramingProtocol::FramedRaw => RemoteSocketAddr::Ftcp(InetSocketAddr {
141+
address: bind_addr.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)).into(),
142+
port: opts.port,
143+
}),
153144
// TODO: (v2) implement overlay protocols
154145
_ => unimplemented!(),
155146
})
156147
} else {
157-
unreachable!(
158-
"Either `connect` or `listen` must be present due to Clap configuration"
159-
)
148+
unreachable!("Either `connect` or `listen` must be present due to Clap configuration")
160149
}
161150
}
162151
}
@@ -207,29 +196,24 @@ fn main() {
207196

208197
debug!("Binding TCP socket {}", inet_addr);
209198
let listener = TcpListener::bind(
210-
SocketAddr::try_from(inet_addr)
211-
.expect("Tor is not yet supported"),
199+
SocketAddr::try_from(inet_addr).expect("Tor is not yet supported"),
212200
)
213201
.expect("Unable to bind to Lightning network peer socket");
214202

215203
debug!("Running TCP listener event loop");
216204
loop {
217205
debug!("Awaiting for incoming connections...");
218-
let (stream, remote_socket_addr) = listener
219-
.accept()
220-
.expect("Error accepting incpming peer connection");
206+
let (stream, remote_socket_addr) =
207+
listener.accept().expect("Error accepting incpming peer connection");
221208
debug!("New connection from {}", remote_socket_addr);
222209

223210
remote_socket = remote_socket_addr.into();
224211

225212
// TODO: Support multithread mode
226213
debug!("Forking child process");
227-
if let ForkResult::Child =
228-
unsafe { fork().expect("Unable to fork child process") }
214+
if let ForkResult::Child = unsafe { fork().expect("Unable to fork child process") }
229215
{
230-
trace!(
231-
"Child forked; returning into main listener event loop"
232-
);
216+
trace!("Child forked; returning into main listener event loop");
233217
continue;
234218
}
235219

@@ -238,11 +222,8 @@ fn main() {
238222
.expect("Unable to set up timeout for TCP connection");
239223

240224
debug!("Establishing session with the remote");
241-
let session =
242-
session::Raw::with_ftcp_unencrypted(stream, inet_addr)
243-
.expect(
244-
"Unable to establish session with the remote peer",
245-
);
225+
let session = session::Raw::with_ftcp_unencrypted(stream, inet_addr)
226+
.expect("Unable to establish session with the remote peer");
246227

247228
debug!("Session successfully established");
248229
break PeerConnection::with(session);
@@ -264,17 +245,8 @@ fn main() {
264245
};
265246

266247
debug!("Starting runtime ...");
267-
peerd::run(
268-
config,
269-
connection,
270-
id,
271-
local_id,
272-
remote_id,
273-
local_socket,
274-
remote_socket,
275-
connect,
276-
)
277-
.expect("Error running peerd runtime");
248+
peerd::run(config, connection, id, local_id, remote_id, local_socket, remote_socket, connect)
249+
.expect("Error running peerd runtime");
278250

279251
unreachable!()
280252
}

src/channeld/opts.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use internet2::PartialNodeAddr;
1818
use lnp::p2p::legacy::ChannelId;
1919

2020
use crate::opts::FUNGIBLED_RPC_ENDPOINT;
21-
2221
use crate::peerd::KeyOpts;
2322

2423
/// Lightning peer network channel daemon; part of LNP Node
@@ -71,8 +70,7 @@ impl Opts {
7170
impl RgbOpts {
7271
pub fn process(&mut self, shared: &crate::opts::Opts) {
7372
match &mut self.rgb20_socket {
74-
PartialNodeAddr::ZmqIpc(path, ..)
75-
| PartialNodeAddr::Posix(path) => {
73+
PartialNodeAddr::ZmqIpc(path, ..) | PartialNodeAddr::Posix(path) => {
7674
shared.process_dir(path);
7775
}
7876
_ => {}

0 commit comments

Comments
 (0)