Skip to content

Commit

Permalink
Fix some clippy warnings (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Sep 22, 2023
1 parent 69edbf7 commit 5192a45
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 48 deletions.
63 changes: 31 additions & 32 deletions cli/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub async fn account_prompt_internal(
}

let input = rl.readline(&prompt);

match input {
Ok(command) => {
match command.as_str() {
Expand Down Expand Up @@ -103,16 +104,16 @@ pub async fn account_prompt_internal(
}
};
match account_cli.command {
AccountCommand::Addresses => addresses_command(&account).await,
AccountCommand::Balance { addresses } => balance_command(&account, addresses).await,
AccountCommand::Addresses => addresses_command(account).await,
AccountCommand::Balance { addresses } => balance_command(account, addresses).await,
AccountCommand::BurnNativeToken { token_id, amount } => {
burn_native_token_command(&account, token_id, amount).await
burn_native_token_command(account, token_id, amount).await
}
AccountCommand::BurnNft { nft_id } => burn_nft_command(&account, nft_id).await,
AccountCommand::Claim { output_id } => claim_command(&account, output_id).await,
AccountCommand::ClaimableOutputs => claimable_outputs_command(&account).await,
AccountCommand::Consolidate => consolidate_command(&account).await,
AccountCommand::CreateAccountOutput => create_account_output_command(&account).await,
AccountCommand::BurnNft { nft_id } => burn_nft_command(account, nft_id).await,
AccountCommand::Claim { output_id } => claim_command(account, output_id).await,
AccountCommand::ClaimableOutputs => claimable_outputs_command(account).await,
AccountCommand::Consolidate => consolidate_command(account).await,
AccountCommand::CreateAccountOutput => create_account_output_command(account).await,
AccountCommand::CreateNativeToken {
circulating_supply,
maximum_supply,
Expand All @@ -128,20 +129,20 @@ pub async fn account_prompt_internal(
.await
}
AccountCommand::DestroyAccount { account_id } => {
destroy_account_command(&account, account_id).await
destroy_account_command(account, account_id).await
}
AccountCommand::DestroyFoundry { foundry_id } => {
destroy_foundry_command(&account, foundry_id).await
destroy_foundry_command(account, foundry_id).await
}
AccountCommand::Exit => {
return Ok(AccountPromptResponse::Done);
}
AccountCommand::Faucet { address, url } => faucet_command(&account, address, url).await,
AccountCommand::Faucet { address, url } => faucet_command(account, address, url).await,
AccountCommand::MeltNativeToken { token_id, amount } => {
melt_native_token_command(&account, token_id, amount).await
melt_native_token_command(account, token_id, amount).await
}
AccountCommand::MintNativeToken { token_id, amount } => {
mint_native_token(&account, token_id, amount).await
mint_native_token(account, token_id, amount).await
}
AccountCommand::MintNft {
address,
Expand All @@ -164,10 +165,10 @@ pub async fn account_prompt_internal(
)
.await
}
AccountCommand::NewAddress => new_address_command(&account).await,
AccountCommand::NodeInfo => node_info_command(&account).await,
AccountCommand::Output { output_id } => output_command(&account, output_id).await,
AccountCommand::Outputs => outputs_command(&account).await,
AccountCommand::NewAddress => new_address_command(account).await,
AccountCommand::NodeInfo => node_info_command(account).await,
AccountCommand::Output { output_id } => output_command(account, output_id).await,
AccountCommand::Outputs => outputs_command(account).await,
AccountCommand::Send {
address,
amount,
Expand All @@ -187,35 +188,33 @@ pub async fn account_prompt_internal(
token_id,
amount,
gift_storage_deposit,
} => send_native_token_command(&account, address, token_id, amount, gift_storage_deposit).await,
AccountCommand::SendNft { address, nft_id } => {
send_nft_command(&account, address, nft_id).await
}
} => send_native_token_command(account, address, token_id, amount, gift_storage_deposit).await,
AccountCommand::SendNft { address, nft_id } => send_nft_command(account, address, nft_id).await,
AccountCommand::Switch { account_id } => {
return Ok(AccountPromptResponse::Switch(wallet.get_account(account_id).await?));
}
AccountCommand::Sync => sync_command(&account).await,
AccountCommand::Transaction { selector } => transaction_command(&account, selector).await,
AccountCommand::Sync => sync_command(account).await,
AccountCommand::Transaction { selector } => transaction_command(account, selector).await,
AccountCommand::Transactions { show_details } => {
transactions_command(&account, show_details).await
transactions_command(account, show_details).await
}
AccountCommand::UnspentOutputs => unspent_outputs_command(&account).await,
AccountCommand::Vote { event_id, answers } => vote_command(&account, event_id, answers).await,
AccountCommand::UnspentOutputs => unspent_outputs_command(account).await,
AccountCommand::Vote { event_id, answers } => vote_command(account, event_id, answers).await,
AccountCommand::StopParticipating { event_id } => {
stop_participating_command(&account, event_id).await
stop_participating_command(account, event_id).await
}
AccountCommand::ParticipationOverview { event_ids } => {
let event_ids = (!event_ids.is_empty()).then_some(event_ids);
participation_overview_command(&account, event_ids).await
participation_overview_command(account, event_ids).await
}
AccountCommand::VotingPower => voting_power_command(&account).await,
AccountCommand::VotingPower => voting_power_command(account).await,
AccountCommand::IncreaseVotingPower { amount } => {
increase_voting_power_command(&account, amount).await
increase_voting_power_command(account, amount).await
}
AccountCommand::DecreaseVotingPower { amount } => {
decrease_voting_power_command(&account, amount).await
decrease_voting_power_command(account, amount).await
}
AccountCommand::VotingOutput => voting_output_command(&account).await,
AccountCommand::VotingOutput => voting_output_command(account).await,
}
.unwrap_or_else(|err| {
println_log_error!("{err}");
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl NetworkInfo {
}

pub fn with_tangle_time(mut self, tangle_time: u64) -> Self {
self.tangle_time = Some(tangle_time.into());
self.tangle_time = Some(tangle_time);
self
}
}
2 changes: 1 addition & 1 deletion sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ClientInner {
/// Returns the information of committee members at the given epoch index. If epoch index is not provided, the
/// current committee members are returned.
/// GET /api/core/v3/committee/?epochIndex
pub async fn get_committee(&self, epoch_index: impl Into<Option<EpochIndex>>) -> Result<CommitteeResponse> {
pub async fn get_committee(&self, epoch_index: impl Into<Option<EpochIndex>> + Send) -> Result<CommitteeResponse> {
const PATH: &str = "api/core/v3/committee";

let epoch_index = epoch_index.into().map(|i| format!("epochIndex={i}"));
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/secret/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl SecretManage for MnemonicSecretManager {
let public_key = private_key.public_key();
let signature = private_key.sign(msg);

Ok(Ed25519Signature::new(public_key.into(), signature))
Ok(Ed25519Signature::new(public_key, signature))
}

async fn sign_secp256k1_ecdsa(
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/secret/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl SecretManage for PrivateKeySecretManager {
let public_key = self.0.public_key();
let signature = self.0.sign(msg);

Ok(Ed25519Signature::new(public_key.into(), signature))
Ok(Ed25519Signature::new(public_key, signature))
}

async fn sign_secp256k1_ecdsa(
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/stronghold/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl SecretManage for StrongholdAdapter {
.delete_secret(derive_location.record_path())
.map_err(Error::from)?;

Ok(Ed25519Signature::new(public_key.into(), signature))
Ok(Ed25519Signature::new(public_key, signature))
}

async fn sign_secp256k1_ecdsa(
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/core/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub(crate) mod dto {
}
}

Ok(BlockWrapper::new(
Ok(Self::new(
dto.protocol_version,
dto.network_id,
dto.issuing_time,
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/rand/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn rand_ed25519_signature() -> Ed25519Signature {
let public_key = private_key.public_key();
let signature = private_key.sign(&rand_bytes(64));

Ed25519Signature::new(public_key.into(), signature)
Ed25519Signature::new(public_key, signature)
}

pub fn rand_signature() -> Signature {
Expand Down
12 changes: 6 additions & 6 deletions sdk/src/types/block/slot/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ impl SlotIndex {

/// Gets the slot index of a unix timestamp.
/// Slots are counted starting from `1` with `0` being reserved for times before the genesis.
pub fn from_timestamp(timestamp: u64, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> SlotIndex {
pub fn from_timestamp(timestamp: u64, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> Self {
timestamp
.checked_sub(genesis_unix_timestamp as u64)
.checked_sub(genesis_unix_timestamp)
.map(|elapsed| (elapsed / slot_duration_in_seconds as u64) + 1)
.unwrap_or_default()
.into()
Expand All @@ -73,7 +73,7 @@ impl SlotIndex {
pub fn to_timestamp(self, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> u64 {
self.0
.checked_sub(1)
.map(|adjusted_slot| (adjusted_slot * slot_duration_in_seconds as u64) + genesis_unix_timestamp as u64)
.map(|adjusted_slot| (adjusted_slot * slot_duration_in_seconds as u64) + genesis_unix_timestamp)
.unwrap_or_default()
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ mod test {
let protocol_params = ProtocolParameters::default();

// Timestamp before the genesis
let timestamp = protocol_params.genesis_unix_timestamp() as u64 - 100;
let timestamp = protocol_params.genesis_unix_timestamp() - 100;
let slot_index = protocol_params.slot_index(timestamp);
assert_eq!(*slot_index, 0);
assert_eq!(
Expand All @@ -142,7 +142,7 @@ mod test {
);

// Genesis timestamp
let timestamp = protocol_params.genesis_unix_timestamp() as u64;
let timestamp = protocol_params.genesis_unix_timestamp();
let slot_index = protocol_params.slot_index(timestamp);
assert_eq!(*slot_index, 1);
assert_eq!(
Expand All @@ -154,7 +154,7 @@ mod test {
);

// Timestamp 5 seconds after slot 100 starts
let timestamp = protocol_params.genesis_unix_timestamp() as u64
let timestamp = protocol_params.genesis_unix_timestamp()
+ (99 * protocol_params.slot_duration_in_seconds() as u64) // Add 99 because the slots are 1-indexed
+ 5;
let slot_index = protocol_params.slot_index(timestamp);
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/utils/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub mod boxed_slice_prefix {
T: Serialize,
{
let mut seq = serializer.serialize_seq(Some(value.len()))?;
for e in value.into_iter() {
for e in value.iter() {
seq.serialize_element(e)?;
}
seq.end()
Expand Down
4 changes: 2 additions & 2 deletions sdk/tests/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn dto_mismatch_version() {
let protocol_parameters = ProtocolParameters::default();
let protocol_parameters_hash = protocol_parameters.hash();
let slot_index = 11_u64;
let issuing_time = protocol_parameters.genesis_unix_timestamp() as u64
let issuing_time = protocol_parameters.genesis_unix_timestamp()
+ (slot_index - 1) * protocol_parameters.slot_duration_in_seconds() as u64;
let network_id = protocol_parameters.network_id();
let protocol_version = 4;
Expand Down Expand Up @@ -168,7 +168,7 @@ fn dto_mismatch_network_id() {
let protocol_parameters = ProtocolParameters::default();
let protocol_parameters_hash = protocol_parameters.hash();
let slot_index = 11_u64;
let issuing_time = protocol_parameters.genesis_unix_timestamp() as u64
let issuing_time = protocol_parameters.genesis_unix_timestamp()
+ (slot_index - 1) * protocol_parameters.slot_duration_in_seconds() as u64;
let network_id = network_name_to_id("invalid-network");
let block_dto_json = serde_json::json!({
Expand Down

0 comments on commit 5192a45

Please sign in to comment.