Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed Feb 24, 2023
1 parent e2daab0 commit fa9aad8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
47 changes: 23 additions & 24 deletions pallets/asset_management/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<T: Config> Pallet<T> {
//Check if we're dealing with an already registered representative
let registered = Roles::RepresentativeLog::<T>::contains_key(&who);

if registered == false {
if !registered {
representative.activated = true;
representative.assets_accounts.clear();
representative.assets_accounts.push(caller);
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<T: Config> Pallet<T> {
}
}

if check0 == false {
if !check0 {
//Set the representative as a registrar
Ident::Pallet::<T>::add_registrar(origin, who2).ok();

Expand All @@ -63,7 +63,7 @@ impl<T: Config> Pallet<T> {
let fees = bals0.ident_bal;
Ident::Pallet::<T>::set_fee(origin2, index, fees).ok();

if registered == false {
if !registered {
//Update Rep number if not yet a registered Representative
index += 1;
Roles::RepNumber::<T>::put(index);
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<T: Config> Pallet<T> {

//Store payment details
let details = Payment::Pallet::<T>::get_payment_details(&from, &creator).unwrap();
GuarantyPayment::<T>::insert(from.clone(), creator.clone(), details);
GuarantyPayment::<T>::insert(from, creator, details);

Ok(())
}
Expand Down Expand Up @@ -171,7 +171,7 @@ impl<T: Config> Pallet<T> {
let rent = bals.roles_bal;
bals = BalanceType::<T>::convert_to_balance(rent1);
let year_rent = bals.roles_bal;
val0.rent = rent.into();
val0.rent = rent;
val0.asset_account = Some(asset_account);
val0.remaining_rent = year_rent;
val0.remaining_payments = time as u8;
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<T: Config> Pallet<T> {
match Dem::Pallet::<T>::note_preimage(origin, proposal_encoded) {
Ok(_) => (),
Err(x) if x == Error::<T>::DuplicatePreimage.into() => (),
Err(x) => panic!("{:?}", x),
Err(x) => panic!("{x:?}"),
}
proposal_hash
}
Expand Down Expand Up @@ -306,7 +306,7 @@ impl<T: Config> Pallet<T> {
let tenants = Roles::Pallet::<T>::tenant_list();
for i in tenants {
let tenant = Roles::Pallet::<T>::tenants(i).unwrap();
if !tenant.asset_account.is_none() {
if tenant.asset_account.is_some() {
let time = <T as Config>::Lease::get();
let remaining_p = tenant.remaining_payments;
let contract_begin = tenant.contract_start;
Expand All @@ -317,7 +317,7 @@ impl<T: Config> Pallet<T> {

//Calculate rent per block
let total_blocks = <T as Config>::ContractLength::get();
let mut rpb = Self::blocknumber_to_u128(total_blocks.clone()).unwrap();
let mut rpb = Self::blocknumber_to_u128(total_blocks).unwrap();
let mut rpb_float = rpb as f64;
rpb_float = (rent_float / rpb_float).round();
rpb = rpb_float as u128;
Expand All @@ -327,7 +327,7 @@ impl<T: Config> Pallet<T> {
let amount_due = blocks.saturating_mul(rpb);

//check how many rents were payed
let payed = (time as u128 - remaining_p as u128) * rent.clone();
let payed = (time as u128 - remaining_p as u128) * rent;
let asset_account = tenant.asset_account.clone().unwrap();
let asset_account_free_balance =
<T as Config>::Currency::free_balance(&asset_account);
Expand All @@ -345,33 +345,32 @@ impl<T: Config> Pallet<T> {

//Get Asset_tokens infos
let token_id = infos.token_id;
let total_issuance =
Assetss::Pallet::<T>::total_supply(token_id.clone().into());
let total_issuance = Assetss::Pallet::<T>::total_supply(token_id.into());
let total_issuance_float =
Self::assets_bal_to_u128(total_issuance).unwrap() as f64;

//Remove maintenance fees from rent and convert it to f64
let maintenance = T::Maintenance::get() * rent1.clone();
let distribute = rent1.saturating_sub(maintenance.clone());
let maintenance = T::Maintenance::get() * rent1;
let distribute = rent1.saturating_sub(maintenance);

//Get the total amount to distribute
let distribute_float = (Self::manage_bal_to_u128(distribute.clone())
.unwrap() * infos.rent_nbr as u128) as f64;
let distribute_float = (Self::manage_bal_to_u128(distribute).unwrap() *
infos.rent_nbr as u128) as f64;

debug_assert!(distribute.clone() > Zero::zero());
debug_assert!(distribute.clone() < rent1.clone());
debug_assert!(maintenance.clone() < asset_account_free_balance);
debug_assert!(distribute > Zero::zero());
debug_assert!(distribute < rent1);
debug_assert!(maintenance < asset_account_free_balance);

//Reserve maintenance fees
let reservation =
<T as Config>::Currency::reserve(&asset_account, maintenance.into());
<T as Config>::Currency::reserve(&asset_account, maintenance);

//Emmit maintenance fee payment event
Self::deposit_event(Event::MaintenanceFeesPayment {
tenant: tenant.account_id.clone(),
when: now,
asset_account: tenant.asset_account.unwrap(),
amount: maintenance.clone(),
amount: maintenance,
});

debug_assert!(reservation.is_ok());
Expand All @@ -381,10 +380,10 @@ impl<T: Config> Pallet<T> {
//Get owner's share: we divide
//the owner's tokens by the total token issuance, and multiply the
// result by the total amount to be distributed.
let share = Assetss::Pallet::<T>::balance(token_id.clone().into(), &i);
let share = Assetss::Pallet::<T>::balance(token_id.into(), &i);
let share_float = Self::assets_bal_to_u128(share).unwrap() as f64 /
total_issuance_float;
let amount_float = share_float * distribute_float.clone();
let amount_float = share_float * distribute_float;
let bals0 = BalanceType::<T>::convert_to_balance(amount_float as u128);
let amount = bals0.manage_bal;
<T as Config>::Currency::transfer(
Expand All @@ -406,9 +405,9 @@ impl<T: Config> Pallet<T> {
//Now return the awaiting payment number to 0
let ownership_infos = Share::Virtual::<T>::iter_keys();
for (i, j) in ownership_infos {
let infos = Share::Pallet::<T>::virtual_acc(&i, &j).unwrap();
let infos = Share::Pallet::<T>::virtual_acc(i, j).unwrap();
if infos.virtual_account == asset_account {
Share::Virtual::<T>::mutate(i.clone(), j.clone(), |val| {
Share::Virtual::<T>::mutate(i, j, |val| {
let mut val0 = val.clone().unwrap();
val0.rent_nbr = 0;
*val = Some(val0);
Expand Down
17 changes: 6 additions & 11 deletions pallets/asset_management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! proposals:
//! - Admit a Tenant for a given asset.
//! - Evict a Tenant from a given asset.
//! The Representative has to submit a judgement about the tenant profile. This judgement
//! The Representative has to submit a judgement about the tenant profile. This judgement
//! will be considered by the owners before voting.
//! Representatives receive a judgement fee from the aspiring tenant.
//! A positive result of the referendum will send a guaranty_deposit payment request to the
Expand Down Expand Up @@ -505,7 +505,7 @@ pub mod pallet {
Share::Pallet::<T>::virtual_acc(collection, item).unwrap().virtual_account;

//Check that the caller is a stored virtual account
ensure!(caller == asset_account.clone(), Error::<T>::NotAnAssetAccount);
ensure!(caller == asset_account, Error::<T>::NotAnAssetAccount);

Onboarding::Houses::<T>::mutate(collection, item, |asset| {
let mut asset0 = asset.clone().unwrap();
Expand Down Expand Up @@ -593,7 +593,7 @@ pub mod pallet {
//Compare guaranty payment amount+fees with tenant free_balance
let guaranty = Self::calculate_guaranty(collection_id, asset_id);
let fee0 = Self::manage_bal_to_u128(T::RepFees::get()).unwrap();
let bals0 = BalanceType::<T>::convert_to_balance(guaranty.clone());
let bals0 = BalanceType::<T>::convert_to_balance(guaranty);
let fee1 = T::IncentivePercentage::get() * bals0.manage_bal;
let total_amount = guaranty + fee0 + Self::manage_bal_to_u128(fee1).unwrap();
let tenant_bal0: BalanceOf<T> = <T as Config>::Currency::free_balance(&tenant);
Expand All @@ -607,7 +607,7 @@ pub mod pallet {
ensure!(tenant0.is_some(), Error::<T>::NotATenant);
// Ensure that the tenant is registered
let tenant_infos = Roles::Pallet::<T>::tenants(tenant.clone()).unwrap();
ensure!(tenant_infos.registered == true, Error::<T>::NotARegisteredTenant);
ensure!(tenant_infos.registered, Error::<T>::NotARegisteredTenant);

let tenant0 = tenant0.unwrap();
match proposal {
Expand All @@ -627,13 +627,8 @@ pub mod pallet {
//provide judgement
let index = rep.index;
let target = T::Lookup::unlookup(tenant.clone());
Ident::Pallet::<T>::provide_judgement(
origin.clone(),
index.into(),
target,
judgement.clone(),
)
.ok();
Ident::Pallet::<T>::provide_judgement(origin.clone(), index, target, judgement)
.ok();
},
VoteProposals::Demotion => {
// Ensure that the tenant is linked to the asset
Expand Down
4 changes: 2 additions & 2 deletions pallets/roles/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ impl<T: Config> Pallet<T> {
let now = <frame_system::Pallet<T>>::block_number();
let rep_count = representatives.len() as u32;
for (index, account) in representatives.iter().enumerate() {
AccountsRolesLog::<T>::insert(&account, Accounts::REPRESENTATIVE);
AccountsRolesLog::<T>::insert(account, Accounts::REPRESENTATIVE);
RepresentativeLog::<T>::insert(
&account,
account,
Representative::<T> {
account_id: account.clone(),
age: now,
Expand Down

0 comments on commit fa9aad8

Please sign in to comment.