Skip to content

Commit

Permalink
refactor: switch to new prefix removal methods
Browse files Browse the repository at this point in the history
New methods allows to call `remove_prefix` with limit multiple times
in the same block
However, we don't use prefix removal limits, so upgrade is
straightforward

Upstream-Change: paritytech/substrate#11490
Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
  • Loading branch information
CertainLach authored and Daniel Shiposha committed Aug 15, 2022
1 parent a170962 commit ca9b9d8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pallets/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,8 @@ impl<T: Config> Pallet<T> {
<DestroyedCollectionCount<T>>::put(destroyed_collections);
<CollectionById<T>>::remove(collection.id);
<AdminAmount<T>>::remove(collection.id);
<IsAdmin<T>>::remove_prefix((collection.id,), None);
<Allowlist<T>>::remove_prefix((collection.id,), None);
let _ = <IsAdmin<T>>::clear_prefix((collection.id,), u32::MAX, None);
let _ = <Allowlist<T>>::clear_prefix((collection.id,), u32::MAX, None);
<CollectionProperties<T>>::remove(collection.id);

<Pallet<T>>::deposit_event(Event::CollectionDestroyed(collection.id));
Expand Down
4 changes: 2 additions & 2 deletions pallets/fungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ impl<T: Config> Pallet<T> {
PalletCommon::destroy_collection(collection.0, sender)?;

<TotalSupply<T>>::remove(id);
<Balance<T>>::remove_prefix((id,), None);
<Allowance<T>>::remove_prefix((id,), None);
let _ = <Balance<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <Allowance<T>>::clear_prefix((id,), u32::MAX, None);
Ok(())
}

Expand Down
12 changes: 6 additions & 6 deletions pallets/nonfungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,13 @@ impl<T: Config> Pallet<T> {

PalletCommon::destroy_collection(collection.0, sender)?;

<TokenData<T>>::remove_prefix((id,), None);
<TokenChildren<T>>::remove_prefix((id,), None);
<Owned<T>>::remove_prefix((id,), None);
let _ = <TokenData<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <TokenChildren<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <Owned<T>>::clear_prefix((id,), u32::MAX, None);
<TokensMinted<T>>::remove(id);
<TokensBurnt<T>>::remove(id);
<Allowance<T>>::remove_prefix((id,), None);
<AccountBalance<T>>::remove_prefix((id,), None);
let _ = <Allowance<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <AccountBalance<T>>::clear_prefix((id,), u32::MAX, None);
Ok(())
}

Expand Down Expand Up @@ -487,7 +487,7 @@ impl<T: Config> Pallet<T> {
<TokensBurnt<T>>::insert(collection.id, burnt);
<TokenData<T>>::remove((collection.id, token));
<TokenProperties<T>>::remove((collection.id, token));
<TokenAuxProperties<T>>::remove_prefix((collection.id, token), None);
let _ = <TokenAuxProperties<T>>::clear_prefix((collection.id, token), u32::MAX, None);
let old_spender = <Allowance<T>>::take((collection.id, token));

if let Some(old_spender) = old_spender {
Expand Down
16 changes: 11 additions & 5 deletions pallets/refungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ impl<T: Config> Pallet<T> {

<TokensMinted<T>>::remove(id);
<TokensBurnt<T>>::remove(id);
<TotalSupply<T>>::remove_prefix((id,), None);
<Balance<T>>::remove_prefix((id,), None);
<Allowance<T>>::remove_prefix((id,), None);
<Owned<T>>::remove_prefix((id,), None);
<AccountBalance<T>>::remove_prefix((id,), None);
let _ = <TotalSupply<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <Balance<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <Allowance<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <Owned<T>>::clear_prefix((id,), u32::MAX, None);
let _ = <AccountBalance<T>>::clear_prefix((id,), u32::MAX, None);
Ok(())
}

Expand All @@ -424,6 +424,7 @@ impl<T: Config> Pallet<T> {
<TokensBurnt<T>>::insert(collection.id, burnt);
<TokenProperties<T>>::remove((collection.id, token_id));
<TotalSupply<T>>::remove((collection.id, token_id));
<<<<<<< HEAD
<Balance<T>>::remove_prefix((collection.id, token_id), None);
<Allowance<T>>::remove_prefix((collection.id, token_id), None);

Expand All @@ -435,6 +436,11 @@ impl<T: Config> Pallet<T> {
}
.to_log(collection_id_to_address(collection.id)),
);
=======
let _ = <Balance<T>>::clear_prefix((collection.id, token_id), u32::MAX, None);
let _ = <Allowance<T>>::clear_prefix((collection.id, token_id), u32::MAX, None);
// TODO: ERC721 transfer event
>>>>>>> 5d9665e0... refactor: switch to new prefix removal methods
Ok(())
}

Expand Down
15 changes: 9 additions & 6 deletions pallets/unique/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,16 @@ decl_module! {

T::CollectionDispatch::destroy(sender, collection)?;

<NftTransferBasket<T>>::remove_prefix(collection_id, None);
<FungibleTransferBasket<T>>::remove_prefix(collection_id, None);
<ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);
// TODO: basket cleanup should be moved elsewhere
// Maybe runtime dispatch.rs should perform it?

<NftApproveBasket<T>>::remove_prefix(collection_id, None);
<FungibleApproveBasket<T>>::remove_prefix(collection_id, None);
<RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);
let _ = <NftTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
let _ = <FungibleTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
let _ = <ReFungibleTransferBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);

let _ = <NftApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
let _ = <FungibleApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
let _ = <RefungibleApproveBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);

Ok(())
}
Expand Down

0 comments on commit ca9b9d8

Please sign in to comment.