Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Add lock balance for activity
Browse files Browse the repository at this point in the history
  • Loading branch information
kikakkz committed Dec 7, 2023
1 parent bc7428c commit 92a9f39
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions foundation/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl Foundation {
if balance.le(&amount) {
return Err(StateError::InsufficientBalance);
}
// TODO: distribute reward from locked activity balance
self.reward_user(reward_user, amount).await?;
self.activity_lock_funds
.insert(&activity_id, balance.saturating_sub(amount))?;
Expand Down Expand Up @@ -222,6 +223,7 @@ impl Foundation {
activity_id: u64,
amount: Amount,
) -> Result<(), StateError> {
// TODO: check application balance
let locked = match self.activity_lock_funds.get(&activity_id).await? {
Some(amount) => amount,
None => Amount::ZERO,
Expand Down
21 changes: 19 additions & 2 deletions review/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,20 @@ impl Review {
Ok(())
}

async fn lock_activity_funds(
&mut self,
activity_id: u64,
budget_amount: Amount,
) -> Result<(), ContractError> {
let call = foundation::ApplicationCall::Lock {
activity_id,
amount: budget_amount,
};
self.call_application(true, Self::foundation_app_id()?, &call, vec![])
.await?;
Ok(())
}

async fn _initialize(&mut self, state: InitialState) -> Result<(), ContractError> {
self.initialize_review(state).await?;
Ok(())
Expand Down Expand Up @@ -993,15 +1007,18 @@ impl Review {
reason: Option<String>,
creation_chain: bool,
) -> Result<(), ContractError> {
let _activity = self
let activity = self
.approve_activity(owner, activity_id, reason.unwrap_or_default())
.await?;
if !creation_chain {
return Ok(());
}
self.reward_credits(owner, Amount::from_tokens(50)).await?;
self.reward_tokens().await?;
// TODO: here we should lock budget from foundation
if let Some(activity) = activity {
self.lock_activity_funds(activity_id, activity.budget_amount)
.await?;
}
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion review/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ pub enum StateError {
#[error("Invalid reviewer")]
InvalidReviewer,

#[error("Already reviewer")]
#[error("Already reviewed")]
AlreadyReviewed,

#[error("Invalid content")]
Expand Down

0 comments on commit 92a9f39

Please sign in to comment.