Skip to content

Commit

Permalink
Code base cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Oct 19, 2023
1 parent d65b361 commit 69f7f01
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 48 deletions.
14 changes: 2 additions & 12 deletions pallets/bidding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl<T: Config> Pallet<T> {
Roles::InvestorLog::<T>::iter().map(|x| x.0).collect_into(&mut investors);
investors.retain(|x|{
let status = Houses::Pallet::<T>::contributions(x.clone()).unwrap();
let contribution0 = Self::hfund_bal_to_u128(status.contributed_balance).unwrap();
let contribution = Self::u128_to_onboarding_bal(contribution0).unwrap();
let contribution = status.contributed_balance;

//user contributed more than 5% of asset_price
contribution > Percent::from_percent(5) * asset_price //should be minimun contribution calculated from asset price.
//ToDo: We also want to only include users that did not contributed to a purchase for y_blocks (to be defined).
Expand All @@ -39,16 +39,6 @@ impl<T: Config> Pallet<T> {

}

// Conversion of BalanceOf<T> to u128
pub fn hfund_bal_to_u128(input: Houses::BalanceOf<T>) -> Option<u128> {
input.try_into().ok()
}

// Conversion of BalanceOf<T> to u128
pub fn u128_to_onboarding_bal(input: u128) -> Option<Onboarding::BalanceOf<T>> {
input.try_into().ok()
}



}
Expand Down
4 changes: 1 addition & 3 deletions pallets/bidding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub use scale_info::{prelude::vec, TypeInfo};
pub use serde::{Deserialize, Serialize};

pub type BalanceOf<T> =
<<T as Onboarding::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type BalanceOf0<T> =
<<T as Houses::Config>::LocalCurrency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
<<T as Roles::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BlockNumberOf<T> = BlockNumberFor<T>;
12 changes: 6 additions & 6 deletions pallets/housing_fund/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<T: Config> Pallet<T> {
/// Check that the fund can afford the amount
pub fn check_available_fund(value: BalanceOf<T>) -> bool {
let fund_account = Self::fund_account_id();
let amount = T::LocalCurrency::free_balance(&fund_account);
let amount = <T as ROLES::Config>::Currency::free_balance(&fund_account);

amount>value
}
Expand All @@ -26,7 +26,7 @@ impl<T: Config> Pallet<T> {
pub fn get_contribution_share() -> Vec<ContributionShare<T>> {
let mut contribution_shares = Vec::<ContributionShare<T>>::new();
let fund_account = Self::fund_account_id();
let total = T::LocalCurrency::free_balance(&fund_account);
let total = <T as ROLES::Config>::Currency::free_balance(&fund_account);


for (account_id, contribution) in Contributions::<T>::iter() {
Expand Down Expand Up @@ -55,7 +55,7 @@ impl<T: Config> Pallet<T> {
) -> DispatchResultWithPostInfo {
// Check that the fund can afford the bid
let fund_account = Self::fund_account_id();
let fund = T::LocalCurrency::free_balance(&fund_account);
let fund = <T as ROLES::Config>::Currency::free_balance(&fund_account);

ensure!(fund>amount, Error::<T>::NotEnoughFundForHouse);

Expand Down Expand Up @@ -83,7 +83,7 @@ impl<T: Config> Pallet<T> {
}

// The amount is tagged as reserved in the fund for the account_id
T::LocalCurrency::reserve(&Self::fund_account_id(), amount)?;
<T as ROLES::Config>::Currency::reserve(&Self::fund_account_id(), amount)?;

// Get the block number for timestamp
let block_number = <frame_system::Pallet<T>>::block_number();
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<T: Config> Pallet<T> {
});
}

T::LocalCurrency::unreserve(&Self::fund_account_id(), reservation.amount);
<T as ROLES::Config>::Currency::unreserve(&Self::fund_account_id(), reservation.amount);
Reservations::<T>::remove((nft_collection_id, nft_item_id));

// Get the block number for timestamp
Expand Down Expand Up @@ -161,7 +161,7 @@ impl<T: Config> Pallet<T> {
let reservation = reservation_wrap.unwrap();

// The amount is unreserved in the currency pallet
T::LocalCurrency::unreserve(&Self::fund_account_id(), reservation.amount);
<T as ROLES::Config>::Currency::unreserve(&Self::fund_account_id(), reservation.amount);

// Get the block number for timestamp
let block_number = <frame_system::Pallet<T>>::block_number();
Expand Down
10 changes: 4 additions & 6 deletions pallets/housing_fund/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub mod pallet {
pub trait Config: frame_system::Config + NFT::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type LocalCurrency: frame_support::traits::Currency<Self::AccountId>
+ frame_support::traits::ReservableCurrency<Self::AccountId>;
type MinContribution: Get<BalanceOf<Self>>;
type FundThreshold: Get<BalanceOf<Self>>;
type MaxFundContribution: Get<BalanceOf<Self>>;
Expand Down Expand Up @@ -164,7 +162,7 @@ pub mod pallet {

// Check if account has enough to contribute
ensure!(
T::LocalCurrency::free_balance(&who) >= amount,
<T as ROLES::Config>::Currency::free_balance(&who) >= amount,
Error::<T>::NotEnoughToContribute
);

Expand Down Expand Up @@ -208,7 +206,7 @@ pub mod pallet {


// The amount is transferred to the treasurery
T::LocalCurrency::transfer(
<T as ROLES::Config>::Currency::transfer(
&who,
&Pallet::<T>::fund_account_id(),
amount,
Expand Down Expand Up @@ -257,7 +255,7 @@ pub mod pallet {

// Get the fund balance
let fund_account = Self::fund_account_id();
let fund = T::LocalCurrency::free_balance(&fund_account);
let fund = <T as ROLES::Config>::Currency::free_balance(&fund_account);

// Check that the fund has enough transferable for the withdraw
ensure!(fund>amount, Error::<T>::NotEnoughInTransferableForWithdraw);
Expand Down Expand Up @@ -285,7 +283,7 @@ pub mod pallet {


// The amount is transferred from the treasury to the account
T::LocalCurrency::transfer(
<T as ROLES::Config>::Currency::transfer(
&Pallet::<T>::fund_account_id(),
&who,
amount,
Expand Down
2 changes: 1 addition & 1 deletion pallets/housing_fund/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use frame_system::{ensure_signed, ensure_root, pallet_prelude::*, RawOrigin}
pub use scale_info::{prelude::vec::Vec, TypeInfo};
pub use serde::{Deserialize, Serialize};

pub type BalanceOf<T> = <<T as Config>::LocalCurrency as Currency<AccountIdOf<T>>>::Balance;
pub type BalanceOf<T> = <<T as ROLES::Config>::Currency as Currency<AccountIdOf<T>>>::Balance;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BlockNumberOf<T> = BlockNumberFor<T>;

Expand Down
6 changes: 3 additions & 3 deletions pallets/onboarding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl<T: Config> Pallet<T> {
let owner = Nft::Pallet::<T>::owner(collection_id, item_id)
.ok_or(Error::<T>::CollectionOrItemUnknown)?;
ensure!(buyer != owner, Error::<T>::BuyFromSelf);
let balance = <T as Config>::Currency::reserved_balance(&owner);
let _returned = <T as Config>::Currency::unreserve(&owner, balance);
let balance = <T as Roles::Config>::Currency::reserved_balance(&owner);
let _returned = <T as Roles::Config>::Currency::unreserve(&owner, balance);

// The reserved funds in Housing Fund from the house bidding are unreserved for the transfer
// transaction
Expand All @@ -101,7 +101,7 @@ impl<T: Config> Pallet<T> {
//Transfer funds from HousingFund to owner
let price = Prices::<T>::get(collection_id, item_id).unwrap();
let fund_id = T::PalletId::get().into_account_truncating();
<T as Config>::Currency::transfer(
<T as Roles::Config>::Currency::transfer(
&fund_id,
&owner,
price,
Expand Down
20 changes: 9 additions & 11 deletions pallets/onboarding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ pub mod pallet {
{
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type Currency: ReservableCurrency<Self::AccountId>
+ IsType<<Self as HousingFund::Config>::LocalCurrency>;
type Prop: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>
+ From<Call<Self>>
Expand Down Expand Up @@ -396,19 +394,19 @@ pub struct GenesisConfig<T: Config> {
Self::change_status(frame_system::RawOrigin::Root.into(), collection, item_id, Status::REJECTED).ok();

let owner = Nft::Pallet::<T>::owner(collection_id, item_id).unwrap();
let balance = <T as Config>::Currency::reserved_balance(&owner);
let balance = <T as Roles::Config>::Currency::reserved_balance(&owner);
let fees = <T as Config>::Slash::get().mul_floor(balance);
let remain = balance.saturating_sub(fees);
<T as pallet::Config>::Currency::unreserve(&owner, fees);
let res = <T as pallet::Config>::Currency::transfer(
<T as Roles::Config>::Currency::unreserve(&owner, fees);
let res = <T as Roles::Config>::Currency::transfer(
&owner,
&Self::account_id(),
fees,
ExistenceRequirement::AllowDeath,
);
debug_assert!(res.is_ok());

let res1 = <T as pallet::Config>::Currency::reserve(&owner, remain);
let res1 = <T as Roles::Config>::Currency::reserve(&owner, remain);
debug_assert!(res1.is_ok());

Self::deposit_event(Event::RejectedForEditing {
Expand Down Expand Up @@ -445,10 +443,10 @@ pub struct GenesisConfig<T: Config> {
Self::change_status(frame_system::RawOrigin::Root.into(), collection, item_id, Status::SLASH).ok();
let owner = Nft::Pallet::<T>::owner(collection_id, item_id).unwrap();
Nft::Pallet::<T>::burn(origin, collection, item_id).ok();
let balance = <T as Config>::Currency::reserved_balance(&owner);
let balance = <T as Roles::Config>::Currency::reserved_balance(&owner);
ensure!(balance > Zero::zero(), Error::<T>::NoneValue);
<T as pallet::Config>::Currency::unreserve(&owner, balance);
let res = <T as pallet::Config>::Currency::transfer(
<T as Roles::Config>::Currency::unreserve(&owner, balance);
let res = <T as Roles::Config>::Currency::transfer(
&owner,
&Self::account_id(),
balance,
Expand Down Expand Up @@ -489,11 +487,11 @@ pub struct GenesisConfig<T: Config> {
let item_id: T::NftItemId = Nft::ItemsCount::<T>::get()[idx].into();

//Create asset
let balance1 = <T as Config>::Currency::free_balance(&caller);
let balance1 = <T as Roles::Config>::Currency::free_balance(&caller);
let balance0 = T::ProposalFee::get().mul_floor(price.unwrap());
ensure!(balance1 > balance0, Error::<T>::InsufficientBalance);

<T as Config>::Currency::reserve(&caller, balance0).ok();
<T as Roles::Config>::Currency::reserve(&caller, balance0).ok();

Self::create_asset(origin.clone(), collection, metadata, price, item_id,max_tenants).ok();

Expand Down
2 changes: 0 additions & 2 deletions pallets/onboarding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ parameter_types! {

impl pallet_onboarding::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type Prop = RuntimeCall;
type ProposalFee = ProposalFee;
type Slash = SlashedFee;
Expand All @@ -159,7 +158,6 @@ parameter_types! {

impl pallet_housing_fund::Config for Test {
type RuntimeEvent = RuntimeEvent;
type LocalCurrency = Balances;
type MinContribution = MinContribution;
type FundThreshold = FundThreshold;
type MaxFundContribution = MaxFundContribution;
Expand Down
2 changes: 1 addition & 1 deletion pallets/onboarding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use sp_std::vec::Vec;
pub type BlockNumberOf<T> = BlockNumberFor<T>;
pub type NftCollectionOf = Nft::PossibleCollections;
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
<<T as Roles::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type BalanceOf1<T> =
<<T as DEM::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type CallOf<T> = <T as frame_system::Config>::RuntimeCall;
Expand Down
6 changes: 3 additions & 3 deletions pallets/roles/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<T: Config> HouseSeller<T>
};

SellerApprovalList::<T>::mutate(|list| {
let check=list.force_push(hw.clone());
let _=list.try_push(hw.clone()).map_err(|_| "Max number of requests reached").ok();
});

hw
Expand Down Expand Up @@ -198,7 +198,7 @@ impl<T: Config> Servicer<T> {
Servicer { account_id: acc.clone(), age: now, activated: false};

ServicerApprovalList::<T>::mutate(|list| {
list.force_push(sv.clone());
list.try_push(sv.clone()).map_err(|_| "Max number of requests reached").ok();
});
sv

Expand Down Expand Up @@ -274,7 +274,7 @@ impl<T: Config> Notary<T>
let notary =
Notary { account_id: caller.clone(), age: now, activated: false};
NotaryApprovalList::<T>::mutate(|list| {
list.force_push(notary.clone());
list.try_push(notary.clone()).map_err(|_| "Max number of requests reached").ok();
});

notary
Expand Down
8 changes: 8 additions & 0 deletions pallets/share_distributor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "share_distributor"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions pallets/share_distributor/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit 69f7f01

Please sign in to comment.