Skip to content

Commit 1d3fdf1

Browse files
committed
ran cargo +nightly fmt
1 parent 653a14d commit 1d3fdf1

5 files changed

Lines changed: 50 additions & 46 deletions

File tree

rustfmt.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md
2+
3+
# Stable configurations
4+
edition = "2024"
5+
max_width = 120
6+
merge_derives = true
7+
use_field_init_shorthand = true
8+
use_small_heuristics = "Max"
9+
use_try_shorthand = true
10+
imports_layout = "HorizontalVertical"
11+
imports_granularity = "Crate"
12+
overflow_delimited_expr = true
13+
14+
# Nightly configurations
15+
reorder_impl_items = true
16+
style_edition = "2024"

src/rest/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use axum::{
3535
response::Response,
3636
routing::{get, post},
3737
};
38-
use std::path::PathBuf;
3938
use axum_extra::response::ErasedJson;
39+
use std::path::PathBuf;
4040

4141
use parking_lot::Mutex;
4242
use std::{

src/restore.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,15 @@ impl Restore {
4343
let snapshot_path = snapshots_dir.join(&self.snapshot);
4444

4545
if !snapshot_path.exists() {
46-
return Err(anyhow!(
47-
"Snapshot '{}' not found at '{}'",
48-
self.snapshot,
49-
snapshot_path.display()
50-
));
46+
return Err(anyhow!("Snapshot '{}' not found at '{}'", self.snapshot, snapshot_path.display()));
5147
}
5248

5349
// Clear the current storage directory, preserving the directory itself.
5450
if self.storage.exists() {
5551
println!("Clearing storage directory: {}", self.storage.display());
5652
clear_dir(&self.storage)?;
5753
} else {
58-
std::fs::create_dir_all(&self.storage)
59-
.map_err(|e| anyhow!("Failed to create storage directory: {e}"))?;
54+
std::fs::create_dir_all(&self.storage).map_err(|e| anyhow!("Failed to create storage directory: {e}"))?;
6055
}
6156

6257
// Copy the snapshot into the storage directory.
@@ -65,12 +60,15 @@ impl Restore {
6560
println!("Restore complete.");
6661

6762
if self.restart {
68-
relaunch_as_start(&self.storage, self.private_key.as_deref(), &self.socket_addr, self.verbosity, self.manual_block_creation)?;
63+
relaunch_as_start(
64+
&self.storage,
65+
self.private_key.as_deref(),
66+
&self.socket_addr,
67+
self.verbosity,
68+
self.manual_block_creation,
69+
)?;
6970
} else {
70-
println!(
71-
"Restart the devnode with:\n aleo-devnode start --storage {}",
72-
self.storage.display()
73-
);
71+
println!("Restart the devnode with:\n aleo-devnode start --storage {}", self.storage.display());
7472
}
7573

7674
Ok(())
@@ -130,10 +128,7 @@ fn relaunch_as_start(
130128
/// Returns the snapshots directory that sits alongside the given storage directory.
131129
/// e.g. `devnode` → `devnode-snapshots`
132130
pub(crate) fn snapshots_sibling_dir(storage: &Path) -> PathBuf {
133-
let dir_name = format!(
134-
"{}-snapshots",
135-
storage.file_name().unwrap_or_default().to_string_lossy()
136-
);
131+
let dir_name = format!("{}-snapshots", storage.file_name().unwrap_or_default().to_string_lossy());
137132
let mut p = storage.to_path_buf();
138133
p.pop();
139134
p.join(dir_name)
@@ -144,11 +139,9 @@ fn clear_dir(dir: &Path) -> Result<()> {
144139
let entry = entry.map_err(|e| anyhow!("Failed to read entry: {e}"))?;
145140
let path = entry.path();
146141
if path.is_dir() {
147-
std::fs::remove_dir_all(&path)
148-
.map_err(|e| anyhow!("Failed to remove '{}': {e}", path.display()))?;
142+
std::fs::remove_dir_all(&path).map_err(|e| anyhow!("Failed to remove '{}': {e}", path.display()))?;
149143
} else {
150-
std::fs::remove_file(&path)
151-
.map_err(|e| anyhow!("Failed to remove '{}': {e}", path.display()))?;
144+
std::fs::remove_file(&path).map_err(|e| anyhow!("Failed to remove '{}': {e}", path.display()))?;
152145
}
153146
}
154147
Ok(())
@@ -163,8 +156,7 @@ fn copy_dir_all(src: &Path, dst: &Path) -> Result<()> {
163156
if src_path.is_dir() {
164157
copy_dir_all(&src_path, &dst_path)?;
165158
} else {
166-
std::fs::copy(&src_path, &dst_path)
167-
.map_err(|e| anyhow!("Failed to copy '{}': {e}", src_path.display()))?;
159+
std::fs::copy(&src_path, &dst_path).map_err(|e| anyhow!("Failed to copy '{}': {e}", src_path.display()))?;
168160
}
169161
}
170162
Ok(())

src/start.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::logger::initialize_terminal_logger;
18-
use crate::rest::Rest;
17+
use crate::{logger::initialize_terminal_logger, rest::Rest};
1918

2019
use anyhow::Result;
2120
use clap::Parser;
@@ -82,9 +81,10 @@ async fn start_devnode(command: Start, private_key: Option<String>) -> Result<()
8281
.map_err(|e| anyhow::anyhow!("Failed to parse listener address '{}': {}", command.socket_addr, e))?;
8382
// Load the genesis block.
8483
let genesis_block: Block<TestnetV0> = if command.genesis_path != "blank" {
85-
Block::from_bytes_le(&std::fs::read(&command.genesis_path).map_err(|e| {
86-
anyhow::anyhow!("Failed to read genesis block file '{}': {}", command.genesis_path, e)
87-
})?)?
84+
Block::from_bytes_le(
85+
&std::fs::read(&command.genesis_path)
86+
.map_err(|e| anyhow::anyhow!("Failed to read genesis block file '{}': {}", command.genesis_path, e))?,
87+
)?
8888
} else {
8989
// This genesis block is stored in $TMPDIR when running snarkos start --dev 0 --dev-num-validators N
9090
Block::from_bytes_le(include_bytes!(concat!(
@@ -95,19 +95,17 @@ async fn start_devnode(command: Start, private_key: Option<String>) -> Result<()
9595
match command.storage {
9696
Some(path) => {
9797
if command.clear_storage && path.exists() {
98-
for entry in std::fs::read_dir(&path)
99-
.map_err(|e| anyhow::anyhow!("Failed to read ledger directory: {e}"))?
98+
for entry in
99+
std::fs::read_dir(&path).map_err(|e| anyhow::anyhow!("Failed to read ledger directory: {e}"))?
100100
{
101101
let entry = entry.map_err(|e| anyhow::anyhow!("Failed to read entry: {e}"))?;
102102
let entry_path = entry.path();
103103
if entry_path.is_dir() {
104-
std::fs::remove_dir_all(&entry_path).map_err(|e| {
105-
anyhow::anyhow!("Failed to remove '{}': {e}", entry_path.display())
106-
})?;
104+
std::fs::remove_dir_all(&entry_path)
105+
.map_err(|e| anyhow::anyhow!("Failed to remove '{}': {e}", entry_path.display()))?;
107106
} else {
108-
std::fs::remove_file(&entry_path).map_err(|e| {
109-
anyhow::anyhow!("Failed to remove '{}': {e}", entry_path.display())
110-
})?;
107+
std::fs::remove_file(&entry_path)
108+
.map_err(|e| anyhow::anyhow!("Failed to remove '{}': {e}", entry_path.display()))?;
111109
}
112110
}
113111
println!("Cleaned ledger directory: {}", path.display());
@@ -173,10 +171,7 @@ async fn run_devnode<C: 'static + ConsensusStorage<TestnetV0>>(
173171

174172
fn resolve_private_key(private_key: &Option<String>) -> Result<PrivateKey<TestnetV0>> {
175173
match private_key {
176-
Some(pk) => {
177-
Ok(PrivateKey::<TestnetV0>::from_str(pk)
178-
.map_err(|e| anyhow::anyhow!("Invalid private key: {e}"))?)
179-
}
174+
Some(pk) => Ok(PrivateKey::<TestnetV0>::from_str(pk).map_err(|e| anyhow::anyhow!("Invalid private key: {e}"))?),
180175
None => {
181176
let pk = std::env::var("PRIVATE_KEY").map_err(|e| {
182177
anyhow::anyhow!(
@@ -187,8 +182,7 @@ Please either:
187182
2. Set the PRIVATE_KEY environment variable"
188183
)
189184
})?;
190-
Ok(PrivateKey::<TestnetV0>::from_str(&pk)
191-
.map_err(|e| anyhow::anyhow!("Invalid private key: {e}"))?)
185+
Ok(PrivateKey::<TestnetV0>::from_str(&pk).map_err(|e| anyhow::anyhow!("Invalid private key: {e}"))?)
192186
}
193187
}
194188
}

tests/integration.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
// Each test spawns the binary directly, mirroring the shell-based devnode tests
44
// in the leo repo (tests/tests/cli/test_devnode*, leo_devnode_missing_private_key).
55

6-
use std::path::Path;
7-
use std::process::{Child, Command, Stdio};
8-
use std::sync::atomic::{AtomicU16, Ordering};
9-
use std::time::{Duration, Instant};
6+
use std::{
7+
path::Path,
8+
process::{Child, Command, Stdio},
9+
sync::atomic::{AtomicU16, Ordering},
10+
time::{Duration, Instant},
11+
};
1012

1113
const PRIVATE_KEY: &str = "APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH";
1214
const DEVNODE_BIN: &str = env!("CARGO_BIN_EXE_aleo-devnode");

0 commit comments

Comments
 (0)