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:
Gavin Wood
2021-12-09 13:22:54 +01:00
committed by GitHub
parent 73bc2f420e
commit 3dd8f83a3a
84 changed files with 513 additions and 154 deletions
+9 -16
View File
@@ -62,11 +62,11 @@ impl<T: Config<I>, I: 'static> ExtraMutator<T, I> {
id: T::AssetId,
who: impl sp_std::borrow::Borrow<T::AccountId>,
) -> Option<ExtraMutator<T, I>> {
if Account::<T, I>::contains_key(id, who.borrow()) {
if let Some(a) = Account::<T, I>::get(id, who.borrow()) {
Some(ExtraMutator::<T, I> {
id,
who: who.borrow().clone(),
original: Account::<T, I>::get(id, who.borrow()).extra,
original: a.extra,
pending: None,
})
} else {
@@ -77,13 +77,8 @@ impl<T: Config<I>, I: 'static> ExtraMutator<T, I> {
/// Commit any changes to storage.
pub fn commit(&mut self) -> Result<(), ()> {
if let Some(extra) = self.pending.take() {
Account::<T, I>::try_mutate_exists(self.id, self.who.borrow(), |maybe_account| {
if let Some(ref mut account) = maybe_account {
account.extra = extra;
Ok(())
} else {
Err(())
}
Account::<T, I>::try_mutate(self.id, self.who.borrow(), |maybe_account| {
maybe_account.as_mut().ok_or(()).map(|account| account.extra = extra)
})
} else {
Ok(())
@@ -93,13 +88,11 @@ impl<T: Config<I>, I: 'static> ExtraMutator<T, I> {
/// Revert any changes, even those already committed by `self` and drop self.
pub fn revert(mut self) -> Result<(), ()> {
self.pending = None;
Account::<T, I>::try_mutate_exists(self.id, self.who.borrow(), |maybe_account| {
if let Some(ref mut account) = maybe_account {
account.extra = self.original.clone();
Ok(())
} else {
Err(())
}
Account::<T, I>::try_mutate(self.id, self.who.borrow(), |maybe_account| {
maybe_account
.as_mut()
.ok_or(())
.map(|account| account.extra = self.original.clone())
})
}
}