Skip to content

Commit

Permalink
Merge pull request #261 from Fair-Squares/fix-clippy
Browse files Browse the repository at this point in the history
fix clippy warnings - M5
  • Loading branch information
cuteolaf committed Mar 14, 2023
2 parents 3f59df5 + 662b582 commit 2fc8882
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 123 deletions.
8 changes: 4 additions & 4 deletions assets/pallet_template/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: TemplateModule Something (r:0 w:1)
/// The range of component `s` is `[0, 100]`.
fn do_something(_s: u32, ) -> Weight {
Weight::from_ref_time(15_009_000 as u64)
.saturating_add(T::DbWeight::get().writes(1 as u64))
Weight::from_ref_time(15_009_000_u64)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

Expand All @@ -71,7 +71,7 @@ impl WeightInfo for () {
// Storage: TemplateModule Something (r:0 w:1)
/// The range of component `s` is `[0, 100]`.
fn do_something(_s: u32, ) -> Weight {
Weight::from_ref_time(15_009_000 as u64)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
Weight::from_ref_time(15_009_000_u64)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
4 changes: 2 additions & 2 deletions pallets/asset_management/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use sp_core::H256;
use sp_runtime::traits::{StaticLookup, Zero};
impl<T: Config> Pallet<T> {
pub fn approve_representative_role(origin: OriginFor<T>, who: T::AccountId) -> DispatchResult {
let caller = ensure_signed(origin.clone())?;
let caller = ensure_signed(origin)?;

let mut representative = Roles::Pallet::<T>::get_pending_representatives(&who).unwrap();
Roles::RepApprovalList::<T>::remove(&who);
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<T: Config> Pallet<T> {
let proposal_hash = T::Hashing::hash_of(&call_dispatch);
let proposal_encoded: Vec<u8> = call_dispatch.encode();
Dem::Pallet::<T>::note_preimage(origin, proposal_encoded).ok();

proposal_hash
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/asset_management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
//! - 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
//! 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
//! 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
//! tenant. When the tenant finally pays the guaranty_deposit,his account is connected to the
//! asset through `link_tenant_to_asset` and this marks the start of his contract with the owners.
//! asset through `link_tenant_to_asset` and this marks the start of his contract with the owners.
//!
//! * `link_tenant_to_asset` - Call used as a proposal to link an accepted tenant with an existing
//! asset.
Expand Down
101 changes: 51 additions & 50 deletions pallets/bidding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ pub mod pallet {
type NewAssetScanPeriod: Get<Self::BlockNumber>;
}

pub type HousingFundAccount<T> = Housing_Fund::AccountIdOf<T>;
pub type HousingFundBalance<T> = Housing_Fund::BalanceOf<T>;
pub type EligibleContribution<T> = (HousingFundAccount<T>, HousingFundBalance<T>, HousingFundBalance<T>);
pub type UserBalance<T> = (HousingFundAccount<T>, HousingFundBalance<T>);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
Expand All @@ -80,29 +85,29 @@ pub mod pallet {
HousingFundNotEnough(
T::NftCollectionId,
T::NftItemId,
Housing_Fund::BalanceOf<T>,
HousingFundBalance<T>,
BlockNumberOf<T>,
),
/// Bidding on the house is successful
HouseBiddingSucceeded(
T::NftCollectionId,
T::NftItemId,
Housing_Fund::BalanceOf<T>,
HousingFundBalance<T>,
BlockNumberOf<T>,
),
/// Bidding on the house failed
HouseBiddingFailed(
T::NftCollectionId,
T::NftItemId,
Housing_Fund::BalanceOf<T>,
HousingFundBalance<T>,
BlockNumberOf<T>,
Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)>,
Vec<UserBalance<T>>,
),
/// Failed to assemble a list of investors for an onboarded asset
FailedToAssembleInvestors(
T::NftCollectionId,
T::NftItemId,
Housing_Fund::BalanceOf<T>,
HousingFundBalance<T>,
BlockNumberOf<T>,
),
/// No new onboarded houses found
Expand All @@ -111,7 +116,7 @@ pub mod pallet {
NotEnoughAmongEligibleInvestors(
T::NftCollectionId,
T::NftItemId,
Housing_Fund::BalanceOf<T>,
HousingFundBalance<T>,
BlockNumberOf<T>,
),
/// No new finalised houses found
Expand All @@ -123,14 +128,14 @@ pub mod pallet {
SellAssetToInvestorsFailed(T::NftCollectionId, T::NftItemId, BlockNumberOf<T>),

/// Processing an asset
ProcessingAsset(T::NftCollectionId, T::NftItemId, Housing_Fund::BalanceOf<T>),
ProcessingAsset(T::NftCollectionId, T::NftItemId, HousingFundBalance<T>),

/// Potential owners list successfully created
InvestorListCreationSuccessful(
T::NftCollectionId,
T::NftItemId,
Housing_Fund::BalanceOf<T>,
Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)>,
HousingFundBalance<T>,
Vec<UserBalance<T>>,
),
}

Expand Down Expand Up @@ -333,9 +338,9 @@ impl<T: Config> Pallet<T> {
/// - no less than T::MinimumSharePerInvestor share per investor
/// The total contribution from the investor list should be equal to the asset's price
fn create_investor_list(
amount: Housing_Fund::BalanceOf<T>,
) -> Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)> {
let mut result: Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)> =
amount: HousingFundBalance<T>,
) -> Vec<UserBalance<T>> {
let mut result: Vec<UserBalance<T>> =
Vec::new();
let percent = Self::u64_to_balance_option(100).unwrap();
// We get contributions following the min-max rules
Expand Down Expand Up @@ -384,16 +389,12 @@ impl<T: Config> Pallet<T> {

/// Get a list of tuple of account id and their contribution set at the same amount
fn get_common_investor_distribution(
amount: Housing_Fund::BalanceOf<T>,
common_share: Housing_Fund::BalanceOf<T>,
eligible_contributions: Vec<(
Housing_Fund::AccountIdOf<T>,
Housing_Fund::BalanceOf<T>,
Housing_Fund::BalanceOf<T>,
)>,
) -> Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)> {
amount: HousingFundBalance<T>,
common_share: HousingFundBalance<T>,
eligible_contributions: Vec<EligibleContribution<T>>,
) -> Vec<UserBalance<T>> {
let percent = Self::u64_to_balance_option(100).unwrap();
let mut result: Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)> =
let mut result: Vec<UserBalance<T>> =
Vec::new();

for item in eligible_contributions.iter() {
Expand All @@ -406,17 +407,17 @@ impl<T: Config> Pallet<T> {
/// Get a list of tuple of account id and their contribution with different values
/// The contribubtions follow the min-max rule of the amount
fn get_investor_distribution(
amount: Housing_Fund::BalanceOf<T>,
amount: HousingFundBalance<T>,
eligible_contributions: Vec<(
Housing_Fund::AccountIdOf<T>,
Housing_Fund::BalanceOf<T>,
Housing_Fund::BalanceOf<T>,
HousingFundAccount<T>,
HousingFundBalance<T>,
HousingFundBalance<T>,
)>,
) -> Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)> {
) -> Vec<UserBalance<T>> {
let percent = Self::u64_to_balance_option(100).unwrap();
let zero_percent = Self::u64_to_balance_option(0).unwrap();
let mut actual_percentage: Housing_Fund::BalanceOf<T> = percent;
let mut result: Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>)> =
let mut actual_percentage: HousingFundBalance<T> = percent;
let mut result: Vec<UserBalance<T>> =
Vec::new();
let mut count: u64 = 1;
let contributions_length: u64 = eligible_contributions.len() as u64;
Expand Down Expand Up @@ -476,24 +477,24 @@ impl<T: Config> Pallet<T> {
/// - a list of tuples (AccountId, Share, Amount) following the min-max share rule
/// - the total amount of the list
fn get_eligible_investors_contribution(
amount: Housing_Fund::BalanceOf<T>,
amount: HousingFundBalance<T>,
) -> (
Housing_Fund::BalanceOf<T>,
Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::BalanceOf<T>, Housing_Fund::BalanceOf<T>)>,
HousingFundBalance<T>,
Vec<(HousingFundAccount<T>, HousingFundBalance<T>, HousingFundBalance<T>)>,
) {
let mut result: Vec<(
Housing_Fund::AccountIdOf<T>,
Housing_Fund::BalanceOf<T>,
Housing_Fund::BalanceOf<T>,
HousingFundAccount<T>,
HousingFundBalance<T>,
HousingFundBalance<T>,
)> = Vec::new();
let contributions = Housing_Fund::Pallet::<T>::get_contributions();
let mut ordered_account_id_list: Vec<Housing_Fund::AccountIdOf<T>> = Vec::new();
let mut ordered_account_id_list: Vec<HousingFundAccount<T>> = Vec::new();
let mut ordered_contributions: Vec<(
Housing_Fund::AccountIdOf<T>,
HousingFundAccount<T>,
Housing_Fund::Contribution<T>,
)> = Vec::new();
let zero_percent = Self::u64_to_balance_option(0).unwrap();
let mut total_share: Housing_Fund::BalanceOf<T> = Self::u64_to_balance_option(0).unwrap();
let mut total_share: HousingFundBalance<T> = Self::u64_to_balance_option(0).unwrap();

// the contributions are ordered by block number ascending order
for _ in 0..contributions.len() {
Expand Down Expand Up @@ -521,11 +522,11 @@ impl<T: Config> Pallet<T> {

/// Get the oldest contribution which accountId is not present in the ordered_list
fn get_oldest_contribution(
ordered_list: Vec<Housing_Fund::AccountIdOf<T>>,
contributions: Vec<(Housing_Fund::AccountIdOf<T>, Housing_Fund::Contribution<T>)>,
) -> (Housing_Fund::AccountIdOf<T>, Housing_Fund::Contribution<T>) {
ordered_list: Vec<HousingFundAccount<T>>,
contributions: Vec<(HousingFundAccount<T>, Housing_Fund::Contribution<T>)>,
) -> (HousingFundAccount<T>, Housing_Fund::Contribution<T>) {
let mut contributions_cut: Vec<(
Housing_Fund::AccountIdOf<T>,
HousingFundAccount<T>,
Housing_Fund::Contribution<T>,
)> = Vec::new();

Expand All @@ -549,11 +550,11 @@ impl<T: Config> Pallet<T> {

// Get the share of the house price from a given contribution
fn get_investor_share(
amount: Housing_Fund::BalanceOf<T>,
amount: HousingFundBalance<T>,
contribution: Housing_Fund::Contribution<T>,
) -> (Housing_Fund::BalanceOf<T>, Housing_Fund::BalanceOf<T>) {
let mut share: Housing_Fund::BalanceOf<T> = Self::u64_to_balance_option(0).unwrap();
let mut value: Housing_Fund::BalanceOf<T> = Self::u64_to_balance_option(0).unwrap();
) -> (HousingFundBalance<T>, HousingFundBalance<T>) {
let mut share: HousingFundBalance<T> = Self::u64_to_balance_option(0).unwrap();
let mut value: HousingFundBalance<T> = Self::u64_to_balance_option(0).unwrap();
// If the available amount is greater than the maximum amount, then the maximum amount is
// returned
if contribution.available_balance >=
Expand All @@ -576,20 +577,20 @@ impl<T: Config> Pallet<T> {
}

fn get_amount_percentage(
amount: Housing_Fund::BalanceOf<T>,
amount: HousingFundBalance<T>,
percentage: u64,
) -> Housing_Fund::BalanceOf<T> {
) -> HousingFundBalance<T> {
amount * Self::u64_to_balance_option(percentage).unwrap() /
Self::u64_to_balance_option(100).unwrap()
}

fn convert_balance(amount: Onboarding::BalanceOf<T>) -> Option<Housing_Fund::BalanceOf<T>> {
fn convert_balance(amount: Onboarding::BalanceOf<T>) -> Option<HousingFundBalance<T>> {
let value: Option<u128> = amount.try_into().ok();
let result: Option<Housing_Fund::BalanceOf<T>> = value.unwrap().try_into().ok();
let result: Option<HousingFundBalance<T>> = value.unwrap().try_into().ok();
result
}

pub fn u64_to_balance_option(input: u64) -> Option<Housing_Fund::BalanceOf<T>> {
pub fn u64_to_balance_option(input: u64) -> Option<HousingFundBalance<T>> {
input.try_into().ok()
}
}
12 changes: 6 additions & 6 deletions pallets/payment/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn request_payment() -> Weight {
Weight::from_ref_time(17_000_000)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: Payment Payment (r:1 w:1)
// Storage: Assets Accounts (r:2 w:2)
Expand All @@ -109,8 +109,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Payment ScheduledTasks (r:1 w:1)
fn remove_task() -> Weight {
Weight::from_ref_time(4_000_000)
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ impl WeightInfo for () {
fn request_payment() -> Weight {
Weight::from_ref_time(17_000_000)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: Payment Payment (r:1 w:1)
// Storage: Assets Accounts (r:2 w:2)
Expand All @@ -179,7 +179,7 @@ impl WeightInfo for () {
// Storage: Payment ScheduledTasks (r:1 w:1)
fn remove_task() -> Weight {
Weight::from_ref_time(4_000_000)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
9 changes: 2 additions & 7 deletions pallets/roles/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,18 @@ pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type Idle<T> = (Vec<HouseSeller<T>>, Vec<Servicer<T>>);

///This enum contains the roles selectable at account creation
#[derive(Clone, Encode, Decode, PartialEq, Eq, TypeInfo, Copy)]
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo, Copy)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum Accounts {
INVESTOR,
#[default]
SELLER,
TENANT,
SERVICER,
NOTARY,
REPRESENTATIVE,
}

impl Default for Accounts {
fn default() -> Self {
Accounts::SELLER
}
}

//-------------------------------------------------------------------------------------
//-------------INVESTOR STRUCT DECLARATION & IMPLEMENTATION_BEGIN----------------------
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo)]
Expand Down
8 changes: 4 additions & 4 deletions pallets/tenancy/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ impl<T: Config> Pallet<T> {
// in the Share_distributor --> Virtual storage --> Ownership struct
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 = 1 + val0.rent_nbr;
val0.rent_nbr += 1;
*val = Some(val0);
});
}
Expand All @@ -72,7 +72,7 @@ impl<T: Config> Pallet<T> {
let tenant = ensure_signed(from.clone())?;

//Accept and pay the guaranty
Payment::Pallet::<T>::accept_and_pay(from.clone(), virtual_account.clone()).ok();
Payment::Pallet::<T>::accept_and_pay(from, virtual_account.clone()).ok();
let origin2 = frame_system::RawOrigin::Signed(virtual_account.clone());

//Change payment state in Asset_Management storage
Expand Down
Loading

0 comments on commit 2fc8882

Please sign in to comment.