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

Bounty payment logic fixes #4395

Open
wants to merge 3 commits into
base: mainnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
41 changes: 25 additions & 16 deletions runtime-modules/bounty/src/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use frame_support::dispatch::{DispatchError, DispatchResult};
use frame_support::ensure;
use frame_support::traits::Currency;
use frame_system::ensure_root;
use sp_arithmetic::traits::Saturating;
use sp_arithmetic::traits::CheckedSub;

use common::costs::burn_from_usable;
use common::council::CouncilBudgetManager;
use common::membership::{MemberId, MemberOriginValidator, MembershipInfoProvider};

Expand Down Expand Up @@ -97,20 +98,20 @@ impl<T: Config> BountyActorManager<T> {
&self,
bounty_id: T::BountyId,
required_balance: BalanceOf<T>,
) {
) -> DispatchResult {
match self {
BountyActorManager::Council => {
BountyActorManager::<T>::transfer_balance_from_council_budget(
bounty_id,
required_balance,
);
)
}
BountyActorManager::Member(account_id, _) => {
Module::<T>::transfer_funds_to_bounty_account(
account_id,
bounty_id,
required_balance,
);
)
}
}
}
Expand All @@ -120,43 +121,51 @@ impl<T: Config> BountyActorManager<T> {
&self,
bounty_id: T::BountyId,
required_balance: BalanceOf<T>,
) {
allow_death: bool,
) -> DispatchResult {
match self {
BountyActorManager::Council => {
BountyActorManager::<T>::transfer_balance_to_council_budget(
bounty_id,
required_balance,
);
)
}
BountyActorManager::Member(account_id, _) => {
Module::<T>::transfer_funds_from_bounty_account(
account_id,
bounty_id,
required_balance,
);
allow_death,
)
}
}
}

// Remove some balance from the council budget and transfer it to the bounty account.
fn transfer_balance_from_council_budget(bounty_id: T::BountyId, amount: BalanceOf<T>) {
fn transfer_balance_from_council_budget(
bounty_id: T::BountyId,
amount: BalanceOf<T>,
) -> DispatchResult {
let budget = T::CouncilBudgetManager::get_budget();
let new_budget = budget.saturating_sub(amount);
let new_budget = budget
.checked_sub(&amount)
.ok_or(Error::<T>::ArithmeticError)?;

T::CouncilBudgetManager::set_budget(new_budget);

let bounty_account_id = Module::<T>::bounty_account_id(bounty_id);
let _ = balances::Pallet::<T>::deposit_creating(&bounty_account_id, amount);
Ok(())
}

// Add some balance from the council budget and slash from the bounty account.
Lezek123 marked this conversation as resolved.
Show resolved Hide resolved
fn transfer_balance_to_council_budget(bounty_id: T::BountyId, amount: BalanceOf<T>) {
fn transfer_balance_to_council_budget(
bounty_id: T::BountyId,
amount: BalanceOf<T>,
) -> DispatchResult {
let bounty_account_id = Module::<T>::bounty_account_id(bounty_id);
let _ = balances::Pallet::<T>::slash(&bounty_account_id, amount);

let budget = T::CouncilBudgetManager::get_budget();
let new_budget = budget.saturating_add(amount);

T::CouncilBudgetManager::set_budget(new_budget);
burn_from_usable::<T>(&bounty_account_id, amount)?;
T::CouncilBudgetManager::increase_budget(amount);
Ok(())
}
}
Loading