Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit ba5d876

Browse files
authored
updates workflow and adds custom formatting for rustfmt (#84)
* updates workflow and adds custom formatting for rustfmt
1 parent c8089cb commit ba5d876

File tree

9 files changed

+119
-102
lines changed

9 files changed

+119
-102
lines changed

.github/workflows/ci-tests.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "ci tests"
22

3+
34
on:
45
push:
56
branches:
@@ -10,7 +11,13 @@ on:
1011
paths-ignore:
1112
- '**.md'
1213
workflow_dispatch:
13-
14+
inputs:
15+
test-macos-and-windows:
16+
description: 'run macOS and Windows tests'
17+
required: true
18+
default: false
19+
type: boolean
20+
1421
env:
1522
# Not needed in CI, should make things a bit faster
1623
CARGO_INCREMENTAL: 0
@@ -25,6 +32,13 @@ jobs:
2532
- ubuntu-22.04
2633
- macos-12
2734
- windows-2022
35+
run-all:
36+
- ${{ inputs.test-macos-and-windows == true || github.ref == 'refs/heads/main' }}
37+
exclude: # exclude macos-12 and windows-2022 when the condition is false
38+
- run-all: false
39+
os: macos-12
40+
- run-all: false
41+
os: windows-2022
2842

2943
runs-on: ${{ matrix.os }}
3044
steps:

rustfmt.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
edition = "2021"
2+
format_code_in_doc_comments = true
3+
format_macro_bodies = true
4+
format_macro_matchers = true
5+
format_strings = true
6+
imports_granularity = "Module"
7+
match_arm_blocks = false
8+
reorder_impl_items = true
9+
group_imports = "StdExternalCrate"
10+
use_field_init_shorthand = true
11+
use_small_heuristics = "Max"
12+
wrap_comments = true

src/commands/farm.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use futures::prelude::*;
66
use indicatif::{ProgressBar, ProgressStyle};
77
use single_instance::SingleInstance;
88
use subspace_sdk::node::SyncStatus;
9-
use tracing::instrument;
10-
119
use subspace_sdk::{chain_spec, Farmer, Node, PlotDescription};
10+
use tracing::instrument;
1211

1312
use crate::config::{validate_config, ChainConfig, Config};
1413
use crate::summary::Summary;
@@ -23,7 +22,8 @@ pub(crate) const SINGLE_INSTANCE: &str = ".subspaceFarmer";
2322
///
2423
/// first, checks for an existing farmer instance
2524
/// then starts the farming and node instances,
26-
/// lastly, depending on the verbosity, it subscribes to plotting progress and new solutions
25+
/// lastly, depending on the verbosity, it subscribes to plotting progress and
26+
/// new solutions
2727
#[instrument]
2828
pub(crate) async fn farm(is_verbose: bool) -> Result<(Farmer, Node, SingleInstance)> {
2929
install_tracing(is_verbose);
@@ -41,16 +41,11 @@ pub(crate) async fn farm(is_verbose: bool) -> Result<(Farmer, Node, SingleInstan
4141
raise_fd_limit();
4242

4343
println!("Starting node ... (this might take up to couple of minutes)");
44-
let Config {
45-
chain,
46-
farmer: farmer_config,
47-
node: node_config,
48-
} = validate_config()?;
44+
let Config { chain, farmer: farmer_config, node: node_config } = validate_config()?;
4945

5046
let chain = match chain {
51-
ChainConfig::Gemini3a => {
52-
chain_spec::gemini_3a().expect("cannot extract the gemini3a chain spec from SDK")
53-
}
47+
ChainConfig::Gemini3a =>
48+
chain_spec::gemini_3a().expect("cannot extract the gemini3a chain spec from SDK"),
5449
};
5550

5651
let node = node_config
@@ -98,9 +93,7 @@ pub(crate) async fn farm(is_verbose: bool) -> Result<(Farmer, Node, SingleInstan
9893

9994
syncing_progress_bar.finish_with_message("Syncing is done!");
10095
} else {
101-
node.sync()
102-
.await
103-
.map_err(|err| eyre!("Node syncing failed: {err}"))?;
96+
node.sync().await.map_err(|err| eyre!("Node syncing failed: {err}"))?;
10497
}
10598

10699
let summary = Summary::new(Some(farmer_config.plot_size)).await?;
@@ -111,10 +104,7 @@ pub(crate) async fn farm(is_verbose: bool) -> Result<(Farmer, Node, SingleInstan
111104
.build(
112105
farmer_config.address,
113106
node.clone(),
114-
&[PlotDescription::new(
115-
farmer_config.plot_directory,
116-
farmer_config.plot_size,
117-
)],
107+
&[PlotDescription::new(farmer_config.plot_directory, farmer_config.plot_size)],
118108
farmer_config.cache,
119109
)
120110
.await?;

src/commands/init.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use std::{io::Write, str::FromStr};
1+
use std::io::Write;
2+
use std::str::FromStr;
23

34
use color_eyre::eyre::{Context, Result};
45
use subspace_sdk::farmer::CacheDescription;
56

6-
use crate::config::DEFAULT_PLOT_SIZE;
7-
use crate::utils::{
8-
cache_directory_getter, get_user_input, node_name_parser, plot_directory_getter,
9-
plot_directory_parser, print_ascii_art, print_version, reward_address_parser, size_parser,
7+
use crate::config::{
8+
create_config, ChainConfig, Config, FarmerConfig, NodeConfig, DEFAULT_PLOT_SIZE,
109
};
11-
use crate::{
12-
config::{create_config, ChainConfig, Config, FarmerConfig, NodeConfig},
13-
utils::node_directory_getter,
10+
use crate::utils::{
11+
cache_directory_getter, get_user_input, node_directory_getter, node_name_parser,
12+
plot_directory_getter, plot_directory_parser, print_ascii_art, print_version,
13+
reward_address_parser, size_parser,
1414
};
1515

1616
/// implementation of the `init` command
@@ -25,38 +25,32 @@ pub(crate) fn init() -> Result<()> {
2525
println!("Configuration creation process has started...");
2626
let config = get_config_from_user_inputs()?;
2727
config_file
28-
.write_all(
29-
toml::to_string_pretty(&config)
30-
.wrap_err("Failed to write config")?
31-
.as_ref(),
32-
)
28+
.write_all(toml::to_string_pretty(&config).wrap_err("Failed to write config")?.as_ref())
3329
.wrap_err("Failed to write config")?;
3430

35-
println!(
36-
"Configuration has been generated at {}",
37-
config_path.display()
38-
);
31+
println!("Configuration has been generated at {}", config_path.display());
3932

4033
println!("Ready for lift off! Run the follow command to begin:");
4134
println!("`./subspace-cli farm`");
4235

4336
Ok(())
4437
}
4538

46-
/// gets the necessary information from user, and writes them to the given configuration file
39+
/// gets the necessary information from user, and writes them to the given
40+
/// configuration file
4741
fn get_config_from_user_inputs() -> Result<Config> {
4842
// GET USER INPUTS...
4943
// get reward address
50-
let reward_address = get_user_input(
51-
"Enter your farmer/reward address: ",
52-
None,
53-
reward_address_parser,
54-
)?;
44+
let reward_address =
45+
get_user_input("Enter your farmer/reward address: ", None, reward_address_parser)?;
5546

5647
// get node name
5748
let default_node_name = whoami::username();
5849
let node_name = get_user_input(
59-
&format!("Enter your node name to be identified on the network(defaults to `{default_node_name}`, press enter to use the default): "),
50+
&format!(
51+
"Enter your node name to be identified on the network(defaults to \
52+
`{default_node_name}`, press enter to use the default): "
53+
),
6054
Some(default_node_name),
6155
node_name_parser,
6256
)?;
@@ -74,7 +68,9 @@ fn get_config_from_user_inputs() -> Result<Config> {
7468
// get plot size
7569
let plot_size = get_user_input(
7670
&format!(
77-
"Specify a plot size (defaults to `{DEFAULT_PLOT_SIZE}`, press enter to use the default): "),
71+
"Specify a plot size (defaults to `{DEFAULT_PLOT_SIZE}`, press enter to use the \
72+
default): "
73+
),
7874
Some(DEFAULT_PLOT_SIZE),
7975
size_parser,
8076
)?;
@@ -83,7 +79,9 @@ fn get_config_from_user_inputs() -> Result<Config> {
8379
let default_chain = ChainConfig::Gemini3a;
8480
let chain = get_user_input(
8581
&format!(
86-
"Specify the chain to farm(defaults to `{default_chain:}`, press enter to use the default): "),
82+
"Specify the chain to farm(defaults to `{default_chain:}`, press enter to use the \
83+
default): "
84+
),
8785
Some(crate::config::ChainConfig::Gemini3a),
8886
ChainConfig::from_str,
8987
)?;

src/commands/wipe.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use color_eyre::eyre::Result;
2-
32
use subspace_sdk::{Node, PlotDescription};
43

54
use crate::config::parse_config;
@@ -13,7 +12,10 @@ pub(crate) async fn wipe() -> Result<()> {
1312
let config = match parse_config() {
1413
Ok(args) => args,
1514
Err(_) => {
16-
println!("could not read your config. You must have a valid config in order to wipe. Aborting...");
15+
println!(
16+
"could not read your config. You must have a valid config in order to wipe. \
17+
Aborting..."
18+
);
1719
return Ok(());
1820
}
1921
};

src/config.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
use std::{
2-
fs::{create_dir, File},
3-
path::PathBuf,
4-
str::FromStr,
5-
};
1+
use std::fs::{create_dir, File};
2+
use std::path::PathBuf;
3+
use std::str::FromStr;
64

75
use bytesize::ByteSize;
8-
use color_eyre::{
9-
eyre::{eyre, Result},
10-
Report,
11-
};
6+
use color_eyre::eyre::{eyre, Result};
7+
use color_eyre::Report;
128
use serde::{Deserialize, Serialize};
9+
use subspace_sdk::farmer::{self, CacheDescription, Config as SdkFarmerConfig, Farmer};
10+
use subspace_sdk::node::{self, Config as SdkNodeConfig, Node};
11+
use subspace_sdk::PublicKey;
1312
use tracing::instrument;
1413

15-
use subspace_sdk::{
16-
farmer::{self, CacheDescription, Config as SdkFarmerConfig, Farmer},
17-
node::{self, Config as SdkNodeConfig, Node},
18-
PublicKey,
19-
};
20-
2114
/// defaults for the user config file
2215
pub(crate) const DEFAULT_PLOT_SIZE: bytesize::ByteSize = bytesize::ByteSize::gb(1);
2316
pub(crate) const MIN_PLOT_SIZE: bytesize::ByteSize = bytesize::ByteSize::mib(32);
@@ -101,9 +94,11 @@ impl FarmerConfig {
10194
plot_size,
10295
cache,
10396
farmer: Farmer::builder()
104-
.dsn(farmer::DsnBuilder::new().listen_on(vec![
105-
"/ip4/0.0.0.0/tcp/30533".parse().expect("Valid multiaddr"),
106-
]))
97+
.dsn(
98+
farmer::DsnBuilder::new().listen_on(vec!["/ip4/0.0.0.0/tcp/30533"
99+
.parse()
100+
.expect("Valid multiaddr")]),
101+
)
107102
.configuration(),
108103
}
109104
}
@@ -130,7 +125,10 @@ impl FromStr for ChainConfig {
130125
let chain_list = vec!["gemini-3a"];
131126
match s {
132127
"gemini-3a" => Ok(ChainConfig::Gemini3a),
133-
_ => Err(eyre!("given chain: `{s}` is not recognized! Please enter a valid chain from this list: {chain_list:?}.")),
128+
_ => Err(eyre!(
129+
"given chain: `{s}` is not recognized! Please enter a valid chain from this list: \
130+
{chain_list:?}."
131+
)),
134132
}
135133
}
136134
}

src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ mod utils;
1212
use clap::{Parser, Subcommand};
1313
use color_eyre::eyre::Report;
1414
use color_eyre::Help;
15-
use commands::{farm::farm, info::info, init::init, wipe::wipe};
15+
use commands::farm::farm;
16+
use commands::info::info;
17+
use commands::init::init;
18+
use commands::wipe::wipe;
1619
use tokio::signal;
1720
use tracing::instrument;
1821

@@ -31,9 +34,8 @@ struct Cli {
3134
/// Available commands for the CLI
3235
#[derive(Debug, Subcommand)]
3336
enum Commands {
34-
#[command(
35-
about = "displays info about the farmer instance (i.e. total amount of rewards, and status of initial plotting)"
36-
)]
37+
#[command(about = "displays info about the farmer instance (i.e. total amount of rewards, \
38+
and status of initial plotting)")]
3739
Info,
3840
#[command(about = "initializes the config file required for the farming")]
3941
Init,
@@ -61,7 +63,10 @@ async fn main() -> Result<(), Report> {
6163
let (farmer, node, _instance) = farm(verbose).await.suggestion(support_message())?;
6264

6365
signal::ctrl_c().await?;
64-
println!("\nWill try to gracefully exit the application now. If you press ctrl+c again, it will try to forcefully close the app!");
66+
println!(
67+
"\nWill try to gracefully exit the application now. If you press ctrl+c again, it \
68+
will try to forcefully close the app!"
69+
);
6570
let handle = tokio::spawn(async {
6671
let _ = farmer.close().await;
6772
node.close().await;

src/summary.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
/// Stores the summary of the farming process into a file.
22
/// This allows to retrieve farming information with `info` command,
3-
/// and also store the amount of potentially farmed blocks during the initial plotting progress,
4-
/// so that progress bar won't be affected with `println!`, and user will still know about them
5-
/// when initial plotting is finished.
3+
/// and also store the amount of potentially farmed blocks during the initial
4+
/// plotting progress, so that progress bar won't be affected with `println!`,
5+
/// and user will still know about them when initial plotting is finished.
66
use std::{path::PathBuf, sync::Arc};
77

88
use bytesize::ByteSize;
99
use color_eyre::eyre::{Report, Result};
1010
use serde::{Deserialize, Serialize};
11-
use tokio::{
12-
fs::{create_dir_all, read_to_string, remove_file, File, OpenOptions},
13-
io::AsyncWriteExt,
14-
sync::Mutex,
15-
};
11+
use tokio::fs::{create_dir_all, read_to_string, remove_file, File, OpenOptions};
12+
use tokio::io::AsyncWriteExt;
13+
use tokio::sync::Mutex;
1614
use tracing::instrument;
1715

18-
/// Struct for holding the information of what to be displayed with the `info` command
16+
/// Struct for holding the information of what to be displayed with the `info`
17+
/// command
1918
#[derive(Deserialize, Serialize, Debug)]
2019
struct FarmerSummary {
2120
initial_plotting_finished: bool,
@@ -24,7 +23,8 @@ struct FarmerSummary {
2423
user_space_pledged: ByteSize,
2524
}
2625

27-
/// utilizing persistent storage for the information to be displayed for the `info` command
26+
/// utilizing persistent storage for the information to be displayed for the
27+
/// `info` command
2828
#[derive(Debug, Clone)]
2929
pub(crate) struct Summary {
3030
file: Arc<Mutex<PathBuf>>,
@@ -39,7 +39,8 @@ impl Summary {
3939
.expect("couldn't get the default local data directory!")
4040
.join("subspace-cli");
4141

42-
// providing `Some` value for `user_space_pledged` means, we are creating a new file
42+
// providing `Some` value for `user_space_pledged` means, we are creating a new
43+
// file
4344
if let Some(user_space_pledged) = user_space_pledged {
4445
// File::create will truncate the existing file, so first
4546
// check if the file exists, if not, `open` will return an error
@@ -63,9 +64,7 @@ impl Summary {
6364
}
6465
}
6566

66-
Ok(Summary {
67-
file: Arc::new(Mutex::new(summary_path)),
68-
})
67+
Ok(Summary { file: Arc::new(Mutex::new(summary_path)) })
6968
}
7069

7170
/// updates the summary file
@@ -101,7 +100,8 @@ impl Summary {
101100
Ok(())
102101
}
103102

104-
/// retrives how much space has user pledged to the network from the summary file
103+
/// retrives how much space has user pledged to the network from the summary
104+
/// file
105105
#[instrument]
106106
pub(crate) async fn get_user_space_pledged(&self) -> Result<ByteSize> {
107107
let summary = self.parse_summary().await?;

0 commit comments

Comments
 (0)