Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added flag to track the withdrawl of fund for milestones #257

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pallets/proposals/src/impls/pallet_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ impl<T: Config> Pallet<T> {
Projects::<T>::mutate_exists(project_key, |project| -> DispatchResult {
if let Some(p) = project {
p.withdrawn_funds = p.withdrawn_funds.saturating_add(withdrawable);
for (_,ms) in &mut p.milestones {
if ms.is_approved {
ms.withdrawn = true;
}
}
if p.withdrawn_funds == p.raised_funds {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice, We can now remove this possibly troublesome line if p.withdrawn_funds == p.raised_funds { which doesnt handle with dust at all and replace it with something like.

if milestones.iter().all(|&ms|{ ms.withdrawn }) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

<T as Config>::DepositHandler::return_deposit(p.deposit_id)?;
CompletedProjects::<T>::try_mutate(
Expand Down
4 changes: 4 additions & 0 deletions pallets/proposals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ pub mod pallet {
milestone_key,
percentage_to_unlock: milestone.percentage_to_unlock,
is_approved: false,
withdrawn: false,
};
milestones
.try_insert(milestone_key, milestone)
Expand Down Expand Up @@ -485,6 +486,7 @@ pub mod pallet {
agreement_hash: brief_hash,
funding_type,
deposit_id,
payment_address: [0; 20],
};

Projects::<T>::insert(project_key, project);
Expand Down Expand Up @@ -527,6 +529,7 @@ pub struct Milestone {
pub milestone_key: MilestoneKey,
pub percentage_to_unlock: Percent,
pub is_approved: bool,
pub withdrawn: bool,
}

/// The vote struct is used to
Expand Down Expand Up @@ -562,6 +565,7 @@ pub struct Project<T: Config> {
pub cancelled: bool,
pub funding_type: FundingType,
pub deposit_id: DepositIdOf<T>,
pub payment_address: [u8; 20],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to signal where the tokens will end up. check telegram when you get a minute!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

}

/// The contribution users made to a proposal project.
Expand Down
3 changes: 3 additions & 0 deletions pallets/proposals/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pub mod v3 {
milestone.percentage_to_unlock as u8,
),
is_approved: milestone.is_approved,
withdrawn: milestone.withdrawn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will these migrations work, the old data doesnt have these flags. You can default them is_approved for now

},
);
});
Expand All @@ -296,6 +297,7 @@ pub mod v3 {
funding_type: FundingType::Proposal,
// A deposit_id of u32::MAX is ignored.
deposit_id: u32::MAX.into(),
payment_address: project.payment_address,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should default to the initiator address

};
Some(migrated_project)
} else {
Expand Down Expand Up @@ -680,6 +682,7 @@ pub mod v6 {

#[cfg(test)]
mod test {
use std::io::Read;
use super::*;
use mock::*;
use test_utils::*;
Expand Down
2 changes: 2 additions & 0 deletions pallets/proposals/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub fn create_project<T: Config>(
milestone_key,
percentage_to_unlock: ms.percentage_to_unlock,
is_approved: false,
withdrawn: false,
};
milestones.insert(milestone_key, milestone);
let _ = bounded_milestone_keys.try_push(milestone_key);
Expand All @@ -122,6 +123,7 @@ pub fn create_project<T: Config>(
agreement_hash,
funding_type: FundingType::Brief,
deposit_id,
payment_address: [0;20],
};

crate::Projects::<T>::insert(project_key, project);
Expand Down
3 changes: 3 additions & 0 deletions pallets/proposals/src/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ fn withdraw_only_transfers_approved_milestones() {
RuntimeOrigin::signed(*ALICE),
project_key
));
//validating the withdrawn flag set to true once the fund for the milestone is being withdrawn
assert_eq!(Projects::<Test>::get(project_key).unwrap().milestones.get(&milestone_key).unwrap().withdrawn,true);

let alice_after = <Test as Config>::MultiCurrency::free_balance(CurrencyId::Native, &ALICE);
let expected_fee = <Test as Config>::ImbueFee::get().mul_floor(per_contribution * 2 / 10);
// total_contribution / number of milestones - fee
Expand Down
Loading