Skip to content

Commit

Permalink
Implemented some corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Sep 22, 2022
1 parent 98dcd69 commit 4e77d0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
19 changes: 11 additions & 8 deletions pallets/share_distributor/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ Ok(())
pub fn owner_and_shares(collection_id: T::NftCollectionId, item_id: T::NftItemId) -> Vec<(T::AccountId, Percent)>{

//Get owners and their reserved contribution to the bid
let infos = HousingFund::Reservations::<T>::get((collection_id,item_id)).unwrap();
let vec0 = infos.contributions;
let price = infos.amount;

let reservation_infos = HousingFund::Reservations::<T>::get((collection_id.clone(),item_id.clone())).unwrap();
let vec0 = reservation_infos.contributions;
let price = reservation_infos.amount;
let mut vec = Vec::new() ;
for i in vec0.iter(){
let price0 = Self::balance_to_u64_option(price).unwrap();
Expand All @@ -80,6 +81,7 @@ pub fn create_tokens(origin: OriginFor<T>,collection_id: T::NftCollectionId, ite
let val0 = val.clone();
*val = val0+1;
});
ensure!(Virtual::<T>::get(collection_id,item_id).is_some(),Error::<T>::InvalidValue);
let token_id = Virtual::<T>::get(collection_id,item_id).unwrap().token_id;

//Create token class
Expand All @@ -98,18 +100,19 @@ pub fn create_tokens(origin: OriginFor<T>,collection_id: T::NftCollectionId, ite
}

pub fn distribute_tokens(account:T::AccountId,collection_id: T::NftCollectionId, item_id: T::NftItemId) -> DispatchResult{
let shares = Self::owner_and_shares(collection_id.clone(),item_id.clone());
let shares = Self::owner_and_shares(collection_id.clone(),item_id.clone());
ensure!(Virtual::<T>::get(collection_id,item_id).is_some(),Error::<T>::InvalidValue);
let token_id = Virtual::<T>::get(collection_id,item_id).unwrap().token_id;
let total_tokens = Assets::Pallet::<T>::total_supply(token_id.into());
debug_assert!(total_tokens == Self::u32_to_balance_option(100).unwrap());

let from = T::Lookup::unlookup(account.clone());
let origin:OriginFor<T> = RawOrigin::Signed(account.clone()).into();
for i in shares.iter(){

let amount:<T as Assets::Config>::Balance = i.clone().1* total_tokens.clone();

for share in shares.iter(){
let amount:<T as Assets::Config>::Balance = share.clone().1* total_tokens.clone();
debug_assert!(!amount.clone().is_zero());
let to = T::Lookup::unlookup(i.clone().0);
let to = T::Lookup::unlookup(share.clone().0);
Assets::Pallet::<T>::force_transfer(origin.clone(),token_id.clone().into(),from.clone(),to,amount).ok();
}

Expand Down
3 changes: 2 additions & 1 deletion pallets/share_distributor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub mod pallet {
pub enum Error<T> {
/// Not a value.
NoneValue,
/// Ivalid parameter
InvalidValue,
/// This action is reserved to Accounts holding the SERVICER role.
ReservedToServicer,
}
Expand All @@ -111,7 +113,6 @@ pub mod pallet {

let _caller = ensure_root(origin.clone());
let seller: T::AccountId = Nft::Pallet::<T>::owner(collection_id.clone(),item_id.clone()).unwrap();

// Create virtual account
Self::virtual_account(collection_id.clone(),item_id.clone()).ok();
let account = Self::virtual_acc(collection_id.clone(),item_id.clone()).unwrap().virtual_account;
Expand Down

0 comments on commit 4e77d0a

Please sign in to comment.