diff --git a/pallets/bidding/Cargo.toml b/pallets/bidding/Cargo.toml index 191b5296..5c6e2141 100644 --- a/pallets/bidding/Cargo.toml +++ b/pallets/bidding/Cargo.toml @@ -32,7 +32,7 @@ pallet-onboarding = { default-features = false, path="../onboarding" } pallet-housing_fund = { default-features = false, path="../housing_fund" } pallet-nft = { default-features = false, path="../nft" } pallet-finalizer = { default-features = false, path="../finalizer" } -rand = "0.8.5" +rand = {version = "0.8.5", features=["alloc"]} [dev-dependencies] sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" } diff --git a/pallets/bidding/src/functions.rs b/pallets/bidding/src/functions.rs index f1d38e70..08fef09a 100644 --- a/pallets/bidding/src/functions.rs +++ b/pallets/bidding/src/functions.rs @@ -1,6 +1,6 @@ pub use super::*; -use rand::Rng; -use rand::distributions::Slice; +use rand::{Rng, seq::IteratorRandom}; +use rand::seq::SliceRandom; use sp_runtime::{BoundedVec,Percent}; use frame_support::pallet_prelude::ConstU32; use Onboarding::Zero; @@ -13,6 +13,7 @@ impl Pallet { //get asset price let asset = Onboarding::Pallet::::houses(collection_id,item_id).unwrap(); let asset_price = asset.price.unwrap(); + let mut remaining_amount = asset_price.clone(); //Max contribution from asset Price //Min contribution from asset price @@ -25,13 +26,17 @@ impl Pallet { let contribution = Self::u128_to_onboarding_bal(contribution0).unwrap(); //user contributed more than 5% of asset_price contribution > Percent::from_percent(5) * asset_price //should be minimun contribution calculated from asset price. - //true + //ToDo: We also want to only include users that did not contributed to a purchase for y_blocks (to be defined). }); - //Get a random sample of qualified investors - let inv_dist = Slice::new(&investors).unwrap(); + //Get a random sample of qualified investors + let mut rng = rand::thread_rng(); + + //Build a sample of 10 investors + let inv_dist = investors.choose_multiple(&mut rng, 10); //let inv:BoundedVec> = BoundedVec::truncate_from(inv_dist); + } // Conversion of BalanceOf to u128