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

Refactors referenda pallet to use fungible traits #1785

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Merge branch 'master' into gpestana/referenda-fungibles
gpestana committed Oct 10, 2023
commit 24840ed7703d64a903bcee313dd6b2c04fb9aeea
28 changes: 16 additions & 12 deletions substrate/frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
@@ -79,8 +79,6 @@ pub mod weights;
#[cfg(feature = "runtime-benchmarks")]
pub use benchmarking::ArgumentsFactory;

use core::marker::PhantomData;

use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

@@ -93,13 +91,18 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use frame_support::{
print,
traits::{
Currency, ExistenceRequirement::KeepAlive, Get, Imbalance, OnUnbalanced,
ReservableCurrency, WithdrawReasons, fungible::{Credit, Balanced},
fungible::{Balanced, Credit},
tokens::Pay,
Currency,
ExistenceRequirement::KeepAlive,
Get, Imbalance, OnUnbalanced, ReservableCurrency, WithdrawReasons,
},
weights::Weight,
PalletId,
};

use core::marker::PhantomData;

pub use pallet::*;
pub use weights::WeightInfo;

@@ -1026,7 +1029,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

impl<T: Config<I>, I: 'static> OnUnbalanced<NegativeImbalanceOf<T, I>> for Pallet<T, I> {
fn on_nonzero_unbalanced(amount: NegativeImbalanceOf<T, I>) {
fn on_nonzero_unbalanced(amount: NegativeImbalanceOf<T, I>) {
let numeric_amount = amount.peek();

// Must resolve into existing but better to be safe.
@@ -1039,13 +1042,14 @@ impl<T: Config<I>, I: 'static> OnUnbalanced<NegativeImbalanceOf<T, I>> for Palle
/// Type that implements the [`OnUnbalanced`] trait that is supported by the fungible traits.
pub struct FunOnUnbalanced<T, F, I>(PhantomData<(T, F, I)>);

impl<T: Config<I>, F, I: 'static> OnUnbalanced<Credit<AccountIdOf<T>, F>> for FunOnUnbalanced<T, F, I>
where F: Balanced<AccountIdOf<T>>
impl<T: Config<I>, F, I: 'static> OnUnbalanced<Credit<AccountIdOf<T>, F>>
for FunOnUnbalanced<T, F, I>
where
F: Balanced<AccountIdOf<T>>,
{
fn on_nonzero_unbalanced(amount: Credit<<T as frame_system::Config>::AccountId, F>) {
let _ = F::resolve(&<Pallet<T, I>>::account_id(), amount);
fn on_nonzero_unbalanced(amount: Credit<<T as frame_system::Config>::AccountId, F>) {
let _ = F::resolve(&<Pallet<T, I>>::account_id(), amount);
Copy link
Member

Choose a reason for hiding this comment

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

If this fails then the credit is just dropped correctly, or?


//<Pallet<T, I>>::deposit_event(Event::Deposit { value: amount.peek() });
}
//<Pallet<T, I>>::deposit_event(Event::Deposit { value: amount.peek() });
}
}

You are viewing a condensed version of this merge commit. You can view the full changes here.