Skip to content

Commit

Permalink
Fix clippy (#597)
Browse files Browse the repository at this point in the history
* Run `cargo clippy --fix`

* Run `cargo clippy --fix`

* Add clippy flags

* Cargo fmt
  • Loading branch information
ark930 authored May 22, 2022
1 parent ae18bb7 commit c7cf638
Show file tree
Hide file tree
Showing 28 changed files with 208 additions and 207 deletions.
33 changes: 33 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# An auto defined `clippy` feature was introduced,
# but it was found to clash with user defined features,
# so was renamed to `cargo-clippy`.
#
# If you want standard clippy run:
# RUSTFLAGS= cargo clippy
[target.'cfg(feature = "cargo-clippy")']
rustflags = [
"-Aclippy::all",
"-Dclippy::correctness",
"-Aclippy::if-same-then-else",
"-Aclippy::clone-double-ref",
"-Dclippy::complexity",
"-Aclippy::clone_on_copy", # Too common
"-Aclippy::needless_lifetimes", # Backward compat?
"-Aclippy::zero-prefixed-literal", # 00_1000_000
"-Aclippy::type_complexity", # raison d'etre
"-Aclippy::nonminimal-bool", # maybe
"-Aclippy::borrowed-box", # Reasonable to fix this one
"-Aclippy::too-many-arguments", # (Turning this on would lead to)
"-Aclippy::unnecessary_cast", # Types may change
"-Aclippy::identity-op", # One case where we do 0 +
"-Aclippy::useless_conversion", # Types may change
"-Aclippy::unit_arg", # styalistic.
"-Aclippy::option-map-unit-fn", # styalistic
"-Aclippy::bind_instead_of_map", # styalistic
"-Aclippy::erasing_op", # E.g. 0 * DOLLARS
"-Aclippy::eq_op", # In tests we test equality.
"-Aclippy::while_immutable_condition", # false positives
"-Aclippy::needless_option_as_deref", # false positives
"-Aclippy::derivable_impls", # false positives
]
17 changes: 6 additions & 11 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn get_exec_name() -> Option<String> {
}

fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
let id = if id == "" {
let id = if id.is_empty() {
let n = get_exec_name().unwrap_or_default();

["bifrost"]
Expand Down Expand Up @@ -175,7 +175,7 @@ impl SubstrateCli for Cli {
feature = "with-bifrost-runtime"
))]
{
return &bifrost_polkadot_runtime::VERSION;
&bifrost_polkadot_runtime::VERSION
}
#[cfg(not(any(
feature = "with-bifrost-polkadot-runtime",
Expand Down Expand Up @@ -218,8 +218,7 @@ impl SubstrateCli for RelayChainCli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name().to_string()].iter())
.load_spec(id)
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
Expand Down Expand Up @@ -319,13 +318,11 @@ pub fn run() -> Result<()> {
let para_id =
node_service::chain_spec::RelayExtensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
.ok_or_else(|| "Could not find parachain ID in chain-spec.")?;
.ok_or("Could not find parachain ID in chain-spec.")?;

let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name().to_string()]
.iter()
.chain(cli.relaychain_args.iter()),
[RelayChainCli::executable_name()].iter().chain(cli.relaychain_args.iter()),
);

let id = ParaId::from(para_id);
Expand Down Expand Up @@ -476,9 +473,7 @@ pub fn run() -> Result<()> {
runner.sync_run(|config| {
let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name().to_string()]
.iter()
.chain(cli.relaychain_args.iter()),
[RelayChainCli::executable_name()].iter().chain(cli.relaychain_args.iter()),
);

let polkadot_config = SubstrateCli::create_configuration(
Expand Down
6 changes: 3 additions & 3 deletions node/primitives/src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,21 +348,21 @@ impl CurrencyId {

pub fn to_token(&self) -> Result<Self, ()> {
match self {
Self::VToken(symbol) => Ok(Self::Token(symbol.clone())),
Self::VToken(symbol) => Ok(Self::Token(*symbol)),
_ => Err(()),
}
}

pub fn to_vtoken(&self) -> Result<Self, ()> {
match self {
Self::Token(symbol) => Ok(Self::VToken(symbol.clone())),
Self::Token(symbol) => Ok(Self::VToken(*symbol)),
_ => Err(()),
}
}

pub fn to_vstoken(&self) -> Result<Self, ()> {
match self {
Self::Token(symbol) => Ok(Self::VSToken(symbol.clone())),
Self::Token(symbol) => Ok(Self::VSToken(*symbol)),
_ => Err(()),
}
}
Expand Down
5 changes: 2 additions & 3 deletions node/primitives/src/salp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ where
}

pub fn to_rpc(&self) -> RpcContributionStatus {
let rpc_status = match self {
match self {
Self::Idle => RpcContributionStatus::Idle,
Self::Contributing(_) => RpcContributionStatus::Contributing,
Self::Refunded => RpcContributionStatus::Refunded,
Self::Unlocked => RpcContributionStatus::Unlocked,
Self::Redeemed => RpcContributionStatus::Redeemed,
Self::MigrateToIdle => RpcContributionStatus::MigratedIdle,
};
rpc_status
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
client.clone(),
)));

io.extend_with(ZenlinkProtocolApi::to_delegate(ZenlinkProtocol::new(client.clone())));
io.extend_with(ZenlinkProtocolApi::to_delegate(ZenlinkProtocol::new(client)));

io
}
Expand All @@ -119,7 +119,7 @@ where
let FullDeps { client, pool, deny_unsafe } = deps;

io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client)));

io
}
6 changes: 3 additions & 3 deletions node/service/src/chain_spec/bifrost_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn bifrost_genesis(
.map(|(acc, aura, _)| {
(
acc.clone(), // account id
acc.clone(), // validator id
acc, // validator id
bifrost_kusama_runtime::SessionKeys { aura }, // session keys
)
})
Expand Down Expand Up @@ -193,7 +193,7 @@ fn development_config_genesis(id: ParaId) -> GenesisConfig {
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT() / 4))
.map(|x| (x, 0u32, 100u32, ENDOWMENT() / 4))
.collect();
let tokens = endowed_accounts
.iter()
Expand Down Expand Up @@ -276,7 +276,7 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT() / 4))
.map(|x| (x, 0u32, 100u32, ENDOWMENT() / 4))
.collect();
let tokens = endowed_accounts
.iter()
Expand Down
6 changes: 3 additions & 3 deletions node/service/src/chain_spec/bifrost_polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn bifrost_polkadot_genesis(
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc.clone(), // validator id
acc, // validator id
bifrost_polkadot_runtime::SessionKeys { aura }, // session keys
)
})
Expand All @@ -119,7 +119,7 @@ fn development_config_genesis(id: ParaId) -> GenesisConfig {
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT() / 4))
.map(|x| (x, 0u32, 100u32, ENDOWMENT() / 4))
.collect();

bifrost_polkadot_genesis(
Expand Down Expand Up @@ -171,7 +171,7 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT() / 4))
.map(|x| (x, 0u32, 100u32, ENDOWMENT() / 4))
.collect();

bifrost_polkadot_genesis(
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/collator_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
&config,
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor,
)?;
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/collator_polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
&config,
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor,
)?;
Expand Down
6 changes: 3 additions & 3 deletions pallets/flexible-fee/src/fee_dealer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<T: Config> FeeDealer<T::AccountId, PalletBalanceOf<T>, CurrencyIdOf<T>>
let native_is_enough = <<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::free_balance(who)
.checked_sub(&(fee + native_existential_deposit.into()))
.checked_sub(&(fee + native_existential_deposit))
.map_or(false, |new_free_balance| {
<<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
Expand Down Expand Up @@ -104,8 +104,8 @@ impl<T: Config> FeeDealer<T::AccountId, PalletBalanceOf<T>, CurrencyIdOf<T>>
T::FeeDealer::ensure_can_charge_fee(who, fee, withdraw_reason)?;

match fee_sign {
true => Ok((T::AlternativeFeeCurrencyId::get(), fee_amount.into())),
false => Ok((T::NativeCurrencyId::get(), fee_amount.into())),
true => Ok((T::AlternativeFeeCurrencyId::get(), fee_amount)),
false => Ok((T::NativeCurrencyId::get(), fee_amount)),
}
}
}
20 changes: 10 additions & 10 deletions pallets/flexible-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub mod pallet {
UserFeeChargeOrderList::<T>::remove(&who);
}

Ok(().into())
Ok(())
}
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ where

let rs;
// if the user has enough BNC for fee
if fee_sign == false {
if !fee_sign {
rs = match T::Currency::withdraw(
who,
fee,
Expand Down Expand Up @@ -297,7 +297,7 @@ where
// refund to the the account that paid the fees. If this fails, the
// account might have dropped below the existential balance. In
// that case we don't refund anything.
let refund_imbalance = T::Currency::deposit_into_existing(&who, refund_amount)
let refund_imbalance = T::Currency::deposit_into_existing(who, refund_amount)
.unwrap_or_else(|_| PositiveImbalanceOf::<T>::zero());
// merge the imbalance caused by paying the fees and refunding parts of it again.
let adjusted_paid = paid
Expand Down Expand Up @@ -340,7 +340,7 @@ impl<T: Config> FeeDealer<T::AccountId, PalletBalanceOf<T>, CurrencyIdOf<T>> for
let native_is_enough = <<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::free_balance(who)
.checked_sub(&(fee + existential_deposit.into()))
.checked_sub(&(fee + existential_deposit))
.map_or(false, |new_free_balance| {
<<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
Expand Down Expand Up @@ -380,11 +380,11 @@ impl<T: Config> FeeDealer<T::AccountId, PalletBalanceOf<T>, CurrencyIdOf<T>> for
T::DexOperator::get_amount_in_by_path(amount_out, &path).map_or(vec![0], |v| v);

if T::DexOperator::inner_swap_assets_for_exact_assets(
&who,
who,
amount_out,
amount_in_max,
&path,
&who,
who,
)
.is_ok()
{
Expand Down Expand Up @@ -425,16 +425,16 @@ impl<T: Config> FeeDealer<T::AccountId, PalletBalanceOf<T>, CurrencyIdOf<T>> for
<T as frame_system::Config>::AccountId,
>>::free_balance(who);

if native_balance >= fee.into() {
fee_token_amount_out = fee.into();
if native_balance >= fee {
fee_token_amount_out = fee;
break;
}
} else {
// If it is other assets
let asset_balance = T::MultiCurrency::total_balance(currency_id, who);
let token_asset_id: AssetId = AssetId::try_from(currency_id)
.map_err(|_| DispatchError::Other("Conversion Error"))?;
let path = vec![native_asset_id.clone(), token_asset_id];
let path = vec![native_asset_id, token_asset_id];

let amount_vec = T::DexOperator::get_amount_in_by_path(amount_out, &path)?;
let amount_in = amount_vec[0];
Expand All @@ -447,6 +447,6 @@ impl<T: Config> FeeDealer<T::AccountId, PalletBalanceOf<T>, CurrencyIdOf<T>> for
}
}
}
Ok((fee_token_id_out, fee_token_amount_out.into()))
Ok((fee_token_id_out, fee_token_amount_out))
}
}
2 changes: 1 addition & 1 deletion pallets/flexible-fee/src/misc_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<AccountId, CurrencyId, Balance, Call> FeeDeductor<AccountId, CurrencyId, Ba
)*
);

return Err(DispatchError::Other("Failed to deduct extra fee."));
Err(DispatchError::Other("Failed to deduct extra fee."))
}
}

Expand Down
20 changes: 8 additions & 12 deletions pallets/lightening-redeem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,14 @@ pub mod pallet {
let (start, end) = Self::get_start_and_end_release_block();
// relsease fixed amount every day if within release interval and has enough balance in
// the pool account
if (n <= end) & (n > start) {
if (n - start) % BLOCKS_PER_DAY.into() == Zero::zero() {
let ksm = CurrencyId::Token(TokenSymbol::KSM);
let pool_account: AccountIdOf<T> = T::PalletId::get().into_account();
let releae_per_day = Self::get_token_release_per_round();
let total_amount = Self::get_pool_amount().saturating_add(releae_per_day);

if T::MultiCurrency::ensure_can_withdraw(ksm, &pool_account, total_amount)
.is_ok()
{
PoolAmount::<T>::mutate(|amt| *amt = total_amount);
}
if (n <= end) & (n > start) && (n - start) % BLOCKS_PER_DAY.into() == Zero::zero() {
let ksm = CurrencyId::Token(TokenSymbol::KSM);
let pool_account: AccountIdOf<T> = T::PalletId::get().into_account();
let releae_per_day = Self::get_token_release_per_round();
let total_amount = Self::get_pool_amount().saturating_add(releae_per_day);

if T::MultiCurrency::ensure_can_withdraw(ksm, &pool_account, total_amount).is_ok() {
PoolAmount::<T>::mutate(|amt| *amt = total_amount);
}
}
T::WeightInfo::on_initialize()
Expand Down
1 change: 0 additions & 1 deletion pallets/lightening-redeem/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ impl ExtBuilder {
orml_tokens::GenesisConfig::<Runtime> {
balances: self
.endowed_accounts
.clone()
.into_iter()
.filter(|(_, currency_id, _)| *currency_id != BNC)
.collect::<Vec<_>>(),
Expand Down
Loading

0 comments on commit c7cf638

Please sign in to comment.