mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 22:08:30 +00:00
Fix new clippy lints (#2036)
## Issue Addressed NA ## Proposed Changes Fixes new clippy lints in the whole project (mainly [manual_strip](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip) and [unnecessary_lazy_evaluations](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations)). Furthermore, removes `to_string()` calls on literals when used with the `?`-operator.
This commit is contained in:
@@ -86,14 +86,12 @@ impl ValidatorDefinition {
|
||||
let voting_keystore_path = voting_keystore_path.as_ref().into();
|
||||
let keystore =
|
||||
Keystore::from_json_file(&voting_keystore_path).map_err(Error::UnableToOpenKeystore)?;
|
||||
let voting_public_key = keystore
|
||||
.public_key()
|
||||
.ok_or_else(|| Error::InvalidKeystorePubkey)?;
|
||||
let voting_public_key = keystore.public_key().ok_or(Error::InvalidKeystorePubkey)?;
|
||||
|
||||
Ok(ValidatorDefinition {
|
||||
enabled: true,
|
||||
voting_public_key,
|
||||
description: keystore.description().unwrap_or_else(|| "").to_string(),
|
||||
description: keystore.description().unwrap_or("").to_string(),
|
||||
signing_definition: SigningDefinition::LocalKeystore {
|
||||
voting_keystore_path,
|
||||
voting_keystore_password_path: None,
|
||||
@@ -214,7 +212,7 @@ impl ValidatorDefinitions {
|
||||
Some(ValidatorDefinition {
|
||||
enabled: true,
|
||||
voting_public_key,
|
||||
description: keystore.description().unwrap_or_else(|| "").to_string(),
|
||||
description: keystore.description().unwrap_or("").to_string(),
|
||||
signing_definition: SigningDefinition::LocalKeystore {
|
||||
voting_keystore_path,
|
||||
voting_keystore_password_path,
|
||||
|
||||
@@ -101,8 +101,8 @@ pub fn parse_ssz_optional<T: Decode>(
|
||||
matches
|
||||
.value_of(name)
|
||||
.map(|val| {
|
||||
if val.starts_with("0x") {
|
||||
let vec = hex::decode(&val[2..])
|
||||
if let Some(stripped) = val.strip_prefix("0x") {
|
||||
let vec = hex::decode(stripped)
|
||||
.map_err(|e| format!("Unable to parse {} as hex: {:?}", name, e))?;
|
||||
|
||||
T::from_ssz_bytes(&vec)
|
||||
|
||||
@@ -86,7 +86,7 @@ pub fn download_deposit_contract(
|
||||
|
||||
let abi = contract
|
||||
.get("abi")
|
||||
.ok_or_else(|| "Response does not contain key: abi".to_string())?
|
||||
.ok_or("Response does not contain key: abi")?
|
||||
.to_string();
|
||||
|
||||
verify_checksum(abi.as_bytes(), abi_checksum);
|
||||
@@ -97,7 +97,7 @@ pub fn download_deposit_contract(
|
||||
|
||||
let bytecode = contract
|
||||
.get("bytecode")
|
||||
.ok_or_else(|| "Response does not contain key: bytecode".to_string())?
|
||||
.ok_or("Response does not contain key: bytecode")?
|
||||
.to_string();
|
||||
|
||||
verify_checksum(bytecode.as_bytes(), bytecode_checksum);
|
||||
|
||||
@@ -55,8 +55,7 @@ pub fn decode_eth1_tx_data(
|
||||
) -> Result<(DepositData, Hash256), DecodeError> {
|
||||
let abi = Contract::load(ABI)?;
|
||||
let function = abi.function("deposit")?;
|
||||
let mut tokens =
|
||||
function.decode_input(bytes.get(4..).ok_or_else(|| DecodeError::InadequateBytes)?)?;
|
||||
let mut tokens = function.decode_input(bytes.get(4..).ok_or(DecodeError::InadequateBytes)?)?;
|
||||
|
||||
macro_rules! decode_token {
|
||||
($type: ty, $to_fn: ident) => {
|
||||
|
||||
@@ -79,7 +79,7 @@ impl ValidatorClientHttpClient {
|
||||
let sig = response
|
||||
.headers()
|
||||
.get("Signature")
|
||||
.ok_or_else(|| Error::MissingSignatureHeader)?
|
||||
.ok_or(Error::MissingSignatureHeader)?
|
||||
.to_str()
|
||||
.map_err(|_| Error::InvalidSignatureHeader)?
|
||||
.to_string();
|
||||
@@ -96,7 +96,7 @@ impl ValidatorClientHttpClient {
|
||||
Some(secp256k1::verify(&message, &sig, &self.server_pubkey))
|
||||
})
|
||||
.filter(|is_valid| *is_valid)
|
||||
.ok_or_else(|| Error::InvalidSignatureHeader)?;
|
||||
.ok_or(Error::InvalidSignatureHeader)?;
|
||||
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ impl TryInto<Keypair> for YamlKeypair {
|
||||
}
|
||||
|
||||
fn string_to_bytes(string: &str) -> Result<Vec<u8>, String> {
|
||||
let string = if string.starts_with("0x") {
|
||||
&string[2..]
|
||||
let string = if let Some(stripped) = string.strip_prefix("0x") {
|
||||
stripped
|
||||
} else {
|
||||
string
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@ impl Eth2TestnetConfig {
|
||||
let genesis_state_bytes = self
|
||||
.genesis_state_bytes
|
||||
.as_ref()
|
||||
.ok_or_else(|| "Genesis state is unknown".to_string())?;
|
||||
.ok_or("Genesis state is unknown")?;
|
||||
|
||||
BeaconState::from_ssz_bytes(genesis_state_bytes)
|
||||
.map_err(|e| format!("Genesis state SSZ bytes are invalid: {:?}", e))
|
||||
@@ -156,8 +156,8 @@ impl Eth2TestnetConfig {
|
||||
//
|
||||
// This allows us to play nice with other clients that are expecting
|
||||
// plain-text, not YAML.
|
||||
let no_doc_header = if yaml.starts_with("---\n") {
|
||||
&yaml[4..]
|
||||
let no_doc_header = if let Some(stripped) = yaml.strip_prefix("---\n") {
|
||||
stripped
|
||||
} else {
|
||||
&yaml
|
||||
};
|
||||
|
||||
@@ -138,7 +138,7 @@ impl<'a> Builder<'a> {
|
||||
pub fn build(self) -> Result<ValidatorDir, Error> {
|
||||
let (voting_keystore, voting_password) = self
|
||||
.voting_keystore
|
||||
.ok_or_else(|| Error::UninitializedVotingKeystore)?;
|
||||
.ok_or(Error::UninitializedVotingKeystore)?;
|
||||
|
||||
let dir = self
|
||||
.base_validators_dir
|
||||
|
||||
@@ -167,8 +167,8 @@ impl ValidatorDir {
|
||||
.map_err(Error::UnableToReadDepositData)
|
||||
.and_then(|hex_bytes| {
|
||||
let hex = std::str::from_utf8(&hex_bytes).map_err(|_| Error::DepositDataNotUtf8)?;
|
||||
if hex.starts_with("0x") {
|
||||
hex::decode(&hex[2..]).map_err(Error::DepositDataInvalidHex)
|
||||
if let Some(stripped) = hex.strip_prefix("0x") {
|
||||
hex::decode(stripped).map_err(Error::DepositDataInvalidHex)
|
||||
} else {
|
||||
Err(Error::DepositDataMissing0xPrefix)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user