mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 15:57:55 +00:00
Insufficient asset quota and deposits (#10382)
* Allow asset accounts to exist by deposit * Place limit on consumers (and therefore freebie asset accounts) * Maximum number of assets * Fixes * Fixes * Formatting * Docs * Formatting * Destroyed assets are properly tidied * Update frame/assets/src/types.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Docs * Docs * Formatting * Docs * Docs * Fixes * Fixes Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -309,6 +309,10 @@ pub mod pallet {
|
||||
/// It's unlikely that this needs to be customized, unless you are writing a parachain using
|
||||
/// `Cumulus`, where the actual code change is deferred.
|
||||
type OnSetCode: SetCode<Self>;
|
||||
|
||||
/// The maximum number of consumers allowed on a single account.
|
||||
#[pallet::constant]
|
||||
type MaxConsumers: Get<RefCount>;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
@@ -1107,8 +1111,12 @@ impl<T: Config> Pallet<T> {
|
||||
pub fn inc_consumers(who: &T::AccountId) -> Result<(), DispatchError> {
|
||||
Account::<T>::try_mutate(who, |a| {
|
||||
if a.providers > 0 {
|
||||
a.consumers = a.consumers.saturating_add(1);
|
||||
Ok(())
|
||||
if a.consumers < T::MaxConsumers::get() {
|
||||
a.consumers = a.consumers.saturating_add(1);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(DispatchError::TooManyConsumers)
|
||||
}
|
||||
} else {
|
||||
Err(DispatchError::NoProviders)
|
||||
}
|
||||
@@ -1148,7 +1156,8 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// True if the account has at least one provider reference.
|
||||
pub fn can_inc_consumer(who: &T::AccountId) -> bool {
|
||||
Account::<T>::get(who).providers > 0
|
||||
let a = Account::<T>::get(who);
|
||||
a.providers > 0 && a.consumers < T::MaxConsumers::get()
|
||||
}
|
||||
|
||||
/// Deposits an event into this block's event record.
|
||||
|
||||
@@ -111,6 +111,7 @@ impl Config for Test {
|
||||
type SystemWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
|
||||
pub type SysEvent = frame_system::Event<Test>;
|
||||
|
||||
Reference in New Issue
Block a user