Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bolt-cli): add lints #432

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bolt-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ alloy-node-bindings = "0.6.3"

[build-dependencies]
tonic-build = "0.12.3"

[lints.clippy]
explicit_iter_loop = "warn"
if_not_else = "warn"
manual_let_else = "warn"
match_bool = "warn"
redundant_else = "warn"
unnecessary_self_imports = "warn"
use_self = "warn"
18 changes: 9 additions & 9 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ impl Cmd {
/// Run the command.
pub async fn run(self) -> eyre::Result<()> {
match self {
Cmd::Delegate(cmd) => cmd.run().await,
Cmd::Pubkeys(cmd) => cmd.run().await,
Cmd::Send(cmd) => cmd.run().await,
Cmd::Validators(cmd) => cmd.run().await,
Cmd::Operators(cmd) => cmd.run().await,
Self::Delegate(cmd) => cmd.run().await,
Self::Pubkeys(cmd) => cmd.run().await,
Self::Send(cmd) => cmd.run().await,
Self::Validators(cmd) => cmd.run().await,
Self::Operators(cmd) => cmd.run().await,
}
}
}
Expand Down Expand Up @@ -406,10 +406,10 @@ impl Chain {
/// Get the fork version for the given chain.
pub fn fork_version(&self) -> [u8; 4] {
match self {
Chain::Mainnet => [0, 0, 0, 0],
Chain::Holesky => [1, 1, 112, 0],
Chain::Helder => [16, 0, 0, 0],
Chain::Kurtosis => [16, 0, 0, 56],
Self::Mainnet => [0, 0, 0, 0],
Self::Holesky => [1, 1, 112, 0],
Self::Helder => [16, 0, 0, 0],
Self::Kurtosis => [16, 0, 0, 56],
}
}

Expand Down
16 changes: 8 additions & 8 deletions bolt-cli/src/common/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ impl KeystoreSecret {
/// Create a new [`KeystoreSecret`] from the provided [`LocalKeystoreOpts`].
pub fn from_keystore_options(opts: &LocalKeystoreOpts) -> Result<Self> {
if let Some(password_path) = &opts.password_path {
Ok(KeystoreSecret::from_directory(password_path)?)
Ok(Self::from_directory(password_path)?)
} else if let Some(password) = &opts.password {
Ok(KeystoreSecret::from_unique_password(password.clone()))
Ok(Self::from_unique_password(password.clone()))
} else {
// This case is prevented upstream by clap's validation.
bail!("Either `password_path` or `password` must be provided")
Expand All @@ -61,19 +61,19 @@ impl KeystoreSecret {
let secret = fs::read_to_string(&path).wrap_err("Failed to read secret file")?;
secrets.insert(filename.trim_start_matches("0x").to_string(), secret);
}
Ok(KeystoreSecret::Directory(secrets))
Ok(Self::Directory(secrets))
}

/// Set a unique password for all validators in the keystore.
pub fn from_unique_password(password: String) -> Self {
KeystoreSecret::Unique(password)
Self::Unique(password)
}

/// Get the password for the given validator public key.
pub fn get(&self, validator_pubkey: &str) -> Option<&str> {
match self {
KeystoreSecret::Unique(password) => Some(password.as_str()),
KeystoreSecret::Directory(secrets) => secrets.get(validator_pubkey).map(|s| s.as_str()),
Self::Unique(password) => Some(password.as_str()),
Self::Directory(secrets) => secrets.get(validator_pubkey).map(|s| s.as_str()),
}
}
}
Expand All @@ -83,13 +83,13 @@ impl KeystoreSecret {
impl Drop for KeystoreSecret {
fn drop(&mut self) {
match self {
KeystoreSecret::Unique(password) => {
Self::Unique(password) => {
let bytes = unsafe { password.as_bytes_mut() };
for b in bytes.iter_mut() {
*b = 0;
}
}
KeystoreSecret::Directory(secrets) => {
Self::Directory(secrets) => {
for secret in secrets.values_mut() {
let bytes = unsafe { secret.as_bytes_mut() };
for b in bytes.iter_mut() {
Expand Down
10 changes: 5 additions & 5 deletions bolt-cli/src/contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ pub enum EigenLayerStrategy {
impl std::fmt::Display for EigenLayerStrategy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let output = match self {
EigenLayerStrategy::StEth => "stETH",
EigenLayerStrategy::REth => "rETH",
EigenLayerStrategy::WEth => "wETH",
EigenLayerStrategy::CbEth => "cbETH",
EigenLayerStrategy::MEth => "mETH",
Self::StEth => "stETH",
Self::REth => "rETH",
Self::WEth => "wETH",
Self::CbEth => "cbETH",
Self::MEth => "mETH",
};
write!(f, "{}", output)
}
Expand Down