Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Oct 11, 2023
1 parent ce24f51 commit 5a28fd1
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 67 deletions.
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/bin/cli/kedqr/decode/img.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;
use std::path::PathBuf;

pub fn save_secret_from_qr(qr: PathBuf, output: Option<PathBuf>, pin: QrPin) -> Result<(), Report> {
let sk = secret_from_qr(&qr, pin)?;
let sk = secret_from_qr(qr, pin)?;
let hrp = Ed25519Extended::SECRET_BECH32_HRP;
let secret_key = bech32::encode(hrp, sk.leak_secret().to_base32(), Variant::Bech32)?;

Expand Down
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/bin/cli/kedqr/encode/img.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn generate_qr(input: PathBuf, output: Option<PathBuf>, pin: QrPin) -> Resul
.read(true)
.write(false)
.append(false)
.open(&input)
.open(input)
.expect("Could not open input file.");

let mut reader = BufReader::new(key_file);
Expand Down
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/bin/cli/kedqr/encode/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn generate_payload(input: PathBuf, output: Option<PathBuf>, pin: QrPin) ->
.read(true)
.write(false)
.append(false)
.open(&input)
.open(input)
.expect("Could not open input file.");

let mut reader = BufReader::new(key_file);
Expand Down
3 changes: 1 addition & 2 deletions catalyst-toolbox/src/bin/cli/kedqr/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ impl VerifyQrCodeCmd {
if let Some(file) = &self.file {
vec![file.to_path_buf()]
} else {
std::fs::read_dir(&self.folder.as_ref().unwrap())
std::fs::read_dir(self.folder.as_ref().unwrap())
.unwrap()
.into_iter()
.map(|x| x.unwrap().path())
.collect()
}
Expand Down
4 changes: 2 additions & 2 deletions catalyst-toolbox/src/bin/cli/rewards/veterans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ impl VeteransRewards {
min_rankings..=max_rankings_reputation,
rewards_agreement_rate_cutoffs
.into_iter()
.zip(rewards_agreement_rate_modifiers.into_iter())
.zip(rewards_agreement_rate_modifiers)
.collect(),
reputation_agreement_rate_cutoffs
.into_iter()
.zip(reputation_agreement_rate_modifiers.into_iter())
.zip(reputation_agreement_rate_modifiers)
.collect(),
);

Expand Down
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/bin/cli/rewards/voters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn write_rewards_results(
let writer = common.open_output()?;
let header = ["Address", "Reward for the voter (lovelace)"];
let mut csv_writer = csv::Writer::from_writer(writer);
csv_writer.write_record(&header)?;
csv_writer.write_record(header)?;

for (address, rewards) in rewards.iter() {
let record = [address.to_string(), rewards.trunc().to_string()];
Expand Down
4 changes: 2 additions & 2 deletions catalyst-toolbox/src/bin/cli/stats/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ impl ArchiveCommand {
pub fn exec(self) -> Result<(), Report> {
let archiver: ArchiveStats = {
if let Some(csv) = &self.csv {
load_from_csv(&csv)?.into()
load_from_csv(csv)?.into()
} else if let Some(folder) = &self.folder {
load_from_folder(&folder)?.into()
load_from_folder(folder)?.into()
} else {
panic!("no csv nor folder defined");
}
Expand Down
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/bin/cli/stats/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Command {

impl SnapshotCommand {
pub fn exec(&self) -> Result<(), Report> {
let initials: Vec<Initial> = read_initials(&jortestkit::file::read_file(&self.snapshot)?)?;
let initials: Vec<Initial> = read_initials(jortestkit::file::read_file(&self.snapshot)?)?;

match self.command {
Command::Count => calculate_wallet_distribution_from_initials(
Expand Down
3 changes: 2 additions & 1 deletion catalyst-toolbox/src/ideascale/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ pub fn build_challenges(
(
c.id,
models::se::Challenge {
#[allow(clippy::obfuscated_if_else)]
challenge_type: funnels
.get(&c.funnel_id)
.unwrap_or_else(|| panic!("A funnel with id {} wasn't found", c.funnel_id))
.is_community()
.then(|| "community-choice")
.then_some("community-choice")
.unwrap_or("simple")
.to_string(),
challenge_url: c.challenge_url.clone(),
Expand Down
5 changes: 1 addition & 4 deletions catalyst-toolbox/src/ideascale/models/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ fn deserialize_rewards<'de, D: Deserializer<'de>>(deserializer: D) -> Result<u64
})
.and_then(|s| s.parse().ok())
.ok_or_else(|| {
D::Error::custom(&format!(
"Unable to read malformed value: '{}'",
rewards_str
))
D::Error::custom(format!("Unable to read malformed value: '{}'", rewards_str))
})
}
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/kedqr/img.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum QrDecodeError {
impl KeyQrCode {
pub fn generate(key: SecretKey<Ed25519Extended>, password: &[u8]) -> Self {
let enc_hex = payload::generate(key, password);
let inner = QrCode::with_error_correction_level(&enc_hex, EcLevel::H).unwrap();
let inner = QrCode::with_error_correction_level(enc_hex, EcLevel::H).unwrap();

KeyQrCode { inner }
}
Expand Down
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/kedqr/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn decode<S: Into<String>>(
password: &[u8],
) -> Result<SecretKey<Ed25519Extended>, Error> {
let encrypted_bytes = hex::decode(payload.into())?;
let key = decrypt(password, &encrypted_bytes)?;
let key = decrypt(password, encrypted_bytes)?;
Ok(SecretKey::from_binary(&key)?)
}

Expand Down
8 changes: 2 additions & 6 deletions catalyst-toolbox/src/logs/sentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,9 @@ mod tests {
let successful_scan_log = serde_json::json!({ "message": REGISTERED_MESSAGE });
let unsuccessful_scan_log = serde_json::json!({ "message": MALFORMED_QR_MESSAGE });

let success_logs = (0..success)
.into_iter()
.map(|_| successful_scan_log.clone());
let success_logs = (0..success).map(|_| successful_scan_log.clone());

let unsuccessful_logs = (0..unssucess)
.into_iter()
.map(|_| unsuccessful_scan_log.clone());
let unsuccessful_logs = (0..unssucess).map(|_| unsuccessful_scan_log.clone());

success_logs.chain(unsuccessful_logs).collect()
}
Expand Down
3 changes: 2 additions & 1 deletion catalyst-toolbox/src/recovery/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Replay {
}
}

#[allow(clippy::result_large_err)]
pub fn exec(self) -> Result<(), Error> {
let fragments = load_persistent_fragments_logs_from_folder_path(&self.logs_path)
.map_err(Error::PersistenLogsLoading)?;
Expand All @@ -53,7 +54,7 @@ impl Replay {
let mut out_writer = self.output.open()?;
let content = self
.output_format
.format_json(serde_json::to_value(&voteplan_status)?)?;
.format_json(serde_json::to_value(voteplan_status)?)?;
out_writer.write_all(content.as_bytes())?;
Ok(())
}
Expand Down
10 changes: 7 additions & 3 deletions catalyst-toolbox/src/recovery/tally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ pub struct VoteFragmentFilter<I: Iterator<Item = PersistentFragmentLog>> {
}

impl<I: Iterator<Item = PersistentFragmentLog>> VoteFragmentFilter<I> {
#[allow(clippy::result_large_err)]
pub fn new(block0: Block, range_check: Range<u32>, fragments: I) -> Result<Self, Error> {
let block0_configuration = Block0Configuration::from_block(&block0)?;
let fees = block0_configuration.blockchain_configuration.linear_fees;
Expand Down Expand Up @@ -347,6 +348,7 @@ impl<I: Iterator<Item = PersistentFragmentLog>> Iterator for VoteFragmentFilter<
}
}

#[allow(clippy::result_large_err)]
pub fn recover_ledger_from_logs(
block0: &Block,
fragment_logs: impl Iterator<Item = Result<PersistentFragmentLog, FragmentLogDeserializeError>>,
Expand Down Expand Up @@ -435,6 +437,7 @@ struct FragmentReplayer {

impl FragmentReplayer {
// build a new block0 with mirror accounts and same configuration as original one
#[allow(clippy::result_large_err)]
fn from_block0(block0: &Block) -> Result<(Self, Block), Error> {
let mut config =
Block0Configuration::from_block(block0).map_err(Error::Block0ConfigurationError)?;
Expand Down Expand Up @@ -502,6 +505,7 @@ impl FragmentReplayer {
))
}

#[allow(clippy::result_large_err)]
fn replay_votecast(&mut self, tx: TransactionSlice<VoteCast>) -> Result<Fragment, Error> {
let (vote_cast, identifier, _) = deconstruct_account_transaction(&tx)?;
let address =
Expand All @@ -526,6 +530,7 @@ impl FragmentReplayer {
Ok(res)
}

#[allow(clippy::result_large_err)]
fn replay_tx(&mut self, tx: TransactionSlice<NoExtra>) -> Result<Fragment, Error> {
let (_, identifier, _) = deconstruct_account_transaction(&tx)?;
let address =
Expand All @@ -544,9 +549,7 @@ impl FragmentReplayer {
self.non_voting_wallets
.entry(address.clone())
.or_insert_with(|| {
Wallet::new_from_key(<SecretKey<Ed25519Extended>>::generate(
&mut rand::thread_rng(),
))
Wallet::new_from_key(<SecretKey<Ed25519Extended>>::generate(rand::thread_rng()))
})
.account_id()
}
Expand Down Expand Up @@ -576,6 +579,7 @@ impl FragmentReplayer {
}

// rebuild a fragment to be used in the new ledger configuration with the account mirror account.
#[allow(clippy::result_large_err)]
fn replay(
&mut self,
original: ValidatedFragment,
Expand Down
14 changes: 7 additions & 7 deletions catalyst-toolbox/src/rewards/veterans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn calculate_veteran_advisors_incentives(

reputation_eligible_rankings
.into_iter()
.zip(rewards_eligible_rankings.into_iter())
.zip(rewards_eligible_rankings)
.map(|((vca, reputation), (_vca2, reward))| {
assert_eq!(vca, _vca2); // the use of BTreeMaps ensures iteration is consistent
(
Expand Down Expand Up @@ -225,11 +225,11 @@ mod tests {
2..=2,
THRESHOLDS
.into_iter()
.zip(REWARDS_DISAGREEMENT_MODIFIERS.into_iter())
.zip(REWARDS_DISAGREEMENT_MODIFIERS)
.collect(),
THRESHOLDS
.into_iter()
.zip(REPUTATION_DISAGREEMENT_MODIFIERS.into_iter())
.zip(REPUTATION_DISAGREEMENT_MODIFIERS)
.collect(),
);
assert!(results.get(VCA_1).is_none());
Expand All @@ -254,11 +254,11 @@ mod tests {
1..=1,
THRESHOLDS
.into_iter()
.zip(REWARDS_DISAGREEMENT_MODIFIERS.into_iter())
.zip(REWARDS_DISAGREEMENT_MODIFIERS)
.collect(),
THRESHOLDS
.into_iter()
.zip(REPUTATION_DISAGREEMENT_MODIFIERS.into_iter())
.zip(REPUTATION_DISAGREEMENT_MODIFIERS)
.collect(),
);
let res1 = results.get(VCA_1).unwrap();
Expand Down Expand Up @@ -304,11 +304,11 @@ mod tests {
1..=200,
THRESHOLDS
.into_iter()
.zip(REWARDS_DISAGREEMENT_MODIFIERS.into_iter())
.zip(REWARDS_DISAGREEMENT_MODIFIERS)
.collect(),
THRESHOLDS
.into_iter()
.zip(REPUTATION_DISAGREEMENT_MODIFIERS.into_iter())
.zip(REPUTATION_DISAGREEMENT_MODIFIERS)
.collect(),
);
let expected_reward_portion = agreement * Rewards::from(100) * reward_modifier;
Expand Down
4 changes: 1 addition & 3 deletions catalyst-toolbox/src/rewards/voters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn active_addresses(
// even if they didn't vote and the threshold is 0.
// Active accounts are overwritten with the correct count.
.map(|key| (key.to_hex(), 0))
.chain(vote_count.into_iter())
.chain(vote_count)
.filter_map(|(account_hex, count)| {
if count >= threshold {
Some(
Expand Down Expand Up @@ -219,7 +219,6 @@ mod tests {
fn test_all_active(snapshot: Snapshot) {
let votes_count = snapshot
.voting_keys()
.into_iter()
.map(|key| (key.to_hex(), 1))
.collect::<VoteCount>();
let n_voters = votes_count.len();
Expand Down Expand Up @@ -299,7 +298,6 @@ mod tests {

let votes_count = snapshot
.voting_keys()
.into_iter()
.map(|key| (key.to_hex(), 1))
.collect::<VoteCount>();

Expand Down
6 changes: 3 additions & 3 deletions catalyst-toolbox/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Snapshot {
.map(|reg| {
let value = u64::from(reg.voting_power);
if in_lovelace {
value / 1_000_000 as u64
value / 1_000_000_u64
} else {
value
}
Expand Down Expand Up @@ -180,7 +180,7 @@ where

let addr_type = match addr_type {
// Shelley
0x0 | 0x1 | 0x2 | 0x3 | 0x4 | 0x5 | 0x6 | 0x7 => AddrType::Shelley,
0x0..=0x7 => AddrType::Shelley,
// Stake
0xf | 0xe => AddrType::Stake,
_ => {
Expand Down Expand Up @@ -232,7 +232,7 @@ mod tests {
.prop_map(|((stake_key, rewards_addr, voting_key), vp)| {
let stake_public_key = hex::encode(stake_key);
let reward_address =
bech32::encode("stake", &rewards_addr.to_base32(), bech32::Variant::Bech32)
bech32::encode("stake", rewards_addr.to_base32(), bech32::Variant::Bech32)
.unwrap();
let voting_public_key = <SecretKey<Ed25519>>::from_binary(&voting_key)
.expect("every binary sequence is a valid secret key")
Expand Down
2 changes: 1 addition & 1 deletion catalyst-toolbox/src/stats/live/harvester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Harvester {
.build()?;

let res = client
.get(&format!("{}/v0/fragment/logs", self.endpoint))
.get(format!("{}/v0/fragment/logs", self.endpoint))
.send()?;
serde_json::from_str(&res.text()?).map_err(Into::into)
}
Expand Down
1 change: 0 additions & 1 deletion catalyst-toolbox/tests/tally/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ impl TestBlockchainBuilder {

let mut initial = Vec::with_capacity(self.n_wallets as usize + self.n_committees as usize);
let mut wallets = (0..self.n_wallets + self.n_committees as u32)
.into_iter()
.map(|_| {
let funds = rng.gen_range(MIN_FUNDS..MAX_FUNDS);
let wallet =
Expand Down
4 changes: 2 additions & 2 deletions catalyst-toolbox/tests/tally/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn account_from_slice<P>(
}
}

impl<'a> VoteRoundGenerator {
impl VoteRoundGenerator {
pub fn new(blockchain: TestBlockchain) -> Self {
let TestBlockchain {
config,
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<'a> VoteRoundGenerator {
let decrypted_tally = DecryptedPrivateTally::new(
results
.into_iter()
.zip(shares.into_iter())
.zip(shares)
.map(|(tally_result, decrypt_shares)| {
DecryptedPrivateTallyProposal {
decrypt_shares,
Expand Down
Loading

0 comments on commit 5a28fd1

Please sign in to comment.