difftreelog
Revert "feat: burn children when destroying a collection"
in: master
This reverts commit 4b7f4d90a16f3a5ab26bed0511dabae078429724.
12 files changed
pallets/common/src/dispatch.rsdiffbeforeafterboth--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -6,7 +6,7 @@
weights::Pays,
traits::Get,
};
-use up_data_structs::{CollectionId, CreateCollectionData, budget::Budget};
+use up_data_structs::{CollectionId, CreateCollectionData};
use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};
@@ -57,11 +57,7 @@
pub trait CollectionDispatch<T: Config> {
fn create(sender: T::AccountId, data: CreateCollectionData<T::AccountId>) -> DispatchResult;
- fn destroy(
- sender: T::CrossAccountId,
- handle: CollectionHandle<T>,
- nesting_budget: &dyn Budget,
- ) -> DispatchResult;
+ fn destroy(sender: T::CrossAccountId, handle: CollectionHandle<T>) -> DispatchResult;
fn dispatch(handle: CollectionHandle<T>) -> Self;
fn into_inner(self) -> CollectionHandle<T>;
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1169,12 +1169,6 @@
token: TokenId,
amount: u128,
) -> DispatchResultWithPostInfo;
- fn burn_item_unchecked(
- &self,
- owner: &T::CrossAccountId,
- token: TokenId,
- amount: u128,
- ) -> DispatchResult;
fn set_collection_properties(
&self,
sender: T::CrossAccountId,
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -170,17 +170,6 @@
)
}
- fn burn_item_unchecked(
- &self,
- owner: &T::CrossAccountId,
- _token: TokenId,
- amount: u128,
- ) -> sp_runtime::DispatchResult {
- <Pallet<T>>::burn_item_unchecked(self, owner, amount)?;
-
- Ok(())
- }
-
fn transfer(
&self,
from: T::CrossAccountId,
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -160,36 +160,6 @@
owner: &T::CrossAccountId,
amount: u128,
) -> DispatchResult {
- if collection.access == AccessMode::AllowList {
- collection.check_allowlist(owner)?;
- }
-
- // =========
-
- Self::burn_item_unchecked(collection, owner, amount)?;
-
- <PalletEvm<T>>::deposit_log(
- ERC20Events::Transfer {
- from: *owner.as_eth(),
- to: H160::default(),
- value: amount.into(),
- }
- .to_log(collection_id_to_address(collection.id)),
- );
- <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
- collection.id,
- TokenId::default(),
- owner.clone(),
- amount,
- ));
- Ok(())
- }
-
- pub fn burn_item_unchecked(
- collection: &FungibleHandle<T>,
- owner: &T::CrossAccountId,
- amount: u128,
- ) -> DispatchResult {
let total_supply = <TotalSupply<T>>::get(collection.id)
.checked_sub(amount)
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
@@ -216,6 +186,20 @@
}
<TotalSupply<T>>::insert(collection.id, total_supply);
+ <PalletEvm<T>>::deposit_log(
+ ERC20Events::Transfer {
+ from: *owner.as_eth(),
+ to: H160::default(),
+ value: amount.into(),
+ }
+ .to_log(collection_id_to_address(collection.id)),
+ );
+ <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
+ collection.id,
+ TokenId::default(),
+ owner.clone(),
+ amount,
+ ));
Ok(())
}
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -264,19 +264,6 @@
}
}
- fn burn_item_unchecked(
- &self,
- owner:& T::CrossAccountId,
- token: TokenId,
- amount: u128,
- ) -> sp_runtime::DispatchResult {
- if amount == 1 {
- <Pallet<T>>::burn_item_unchecked(self, owner, token)
- } else {
- Ok(())
- }
- }
-
fn transfer(
&self,
from: T::CrossAccountId,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use erc::ERC721Events;20use evm_coder::ToLog;21use frame_support::{BoundedVec, ensure, fail, transactional, storage::with_transaction};22use up_data_structs::{23 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,24 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,25 PropertyKey, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty,26};27use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};28use pallet_common::{29 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,30 dispatch::CollectionDispatch,31 eth::collection_id_to_address,32};33use pallet_structure::Pallet as PalletStructure;34use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};35use sp_core::H160;36use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};37use sp_std::{vec::Vec, vec, collections::btree_set::BTreeSet};38use core::ops::Deref;39use sp_std::collections::btree_map::BTreeMap;40use codec::{Encode, Decode, MaxEncodedLen};41use scale_info::TypeInfo;4243pub use pallet::*;44#[cfg(feature = "runtime-benchmarks")]45pub mod benchmarking;46pub mod common;47pub mod erc;48pub mod weights;4950pub type CreateItemData<T> = CreateNftExData<<T as pallet_evm::account::Config>::CrossAccountId>;51pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;5253#[struct_versioning::versioned(version = 2, upper)]54#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]55pub struct ItemData<CrossAccountId> {56 #[version(..2)]57 pub const_data: BoundedVec<u8, CustomDataLimit>,5859 #[version(..2)]60 pub variable_data: BoundedVec<u8, CustomDataLimit>,6162 pub owner: CrossAccountId,63}6465#[frame_support::pallet]66pub mod pallet {67 use super::*;68 use frame_support::{69 Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, traits::StorageVersion,70 };71 use frame_system::pallet_prelude::*;72 use up_data_structs::{CollectionId, TokenId};73 use super::weights::WeightInfo;7475 #[pallet::error]76 pub enum Error<T> {77 /// Not Nonfungible item data used to mint in Nonfungible collection.78 NotNonfungibleDataUsedToMintFungibleCollectionToken,79 /// Used amount > 1 with NFT80 NonfungibleItemsHaveNoAmount,81 /// Unable to burn NFT with children82 CantBurnNftWithChildren,83 /// Too many children to burn when destroying a collection84 TooManyChildrenToBurn,85 }8687 #[pallet::config]88 pub trait Config:89 frame_system::Config + pallet_common::Config + pallet_structure::Config + pallet_evm::Config90 {91 type WeightInfo: WeightInfo;92 }9394 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);9596 #[pallet::pallet]97 #[pallet::storage_version(STORAGE_VERSION)]98 #[pallet::generate_store(pub(super) trait Store)]99 pub struct Pallet<T>(_);100101 #[pallet::storage]102 pub type TokensMinted<T: Config> =103 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;104 #[pallet::storage]105 pub type TokensBurnt<T: Config> =106 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;107108 #[pallet::storage]109 pub type TokenData<T: Config> = StorageNMap<110 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),111 Value = ItemData<T::CrossAccountId>,112 QueryKind = OptionQuery,113 >;114115 #[pallet::storage]116 #[pallet::getter(fn token_properties)]117 pub type TokenProperties<T: Config> = StorageNMap<118 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),119 Value = Properties,120 QueryKind = ValueQuery,121 OnEmpty = up_data_structs::TokenProperties,122 >;123124 /// Used to enumerate tokens owned by account125 #[pallet::storage]126 pub type Owned<T: Config> = StorageNMap<127 Key = (128 Key<Twox64Concat, CollectionId>,129 Key<Blake2_128Concat, T::CrossAccountId>,130 Key<Twox64Concat, TokenId>,131 ),132 Value = bool,133 QueryKind = ValueQuery,134 >;135136 /// Used to enumerate token's children137 #[pallet::storage]138 #[pallet::getter(fn token_children)]139 pub type TokenChildren<T: Config> = StorageNMap<140 Key = (141 Key<Twox64Concat, CollectionId>,142 Key<Twox64Concat, TokenId>,143 Key<Twox64Concat, (CollectionId, TokenId)>,144 ),145 Value = bool,146 QueryKind = ValueQuery,147 >;148149 #[pallet::storage]150 pub type AccountBalance<T: Config> = StorageNMap<151 Key = (152 Key<Twox64Concat, CollectionId>,153 Key<Blake2_128Concat, T::CrossAccountId>,154 ),155 Value = u32,156 QueryKind = ValueQuery,157 >;158159 #[pallet::storage]160 pub type Allowance<T: Config> = StorageNMap<161 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),162 Value = T::CrossAccountId,163 QueryKind = OptionQuery,164 >;165166 #[pallet::hooks]167 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {168 fn on_runtime_upgrade() -> Weight {169 if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {170 let mut had_consts = BTreeSet::new();171 <TokenData<T>>::translate::<ItemDataVersion1<T::CrossAccountId>, _>(|(collection, token), v| {172 let mut props = vec![];173 if !v.const_data.is_empty() {174 props.push(Property {175 key: b"_old_constData".to_vec().try_into().unwrap(),176 value: v.const_data.clone().into_inner().try_into().expect("const too long"),177 });178 had_consts.insert(collection);179 }180 if !v.variable_data.is_empty() {181 props.push(Property {182 key: b"_old_variableData".to_vec().try_into().unwrap(),183 value: v.variable_data.clone().into_inner().try_into().expect("variable too long"),184 })185 }186 if !props.is_empty() {187 Self::set_scoped_token_properties(188 collection,189 token,190 PropertyScope::None,191 props.into_iter(),192 ).expect("existing token data exceeds property storage");193 }194 Some(<ItemDataVersion2<T::CrossAccountId>>::from(v))195 });196 for collection in had_consts {197 <PalletCommon<T>>::set_property_permission_unchecked(198 collection,199 PropertyKeyPermission {200 key: b"_old_constData".to_vec().try_into().unwrap(),201 permission: PropertyPermission {202 mutable: false,203 collection_admin: true,204 token_owner: false,205 },206 }207 ).expect("failed to configure permission");208 }209 }210211 0212 }213 }214}215216pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);217impl<T: Config> NonfungibleHandle<T> {218 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {219 Self(inner)220 }221 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {222 self.0223 }224 pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {225 &mut self.0226 }227}228impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {229 fn recorder(&self) -> &SubstrateRecorder<T> {230 self.0.recorder()231 }232 fn into_recorder(self) -> SubstrateRecorder<T> {233 self.0.into_recorder()234 }235}236impl<T: Config> Deref for NonfungibleHandle<T> {237 type Target = pallet_common::CollectionHandle<T>;238239 fn deref(&self) -> &Self::Target {240 &self.0241 }242}243244impl<T: Config> Pallet<T> {245 pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {246 <TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)247 }248 pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {249 <TokenData<T>>::contains_key((collection.id, token))250 }251252 pub fn set_scoped_token_property(253 collection_id: CollectionId,254 token_id: TokenId,255 scope: PropertyScope,256 property: Property,257 ) -> DispatchResult {258 TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {259 properties.try_scoped_set(scope, property.key, property.value)260 })261 .map_err(<CommonError<T>>::from)?;262263 Ok(())264 }265266 pub fn set_scoped_token_properties(267 collection_id: CollectionId,268 token_id: TokenId,269 scope: PropertyScope,270 properties: impl Iterator<Item=Property>,271 ) -> DispatchResult {272 TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {273 stored_properties.try_scoped_set_from_iter(scope, properties)274 })275 .map_err(<CommonError<T>>::from)?;276277 Ok(())278 }279280 pub fn current_token_id(collection_id: CollectionId) -> TokenId {281 TokenId(<TokensMinted<T>>::get(collection_id))282 }283}284285// unchecked calls skips any permission checks286impl<T: Config> Pallet<T> {287 pub fn init_collection(288 owner: T::AccountId,289 data: CreateCollectionData<T::AccountId>,290 ) -> Result<CollectionId, DispatchError> {291 <PalletCommon<T>>::init_collection(owner, data)292 }293 pub fn destroy_collection(294 collection: NonfungibleHandle<T>,295 sender: &T::CrossAccountId,296 nesting_budget: &dyn Budget,297 ) -> DispatchResult {298 let id = collection.id;299300 // =========301302 Self::burn_children_in_collection(id, nesting_budget)?;303 PalletCommon::destroy_collection(collection.0, sender)?;304 <TokenData<T>>::remove_prefix((id,), None);305 <TokenChildren<T>>::remove_prefix((id,), None);306 <Owned<T>>::remove_prefix((id,), None);307 <TokensMinted<T>>::remove(id);308 <TokensBurnt<T>>::remove(id);309 <Allowance<T>>::remove_prefix((id,), None);310 <AccountBalance<T>>::remove_prefix((id,), None);311 Ok(())312 }313314 #[transactional]315 fn burn_children_in_collection(collection_id: CollectionId, nesting_budget: &dyn Budget) -> DispatchResult {316 for (parent_id, child) in <TokenChildren<T>>::drain_prefix((collection_id,))317 .map(|((parent_id, child), _)| (parent_id, child)) {318319 let parent_address = T::CrossTokenAddressMapping::token_to_address(collection_id, parent_id);320 Self::burn_tree(parent_address, child.0, child.1, nesting_budget)?;321 }322323 Ok(())324 }325326 fn burn_tree(327 parent: T::CrossAccountId,328 collection_id: CollectionId,329 token_id: TokenId,330 nesting_budget: &dyn Budget331 ) -> DispatchResult {332 if !nesting_budget.consume() {333 return Err(<Error<T>>::TooManyChildrenToBurn.into());334 }335336 let handle = <CollectionHandle<T>>::try_get(collection_id)?;337 let handle = T::CollectionDispatch::dispatch(handle);338 let handle = handle.as_dyn();339340 let amount = handle.balance(parent.clone(), token_id);341342 handle.burn_item_unchecked(&parent, token_id, amount)?;343344 for child in <TokenChildren<T>>::drain_prefix((collection_id, token_id)).map(|(child, _)| child) {345 let parent = T::CrossTokenAddressMapping::token_to_address(collection_id, token_id);346 Self::burn_tree(parent, child.0, child.1, nesting_budget)?;347 }348349 Ok(())350 }351352 pub fn burn(353 collection: &NonfungibleHandle<T>,354 sender: &T::CrossAccountId,355 token: TokenId,356 ) -> DispatchResult {357 let token_data =358 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;359 ensure!(360 &token_data.owner == sender361 || (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),362 <CommonError<T>>::NoPermission363 );364365 if collection.permissions.access() == AccessMode::AllowList {366 collection.check_allowlist(sender)?;367 }368369 if Self::token_has_children(collection.id, token) {370 return Err(<Error<T>>::CantBurnNftWithChildren.into());371 }372373 let old_spender = <Allowance<T>>::get((collection.id, token));374375 // =========376377 Self::burn_item_unchecked(collection, &token_data.owner, token)?;378379 if let Some(old_spender) = old_spender {380 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(381 collection.id,382 token,383 sender.clone(),384 old_spender,385 0,386 ));387 }388389 <PalletEvm<T>>::deposit_log(390 ERC721Events::Transfer {391 from: *token_data.owner.as_eth(),392 to: H160::default(),393 token_id: token.into(),394 }395 .to_log(collection_id_to_address(collection.id)),396 );397 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(398 collection.id,399 token,400 token_data.owner,401 1,402 ));403 Ok(())404 }405406 pub fn burn_item_unchecked(407 collection: &NonfungibleHandle<T>,408 owner: &T::CrossAccountId,409 token: TokenId,410 ) -> DispatchResult {411 let burnt = <TokensBurnt<T>>::get(collection.id)412 .checked_add(1)413 .ok_or(ArithmeticError::Overflow)?;414415 let balance = <AccountBalance<T>>::get((collection.id, owner.clone()))416 .checked_sub(1)417 .ok_or(ArithmeticError::Overflow)?;418419 // =========420421 if let Some(owner) = T::CrossTokenAddressMapping::address_to_token(owner) {422 Self::unnest(owner, (collection.id, token));423 }424425 if balance == 0 {426 <AccountBalance<T>>::remove((collection.id, owner.clone()));427 } else {428 <AccountBalance<T>>::insert((collection.id, owner.clone()), balance);429 }430431 <Owned<T>>::remove((collection.id, owner, token));432 <TokensBurnt<T>>::insert(collection.id, burnt);433 <TokenData<T>>::remove((collection.id, token));434 <TokenProperties<T>>::remove((collection.id, token));435 <Allowance<T>>::remove((collection.id, token));436437 Ok(())438 }439440 pub fn set_token_property(441 collection: &NonfungibleHandle<T>,442 sender: &T::CrossAccountId,443 token_id: TokenId,444 property: Property,445 ) -> DispatchResult {446 Self::check_token_change_permission(collection, sender, token_id, &property.key)?;447448 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {449 let property = property.clone();450 properties.try_set(property.key, property.value)451 })452 .map_err(<CommonError<T>>::from)?;453454 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(455 collection.id,456 token_id,457 property.key,458 ));459460 Ok(())461 }462463 #[transactional]464 pub fn set_token_properties(465 collection: &NonfungibleHandle<T>,466 sender: &T::CrossAccountId,467 token_id: TokenId,468 properties: Vec<Property>,469 ) -> DispatchResult {470 for property in properties {471 Self::set_token_property(collection, sender, token_id, property)?;472 }473474 Ok(())475 }476477 pub fn delete_token_property(478 collection: &NonfungibleHandle<T>,479 sender: &T::CrossAccountId,480 token_id: TokenId,481 property_key: PropertyKey,482 ) -> DispatchResult {483 Self::check_token_change_permission(collection, sender, token_id, &property_key)?;484485 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {486 properties.remove(&property_key)487 })488 .map_err(<CommonError<T>>::from)?;489490 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(491 collection.id,492 token_id,493 property_key,494 ));495496 Ok(())497 }498499 fn check_token_change_permission(500 collection: &NonfungibleHandle<T>,501 sender: &T::CrossAccountId,502 token_id: TokenId,503 property_key: &PropertyKey,504 ) -> DispatchResult {505 let permission = <PalletCommon<T>>::property_permissions(collection.id)506 .get(property_key)507 .cloned()508 .unwrap_or_else(PropertyPermission::none);509510 let token_data = <TokenData<T>>::get((collection.id, token_id))511 .ok_or(<CommonError<T>>::TokenNotFound)?;512513 let check_token_owner = || -> DispatchResult {514 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);515 Ok(())516 };517518 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))519 .get(property_key)520 .is_some();521522 match permission {523 PropertyPermission { mutable: false, .. } if is_property_exists => {524 Err(<CommonError<T>>::NoPermission.into())525 }526527 PropertyPermission {528 collection_admin,529 token_owner,530 ..531 } => {532 let mut check_result = Err(<CommonError<T>>::NoPermission.into());533534 if collection_admin {535 check_result = collection.check_is_owner_or_admin(sender);536 }537538 if token_owner {539 check_result.or_else(|_| check_token_owner())540 } else {541 check_result542 }543 }544 }545 }546547 #[transactional]548 pub fn delete_token_properties(549 collection: &NonfungibleHandle<T>,550 sender: &T::CrossAccountId,551 token_id: TokenId,552 property_keys: Vec<PropertyKey>,553 ) -> DispatchResult {554 for key in property_keys {555 Self::delete_token_property(collection, sender, token_id, key)?;556 }557558 Ok(())559 }560561 pub fn set_collection_properties(562 collection: &NonfungibleHandle<T>,563 sender: &T::CrossAccountId,564 properties: Vec<Property>,565 ) -> DispatchResult {566 <PalletCommon<T>>::set_collection_properties(collection, sender, properties)567 }568569 pub fn delete_collection_properties(570 collection: &CollectionHandle<T>,571 sender: &T::CrossAccountId,572 property_keys: Vec<PropertyKey>,573 ) -> DispatchResult {574 <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)575 }576577 pub fn set_property_permissions(578 collection: &CollectionHandle<T>,579 sender: &T::CrossAccountId,580 property_permissions: Vec<PropertyKeyPermission>,581 ) -> DispatchResult {582 <PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)583 }584585 pub fn set_property_permission(586 collection: &CollectionHandle<T>,587 sender: &T::CrossAccountId,588 permission: PropertyKeyPermission,589 ) -> DispatchResult {590 <PalletCommon<T>>::set_property_permission(collection, sender, permission)591 }592593 pub fn transfer(594 collection: &NonfungibleHandle<T>,595 from: &T::CrossAccountId,596 to: &T::CrossAccountId,597 token: TokenId,598 nesting_budget: &dyn Budget,599 ) -> DispatchResult {600 ensure!(601 collection.limits.transfers_enabled(),602 <CommonError<T>>::TransferNotAllowed603 );604605 let token_data =606 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;607 // TODO: require sender to be token, owner, require admins to go through transfer_from608 ensure!(609 &token_data.owner == from610 || (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),611 <CommonError<T>>::NoPermission612 );613614 if collection.permissions.access() == AccessMode::AllowList {615 collection.check_allowlist(from)?;616 collection.check_allowlist(to)?;617 }618 <PalletCommon<T>>::ensure_correct_receiver(to)?;619620 let balance_from = <AccountBalance<T>>::get((collection.id, from))621 .checked_sub(1)622 .ok_or(<CommonError<T>>::TokenValueTooLow)?;623 let balance_to = if from != to {624 let balance_to = <AccountBalance<T>>::get((collection.id, to))625 .checked_add(1)626 .ok_or(ArithmeticError::Overflow)?;627628 ensure!(629 balance_to < collection.limits.account_token_ownership_limit(),630 <CommonError<T>>::AccountTokenLimitExceeded,631 );632633 Some(balance_to)634 } else {635 None636 };637638 <PalletStructure<T>>::try_nest_if_sent_to_token(639 from.clone(),640 to,641 collection.id,642 token,643 nesting_budget644 )?;645646 // =========647648 <TokenData<T>>::insert(649 (collection.id, token),650 ItemData {651 owner: to.clone(),652 ..token_data653 },654 );655656 if let Some(balance_to) = balance_to {657 // from != to658 if balance_from == 0 {659 <AccountBalance<T>>::remove((collection.id, from));660 } else {661 <AccountBalance<T>>::insert((collection.id, from), balance_from);662 }663 <AccountBalance<T>>::insert((collection.id, to), balance_to);664 <Owned<T>>::remove((collection.id, from, token));665 <Owned<T>>::insert((collection.id, to, token), true);666 }667 Self::set_allowance_unchecked(collection, from, token, None, true);668669 <PalletEvm<T>>::deposit_log(670 ERC721Events::Transfer {671 from: *from.as_eth(),672 to: *to.as_eth(),673 token_id: token.into(),674 }675 .to_log(collection_id_to_address(collection.id)),676 );677 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(678 collection.id,679 token,680 from.clone(),681 to.clone(),682 1,683 ));684 Ok(())685 }686687 pub fn create_multiple_items(688 collection: &NonfungibleHandle<T>,689 sender: &T::CrossAccountId,690 data: Vec<CreateItemData<T>>,691 nesting_budget: &dyn Budget,692 ) -> DispatchResult {693 if !collection.is_owner_or_admin(sender) {694 ensure!(695 collection.permissions.mint_mode(),696 <CommonError<T>>::PublicMintingNotAllowed697 );698 collection.check_allowlist(sender)?;699700 for item in data.iter() {701 collection.check_allowlist(&item.owner)?;702 }703 }704705 for data in data.iter() {706 <PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;707 }708709 let first_token = <TokensMinted<T>>::get(collection.id);710 let tokens_minted = first_token711 .checked_add(data.len() as u32)712 .ok_or(ArithmeticError::Overflow)?;713 ensure!(714 tokens_minted <= collection.limits.token_limit(),715 <CommonError<T>>::CollectionTokenLimitExceeded716 );717718 let mut balances = BTreeMap::new();719 for data in &data {720 let balance = balances721 .entry(&data.owner)722 .or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));723 *balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;724725 ensure!(726 *balance <= collection.limits.account_token_ownership_limit(),727 <CommonError<T>>::AccountTokenLimitExceeded,728 );729 }730731 for (i, data) in data.iter().enumerate() {732 let token = TokenId(first_token + i as u32 + 1);733734 <PalletStructure<T>>::check_nesting(735 sender.clone(),736 &data.owner,737 collection.id,738 token,739 nesting_budget,740 )?;741 }742743 // =========744745 with_transaction(|| {746 for (i, data) in data.iter().enumerate() {747 let token = first_token + i as u32 + 1;748749 <TokenData<T>>::insert(750 (collection.id, token),751 ItemData {752 // const_data: data.const_data.clone(),753 owner: data.owner.clone(),754 },755 );756757 <PalletStructure<T>>::nest_if_sent_to_token(&data.owner, collection.id, TokenId(token));758759 if let Err(e) = Self::set_token_properties(760 collection,761 sender,762 TokenId(token),763 data.properties.clone().into_inner(),764 ) {765 return TransactionOutcome::Rollback(Err(e));766 }767 }768 TransactionOutcome::Commit(Ok(()))769 })?;770771 <TokensMinted<T>>::insert(collection.id, tokens_minted);772 for (account, balance) in balances {773 <AccountBalance<T>>::insert((collection.id, account), balance);774 }775 for (i, data) in data.into_iter().enumerate() {776 let token = first_token + i as u32 + 1;777 <Owned<T>>::insert((collection.id, &data.owner, token), true);778779 <PalletEvm<T>>::deposit_log(780 ERC721Events::Transfer {781 from: H160::default(),782 to: *data.owner.as_eth(),783 token_id: token.into(),784 }785 .to_log(collection_id_to_address(collection.id)),786 );787 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(788 collection.id,789 TokenId(token),790 data.owner.clone(),791 1,792 ));793 }794 Ok(())795 }796797 pub fn set_allowance_unchecked(798 collection: &NonfungibleHandle<T>,799 sender: &T::CrossAccountId,800 token: TokenId,801 spender: Option<&T::CrossAccountId>,802 assume_implicit_eth: bool,803 ) {804 if let Some(spender) = spender {805 let old_spender = <Allowance<T>>::get((collection.id, token));806 <Allowance<T>>::insert((collection.id, token), spender);807 // In ERC721 there is only one possible approved user of token, so we set808 // approved user to spender809 <PalletEvm<T>>::deposit_log(810 ERC721Events::Approval {811 owner: *sender.as_eth(),812 approved: *spender.as_eth(),813 token_id: token.into(),814 }815 .to_log(collection_id_to_address(collection.id)),816 );817 // In Unique chain, any token can have any amount of approved users, so we need to818 // set allowance of old owner to 0, and allowance of new owner to 1819 if old_spender.as_ref() != Some(spender) {820 if let Some(old_owner) = old_spender {821 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(822 collection.id,823 token,824 sender.clone(),825 old_owner,826 0,827 ));828 }829 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(830 collection.id,831 token,832 sender.clone(),833 spender.clone(),834 1,835 ));836 }837 } else {838 let old_spender = <Allowance<T>>::take((collection.id, token));839 if !assume_implicit_eth {840 // In ERC721 there is only one possible approved user of token, so we set841 // approved user to zero address842 <PalletEvm<T>>::deposit_log(843 ERC721Events::Approval {844 owner: *sender.as_eth(),845 approved: H160::default(),846 token_id: token.into(),847 }848 .to_log(collection_id_to_address(collection.id)),849 );850 }851 // In Unique chain, any token can have any amount of approved users, so we need to852 // set allowance of old owner to 0853 if let Some(old_spender) = old_spender {854 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(855 collection.id,856 token,857 sender.clone(),858 old_spender,859 0,860 ));861 }862 }863 }864865 pub fn set_allowance(866 collection: &NonfungibleHandle<T>,867 sender: &T::CrossAccountId,868 token: TokenId,869 spender: Option<&T::CrossAccountId>,870 ) -> DispatchResult {871 if collection.permissions.access() == AccessMode::AllowList {872 collection.check_allowlist(sender)?;873 if let Some(spender) = spender {874 collection.check_allowlist(spender)?;875 }876 }877878 if let Some(spender) = spender {879 <PalletCommon<T>>::ensure_correct_receiver(spender)?;880 }881 let token_data =882 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;883 if &token_data.owner != sender {884 ensure!(885 collection.ignores_owned_amount(sender),886 <CommonError<T>>::CantApproveMoreThanOwned887 );888 }889890 // =========891892 Self::set_allowance_unchecked(collection, sender, token, spender, false);893 Ok(())894 }895896 fn check_allowed(897 collection: &NonfungibleHandle<T>,898 spender: &T::CrossAccountId,899 from: &T::CrossAccountId,900 token: TokenId,901 nesting_budget: &dyn Budget,902 ) -> DispatchResult {903 if spender.conv_eq(from) {904 return Ok(());905 }906 if collection.permissions.access() == AccessMode::AllowList {907 // `from`, `to` checked in [`transfer`]908 collection.check_allowlist(spender)?;909 }910 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {911 // TODO: should collection owner be allowed to perform this transfer?912 ensure!(913 <PalletStructure<T>>::check_indirectly_owned(914 spender.clone(),915 source.0,916 source.1,917 None,918 nesting_budget919 )?,920 <CommonError<T>>::ApprovedValueTooLow,921 );922 return Ok(());923 }924 if <Allowance<T>>::get((collection.id, token)).as_ref() == Some(spender) {925 return Ok(());926 }927 ensure!(928 collection.ignores_allowance(spender),929 <CommonError<T>>::ApprovedValueTooLow930 );931 Ok(())932 }933934 pub fn transfer_from(935 collection: &NonfungibleHandle<T>,936 spender: &T::CrossAccountId,937 from: &T::CrossAccountId,938 to: &T::CrossAccountId,939 token: TokenId,940 nesting_budget: &dyn Budget,941 ) -> DispatchResult {942 Self::check_allowed(collection, spender, from, token, nesting_budget)?;943944 // =========945946 // Allowance is reset in [`transfer`]947 Self::transfer(collection, from, to, token, nesting_budget)948 }949950 pub fn burn_from(951 collection: &NonfungibleHandle<T>,952 spender: &T::CrossAccountId,953 from: &T::CrossAccountId,954 token: TokenId,955 nesting_budget: &dyn Budget,956 ) -> DispatchResult {957 Self::check_allowed(collection, spender, from, token, nesting_budget)?;958959 // =========960961 Self::burn(collection, from, token)962 }963964 pub fn check_nesting(965 handle: &NonfungibleHandle<T>,966 sender: T::CrossAccountId,967 from: (CollectionId, TokenId),968 under: TokenId,969 nesting_budget: &dyn Budget,970 ) -> DispatchResult {971 fn ensure_sender_allowed<T: Config>(972 collection: CollectionId,973 token: TokenId,974 for_nest: (CollectionId, TokenId),975 sender: T::CrossAccountId,976 budget: &dyn Budget,977 ) -> DispatchResult {978 ensure!(979 <PalletStructure<T>>::check_indirectly_owned(980 sender,981 collection,982 token,983 Some(for_nest),984 budget985 )?,986 <CommonError<T>>::OnlyOwnerAllowedToNest,987 );988 Ok(())989 }990 match handle.permissions.nesting() {991 NestingRule::Disabled => fail!(<CommonError<T>>::NestingIsDisabled),992 NestingRule::Owner => {993 ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?994 }995 NestingRule::OwnerRestricted(whitelist) => {996 ensure!(997 whitelist.contains(&from.0),998 <CommonError<T>>::SourceCollectionIsNotAllowedToNest999 );1000 ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?1001 }1002 }1003 Ok(())1004 }10051006 fn nest(1007 under: (CollectionId, TokenId),1008 to_nest: (CollectionId, TokenId),1009 ) {1010 <TokenChildren<T>>::insert(1011 (under.0, under.1, (to_nest.0, to_nest.1)),1012 true1013 );1014 }10151016 fn unnest(1017 under: (CollectionId, TokenId),1018 to_unnest: (CollectionId, TokenId),1019 ) {1020 <TokenChildren<T>>::remove(1021 (under.0, under.1, to_unnest)1022 );1023 }10241025 fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {1026 <TokenChildren<T>>::iter_prefix((collection_id, token_id)).next().is_some()1027 }10281029 /// Delegated to `create_multiple_items`1030 pub fn create_item(1031 collection: &NonfungibleHandle<T>,1032 sender: &T::CrossAccountId,1033 data: CreateItemData<T>,1034 nesting_budget: &dyn Budget,1035 ) -> DispatchResult {1036 Self::create_multiple_items(collection, sender, vec![data], nesting_budget)1037 }1038}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use erc::ERC721Events;20use evm_coder::ToLog;21use frame_support::{BoundedVec, ensure, fail, transactional, storage::with_transaction};22use up_data_structs::{23 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,24 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,25 PropertyKey, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty,26};27use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};28use pallet_common::{29 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,30 eth::collection_id_to_address,31};32use pallet_structure::Pallet as PalletStructure;33use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};34use sp_core::H160;35use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};36use sp_std::{vec::Vec, vec, collections::btree_set::BTreeSet};37use core::ops::Deref;38use sp_std::collections::btree_map::BTreeMap;39use codec::{Encode, Decode, MaxEncodedLen};40use scale_info::TypeInfo;4142pub use pallet::*;43#[cfg(feature = "runtime-benchmarks")]44pub mod benchmarking;45pub mod common;46pub mod erc;47pub mod weights;4849pub type CreateItemData<T> = CreateNftExData<<T as pallet_evm::account::Config>::CrossAccountId>;50pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;5152#[struct_versioning::versioned(version = 2, upper)]53#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]54pub struct ItemData<CrossAccountId> {55 #[version(..2)]56 pub const_data: BoundedVec<u8, CustomDataLimit>,5758 #[version(..2)]59 pub variable_data: BoundedVec<u8, CustomDataLimit>,6061 pub owner: CrossAccountId,62}6364#[frame_support::pallet]65pub mod pallet {66 use super::*;67 use frame_support::{68 Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, traits::StorageVersion,69 };70 use frame_system::pallet_prelude::*;71 use up_data_structs::{CollectionId, TokenId};72 use super::weights::WeightInfo;7374 #[pallet::error]75 pub enum Error<T> {76 /// Not Nonfungible item data used to mint in Nonfungible collection.77 NotNonfungibleDataUsedToMintFungibleCollectionToken,78 /// Used amount > 1 with NFT79 NonfungibleItemsHaveNoAmount,80 /// Unable to burn NFT with children81 CantBurnNftWithChildren,82 }8384 #[pallet::config]85 pub trait Config:86 frame_system::Config + pallet_common::Config + pallet_structure::Config + pallet_evm::Config87 {88 type WeightInfo: WeightInfo;89 }9091 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);9293 #[pallet::pallet]94 #[pallet::storage_version(STORAGE_VERSION)]95 #[pallet::generate_store(pub(super) trait Store)]96 pub struct Pallet<T>(_);9798 #[pallet::storage]99 pub type TokensMinted<T: Config> =100 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;101 #[pallet::storage]102 pub type TokensBurnt<T: Config> =103 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;104105 #[pallet::storage]106 pub type TokenData<T: Config> = StorageNMap<107 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),108 Value = ItemData<T::CrossAccountId>,109 QueryKind = OptionQuery,110 >;111112 #[pallet::storage]113 #[pallet::getter(fn token_properties)]114 pub type TokenProperties<T: Config> = StorageNMap<115 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),116 Value = Properties,117 QueryKind = ValueQuery,118 OnEmpty = up_data_structs::TokenProperties,119 >;120121 /// Used to enumerate tokens owned by account122 #[pallet::storage]123 pub type Owned<T: Config> = StorageNMap<124 Key = (125 Key<Twox64Concat, CollectionId>,126 Key<Blake2_128Concat, T::CrossAccountId>,127 Key<Twox64Concat, TokenId>,128 ),129 Value = bool,130 QueryKind = ValueQuery,131 >;132133 /// Used to enumerate token's children134 #[pallet::storage]135 #[pallet::getter(fn token_children)]136 pub type TokenChildren<T: Config> = StorageNMap<137 Key = (138 Key<Twox64Concat, CollectionId>,139 Key<Twox64Concat, TokenId>,140 Key<Twox64Concat, (CollectionId, TokenId)>,141 ),142 Value = bool,143 QueryKind = ValueQuery,144 >;145146 #[pallet::storage]147 pub type AccountBalance<T: Config> = StorageNMap<148 Key = (149 Key<Twox64Concat, CollectionId>,150 Key<Blake2_128Concat, T::CrossAccountId>,151 ),152 Value = u32,153 QueryKind = ValueQuery,154 >;155156 #[pallet::storage]157 pub type Allowance<T: Config> = StorageNMap<158 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),159 Value = T::CrossAccountId,160 QueryKind = OptionQuery,161 >;162163 #[pallet::hooks]164 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {165 fn on_runtime_upgrade() -> Weight {166 if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {167 let mut had_consts = BTreeSet::new();168 <TokenData<T>>::translate::<ItemDataVersion1<T::CrossAccountId>, _>(|(collection, token), v| {169 let mut props = vec![];170 if !v.const_data.is_empty() {171 props.push(Property {172 key: b"_old_constData".to_vec().try_into().unwrap(),173 value: v.const_data.clone().into_inner().try_into().expect("const too long"),174 });175 had_consts.insert(collection);176 }177 if !v.variable_data.is_empty() {178 props.push(Property {179 key: b"_old_variableData".to_vec().try_into().unwrap(),180 value: v.variable_data.clone().into_inner().try_into().expect("variable too long"),181 })182 }183 if !props.is_empty() {184 Self::set_scoped_token_properties(185 collection,186 token,187 PropertyScope::None,188 props.into_iter(),189 ).expect("existing token data exceeds property storage");190 }191 Some(<ItemDataVersion2<T::CrossAccountId>>::from(v))192 });193 for collection in had_consts {194 <PalletCommon<T>>::set_property_permission_unchecked(195 collection,196 PropertyKeyPermission {197 key: b"_old_constData".to_vec().try_into().unwrap(),198 permission: PropertyPermission {199 mutable: false,200 collection_admin: true,201 token_owner: false,202 },203 }204 ).expect("failed to configure permission");205 }206 }207208 0209 }210 }211}212213pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);214impl<T: Config> NonfungibleHandle<T> {215 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {216 Self(inner)217 }218 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {219 self.0220 }221 pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {222 &mut self.0223 }224}225impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {226 fn recorder(&self) -> &SubstrateRecorder<T> {227 self.0.recorder()228 }229 fn into_recorder(self) -> SubstrateRecorder<T> {230 self.0.into_recorder()231 }232}233impl<T: Config> Deref for NonfungibleHandle<T> {234 type Target = pallet_common::CollectionHandle<T>;235236 fn deref(&self) -> &Self::Target {237 &self.0238 }239}240241impl<T: Config> Pallet<T> {242 pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {243 <TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)244 }245 pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {246 <TokenData<T>>::contains_key((collection.id, token))247 }248249 pub fn set_scoped_token_property(250 collection_id: CollectionId,251 token_id: TokenId,252 scope: PropertyScope,253 property: Property,254 ) -> DispatchResult {255 TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {256 properties.try_scoped_set(scope, property.key, property.value)257 })258 .map_err(<CommonError<T>>::from)?;259260 Ok(())261 }262263 pub fn set_scoped_token_properties(264 collection_id: CollectionId,265 token_id: TokenId,266 scope: PropertyScope,267 properties: impl Iterator<Item=Property>,268 ) -> DispatchResult {269 TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {270 stored_properties.try_scoped_set_from_iter(scope, properties)271 })272 .map_err(<CommonError<T>>::from)?;273274 Ok(())275 }276277 pub fn current_token_id(collection_id: CollectionId) -> TokenId {278 TokenId(<TokensMinted<T>>::get(collection_id))279 }280}281282// unchecked calls skips any permission checks283impl<T: Config> Pallet<T> {284 pub fn init_collection(285 owner: T::AccountId,286 data: CreateCollectionData<T::AccountId>,287 ) -> Result<CollectionId, DispatchError> {288 <PalletCommon<T>>::init_collection(owner, data)289 }290 pub fn destroy_collection(291 collection: NonfungibleHandle<T>,292 sender: &T::CrossAccountId,293 ) -> DispatchResult {294 let id = collection.id;295296 // =========297298 PalletCommon::destroy_collection(collection.0, sender)?;299300 <TokenData<T>>::remove_prefix((id,), None);301 <TokenChildren<T>>::remove_prefix((id,), None);302 <Owned<T>>::remove_prefix((id,), None);303 <TokensMinted<T>>::remove(id);304 <TokensBurnt<T>>::remove(id);305 <Allowance<T>>::remove_prefix((id,), None);306 <AccountBalance<T>>::remove_prefix((id,), None);307 Ok(())308 }309310 pub fn burn(311 collection: &NonfungibleHandle<T>,312 sender: &T::CrossAccountId,313 token: TokenId,314 ) -> DispatchResult {315 let token_data =316 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;317 ensure!(318 &token_data.owner == sender319 || (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),320 <CommonError<T>>::NoPermission321 );322323 if collection.permissions.access() == AccessMode::AllowList {324 collection.check_allowlist(sender)?;325 }326327 if Self::token_has_children(collection.id, token) {328 return Err(<Error<T>>::CantBurnNftWithChildren.into());329 }330331 let burnt = <TokensBurnt<T>>::get(collection.id)332 .checked_add(1)333 .ok_or(ArithmeticError::Overflow)?;334335 let balance = <AccountBalance<T>>::get((collection.id, token_data.owner.clone()))336 .checked_sub(1)337 .ok_or(ArithmeticError::Overflow)?;338339 if balance == 0 {340 <AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));341 } else {342 <AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);343 }344345 if let Some(owner) = T::CrossTokenAddressMapping::address_to_token(&token_data.owner) {346 Self::unnest(owner, (collection.id, token));347 }348349 // =========350351 <Owned<T>>::remove((collection.id, &token_data.owner, token));352 <TokensBurnt<T>>::insert(collection.id, burnt);353 <TokenData<T>>::remove((collection.id, token));354 <TokenProperties<T>>::remove((collection.id, token));355 let old_spender = <Allowance<T>>::take((collection.id, token));356357 if let Some(old_spender) = old_spender {358 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(359 collection.id,360 token,361 sender.clone(),362 old_spender,363 0,364 ));365 }366367 <PalletEvm<T>>::deposit_log(368 ERC721Events::Transfer {369 from: *token_data.owner.as_eth(),370 to: H160::default(),371 token_id: token.into(),372 }373 .to_log(collection_id_to_address(collection.id)),374 );375 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(376 collection.id,377 token,378 token_data.owner,379 1,380 ));381 Ok(())382 }383384 pub fn set_token_property(385 collection: &NonfungibleHandle<T>,386 sender: &T::CrossAccountId,387 token_id: TokenId,388 property: Property,389 ) -> DispatchResult {390 Self::check_token_change_permission(collection, sender, token_id, &property.key)?;391392 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {393 let property = property.clone();394 properties.try_set(property.key, property.value)395 })396 .map_err(<CommonError<T>>::from)?;397398 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(399 collection.id,400 token_id,401 property.key,402 ));403404 Ok(())405 }406407 #[transactional]408 pub fn set_token_properties(409 collection: &NonfungibleHandle<T>,410 sender: &T::CrossAccountId,411 token_id: TokenId,412 properties: Vec<Property>,413 ) -> DispatchResult {414 for property in properties {415 Self::set_token_property(collection, sender, token_id, property)?;416 }417418 Ok(())419 }420421 pub fn delete_token_property(422 collection: &NonfungibleHandle<T>,423 sender: &T::CrossAccountId,424 token_id: TokenId,425 property_key: PropertyKey,426 ) -> DispatchResult {427 Self::check_token_change_permission(collection, sender, token_id, &property_key)?;428429 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {430 properties.remove(&property_key)431 })432 .map_err(<CommonError<T>>::from)?;433434 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(435 collection.id,436 token_id,437 property_key,438 ));439440 Ok(())441 }442443 fn check_token_change_permission(444 collection: &NonfungibleHandle<T>,445 sender: &T::CrossAccountId,446 token_id: TokenId,447 property_key: &PropertyKey,448 ) -> DispatchResult {449 let permission = <PalletCommon<T>>::property_permissions(collection.id)450 .get(property_key)451 .cloned()452 .unwrap_or_else(PropertyPermission::none);453454 let token_data = <TokenData<T>>::get((collection.id, token_id))455 .ok_or(<CommonError<T>>::TokenNotFound)?;456457 let check_token_owner = || -> DispatchResult {458 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);459 Ok(())460 };461462 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))463 .get(property_key)464 .is_some();465466 match permission {467 PropertyPermission { mutable: false, .. } if is_property_exists => {468 Err(<CommonError<T>>::NoPermission.into())469 }470471 PropertyPermission {472 collection_admin,473 token_owner,474 ..475 } => {476 let mut check_result = Err(<CommonError<T>>::NoPermission.into());477478 if collection_admin {479 check_result = collection.check_is_owner_or_admin(sender);480 }481482 if token_owner {483 check_result.or_else(|_| check_token_owner())484 } else {485 check_result486 }487 }488 }489 }490491 #[transactional]492 pub fn delete_token_properties(493 collection: &NonfungibleHandle<T>,494 sender: &T::CrossAccountId,495 token_id: TokenId,496 property_keys: Vec<PropertyKey>,497 ) -> DispatchResult {498 for key in property_keys {499 Self::delete_token_property(collection, sender, token_id, key)?;500 }501502 Ok(())503 }504505 pub fn set_collection_properties(506 collection: &NonfungibleHandle<T>,507 sender: &T::CrossAccountId,508 properties: Vec<Property>,509 ) -> DispatchResult {510 <PalletCommon<T>>::set_collection_properties(collection, sender, properties)511 }512513 pub fn delete_collection_properties(514 collection: &CollectionHandle<T>,515 sender: &T::CrossAccountId,516 property_keys: Vec<PropertyKey>,517 ) -> DispatchResult {518 <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)519 }520521 pub fn set_property_permissions(522 collection: &CollectionHandle<T>,523 sender: &T::CrossAccountId,524 property_permissions: Vec<PropertyKeyPermission>,525 ) -> DispatchResult {526 <PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)527 }528529 pub fn set_property_permission(530 collection: &CollectionHandle<T>,531 sender: &T::CrossAccountId,532 permission: PropertyKeyPermission,533 ) -> DispatchResult {534 <PalletCommon<T>>::set_property_permission(collection, sender, permission)535 }536537 pub fn transfer(538 collection: &NonfungibleHandle<T>,539 from: &T::CrossAccountId,540 to: &T::CrossAccountId,541 token: TokenId,542 nesting_budget: &dyn Budget,543 ) -> DispatchResult {544 ensure!(545 collection.limits.transfers_enabled(),546 <CommonError<T>>::TransferNotAllowed547 );548549 let token_data =550 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;551 // TODO: require sender to be token, owner, require admins to go through transfer_from552 ensure!(553 &token_data.owner == from554 || (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),555 <CommonError<T>>::NoPermission556 );557558 if collection.permissions.access() == AccessMode::AllowList {559 collection.check_allowlist(from)?;560 collection.check_allowlist(to)?;561 }562 <PalletCommon<T>>::ensure_correct_receiver(to)?;563564 let balance_from = <AccountBalance<T>>::get((collection.id, from))565 .checked_sub(1)566 .ok_or(<CommonError<T>>::TokenValueTooLow)?;567 let balance_to = if from != to {568 let balance_to = <AccountBalance<T>>::get((collection.id, to))569 .checked_add(1)570 .ok_or(ArithmeticError::Overflow)?;571572 ensure!(573 balance_to < collection.limits.account_token_ownership_limit(),574 <CommonError<T>>::AccountTokenLimitExceeded,575 );576577 Some(balance_to)578 } else {579 None580 };581582 <PalletStructure<T>>::try_nest_if_sent_to_token(583 from.clone(),584 to,585 collection.id,586 token,587 nesting_budget588 )?;589590 // =========591592 <TokenData<T>>::insert(593 (collection.id, token),594 ItemData {595 owner: to.clone(),596 ..token_data597 },598 );599600 if let Some(balance_to) = balance_to {601 // from != to602 if balance_from == 0 {603 <AccountBalance<T>>::remove((collection.id, from));604 } else {605 <AccountBalance<T>>::insert((collection.id, from), balance_from);606 }607 <AccountBalance<T>>::insert((collection.id, to), balance_to);608 <Owned<T>>::remove((collection.id, from, token));609 <Owned<T>>::insert((collection.id, to, token), true);610 }611 Self::set_allowance_unchecked(collection, from, token, None, true);612613 <PalletEvm<T>>::deposit_log(614 ERC721Events::Transfer {615 from: *from.as_eth(),616 to: *to.as_eth(),617 token_id: token.into(),618 }619 .to_log(collection_id_to_address(collection.id)),620 );621 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(622 collection.id,623 token,624 from.clone(),625 to.clone(),626 1,627 ));628 Ok(())629 }630631 pub fn create_multiple_items(632 collection: &NonfungibleHandle<T>,633 sender: &T::CrossAccountId,634 data: Vec<CreateItemData<T>>,635 nesting_budget: &dyn Budget,636 ) -> DispatchResult {637 if !collection.is_owner_or_admin(sender) {638 ensure!(639 collection.permissions.mint_mode(),640 <CommonError<T>>::PublicMintingNotAllowed641 );642 collection.check_allowlist(sender)?;643644 for item in data.iter() {645 collection.check_allowlist(&item.owner)?;646 }647 }648649 for data in data.iter() {650 <PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;651 }652653 let first_token = <TokensMinted<T>>::get(collection.id);654 let tokens_minted = first_token655 .checked_add(data.len() as u32)656 .ok_or(ArithmeticError::Overflow)?;657 ensure!(658 tokens_minted <= collection.limits.token_limit(),659 <CommonError<T>>::CollectionTokenLimitExceeded660 );661662 let mut balances = BTreeMap::new();663 for data in &data {664 let balance = balances665 .entry(&data.owner)666 .or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));667 *balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;668669 ensure!(670 *balance <= collection.limits.account_token_ownership_limit(),671 <CommonError<T>>::AccountTokenLimitExceeded,672 );673 }674675 for (i, data) in data.iter().enumerate() {676 let token = TokenId(first_token + i as u32 + 1);677678 <PalletStructure<T>>::check_nesting(679 sender.clone(),680 &data.owner,681 collection.id,682 token,683 nesting_budget,684 )?;685 }686687 // =========688689 with_transaction(|| {690 for (i, data) in data.iter().enumerate() {691 let token = first_token + i as u32 + 1;692693 <TokenData<T>>::insert(694 (collection.id, token),695 ItemData {696 // const_data: data.const_data.clone(),697 owner: data.owner.clone(),698 },699 );700701 <PalletStructure<T>>::nest_if_sent_to_token(&data.owner, collection.id, TokenId(token));702703 if let Err(e) = Self::set_token_properties(704 collection,705 sender,706 TokenId(token),707 data.properties.clone().into_inner(),708 ) {709 return TransactionOutcome::Rollback(Err(e));710 }711 }712 TransactionOutcome::Commit(Ok(()))713 })?;714715 <TokensMinted<T>>::insert(collection.id, tokens_minted);716 for (account, balance) in balances {717 <AccountBalance<T>>::insert((collection.id, account), balance);718 }719 for (i, data) in data.into_iter().enumerate() {720 let token = first_token + i as u32 + 1;721 <Owned<T>>::insert((collection.id, &data.owner, token), true);722723 <PalletEvm<T>>::deposit_log(724 ERC721Events::Transfer {725 from: H160::default(),726 to: *data.owner.as_eth(),727 token_id: token.into(),728 }729 .to_log(collection_id_to_address(collection.id)),730 );731 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(732 collection.id,733 TokenId(token),734 data.owner.clone(),735 1,736 ));737 }738 Ok(())739 }740741 pub fn set_allowance_unchecked(742 collection: &NonfungibleHandle<T>,743 sender: &T::CrossAccountId,744 token: TokenId,745 spender: Option<&T::CrossAccountId>,746 assume_implicit_eth: bool,747 ) {748 if let Some(spender) = spender {749 let old_spender = <Allowance<T>>::get((collection.id, token));750 <Allowance<T>>::insert((collection.id, token), spender);751 // In ERC721 there is only one possible approved user of token, so we set752 // approved user to spender753 <PalletEvm<T>>::deposit_log(754 ERC721Events::Approval {755 owner: *sender.as_eth(),756 approved: *spender.as_eth(),757 token_id: token.into(),758 }759 .to_log(collection_id_to_address(collection.id)),760 );761 // In Unique chain, any token can have any amount of approved users, so we need to762 // set allowance of old owner to 0, and allowance of new owner to 1763 if old_spender.as_ref() != Some(spender) {764 if let Some(old_owner) = old_spender {765 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(766 collection.id,767 token,768 sender.clone(),769 old_owner,770 0,771 ));772 }773 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(774 collection.id,775 token,776 sender.clone(),777 spender.clone(),778 1,779 ));780 }781 } else {782 let old_spender = <Allowance<T>>::take((collection.id, token));783 if !assume_implicit_eth {784 // In ERC721 there is only one possible approved user of token, so we set785 // approved user to zero address786 <PalletEvm<T>>::deposit_log(787 ERC721Events::Approval {788 owner: *sender.as_eth(),789 approved: H160::default(),790 token_id: token.into(),791 }792 .to_log(collection_id_to_address(collection.id)),793 );794 }795 // In Unique chain, any token can have any amount of approved users, so we need to796 // set allowance of old owner to 0797 if let Some(old_spender) = old_spender {798 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(799 collection.id,800 token,801 sender.clone(),802 old_spender,803 0,804 ));805 }806 }807 }808809 pub fn set_allowance(810 collection: &NonfungibleHandle<T>,811 sender: &T::CrossAccountId,812 token: TokenId,813 spender: Option<&T::CrossAccountId>,814 ) -> DispatchResult {815 if collection.permissions.access() == AccessMode::AllowList {816 collection.check_allowlist(sender)?;817 if let Some(spender) = spender {818 collection.check_allowlist(spender)?;819 }820 }821822 if let Some(spender) = spender {823 <PalletCommon<T>>::ensure_correct_receiver(spender)?;824 }825 let token_data =826 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;827 if &token_data.owner != sender {828 ensure!(829 collection.ignores_owned_amount(sender),830 <CommonError<T>>::CantApproveMoreThanOwned831 );832 }833834 // =========835836 Self::set_allowance_unchecked(collection, sender, token, spender, false);837 Ok(())838 }839840 fn check_allowed(841 collection: &NonfungibleHandle<T>,842 spender: &T::CrossAccountId,843 from: &T::CrossAccountId,844 token: TokenId,845 nesting_budget: &dyn Budget,846 ) -> DispatchResult {847 if spender.conv_eq(from) {848 return Ok(());849 }850 if collection.permissions.access() == AccessMode::AllowList {851 // `from`, `to` checked in [`transfer`]852 collection.check_allowlist(spender)?;853 }854 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {855 // TODO: should collection owner be allowed to perform this transfer?856 ensure!(857 <PalletStructure<T>>::check_indirectly_owned(858 spender.clone(),859 source.0,860 source.1,861 None,862 nesting_budget863 )?,864 <CommonError<T>>::ApprovedValueTooLow,865 );866 return Ok(());867 }868 if <Allowance<T>>::get((collection.id, token)).as_ref() == Some(spender) {869 return Ok(());870 }871 ensure!(872 collection.ignores_allowance(spender),873 <CommonError<T>>::ApprovedValueTooLow874 );875 Ok(())876 }877878 pub fn transfer_from(879 collection: &NonfungibleHandle<T>,880 spender: &T::CrossAccountId,881 from: &T::CrossAccountId,882 to: &T::CrossAccountId,883 token: TokenId,884 nesting_budget: &dyn Budget,885 ) -> DispatchResult {886 Self::check_allowed(collection, spender, from, token, nesting_budget)?;887888 // =========889890 // Allowance is reset in [`transfer`]891 Self::transfer(collection, from, to, token, nesting_budget)892 }893894 pub fn burn_from(895 collection: &NonfungibleHandle<T>,896 spender: &T::CrossAccountId,897 from: &T::CrossAccountId,898 token: TokenId,899 nesting_budget: &dyn Budget,900 ) -> DispatchResult {901 Self::check_allowed(collection, spender, from, token, nesting_budget)?;902903 // =========904905 Self::burn(collection, from, token)906 }907908 pub fn check_nesting(909 handle: &NonfungibleHandle<T>,910 sender: T::CrossAccountId,911 from: (CollectionId, TokenId),912 under: TokenId,913 nesting_budget: &dyn Budget,914 ) -> DispatchResult {915 fn ensure_sender_allowed<T: Config>(916 collection: CollectionId,917 token: TokenId,918 for_nest: (CollectionId, TokenId),919 sender: T::CrossAccountId,920 budget: &dyn Budget,921 ) -> DispatchResult {922 ensure!(923 <PalletStructure<T>>::check_indirectly_owned(924 sender,925 collection,926 token,927 Some(for_nest),928 budget929 )?,930 <CommonError<T>>::OnlyOwnerAllowedToNest,931 );932 Ok(())933 }934 match handle.permissions.nesting() {935 NestingRule::Disabled => fail!(<CommonError<T>>::NestingIsDisabled),936 NestingRule::Owner => {937 ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?938 }939 NestingRule::OwnerRestricted(whitelist) => {940 ensure!(941 whitelist.contains(&from.0),942 <CommonError<T>>::SourceCollectionIsNotAllowedToNest943 );944 ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?945 }946 }947 Ok(())948 }949950 fn nest(951 under: (CollectionId, TokenId),952 to_nest: (CollectionId, TokenId),953 ) {954 <TokenChildren<T>>::insert(955 (under.0, under.1, (to_nest.0, to_nest.1)),956 true957 );958 }959960 fn unnest(961 under: (CollectionId, TokenId),962 to_unnest: (CollectionId, TokenId),963 ) {964 <TokenChildren<T>>::remove(965 (under.0, under.1, to_unnest)966 );967 }968969 fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {970 <TokenChildren<T>>::iter_prefix((collection_id, token_id)).next().is_some()971 }972973 /// Delegated to `create_multiple_items`974 pub fn create_item(975 collection: &NonfungibleHandle<T>,976 sender: &T::CrossAccountId,977 data: CreateItemData<T>,978 nesting_budget: &dyn Budget,979 ) -> DispatchResult {980 Self::create_multiple_items(collection, sender, vec![data], nesting_budget)981 }982}pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -179,8 +179,7 @@
ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
- let empty_budget = budget::Value::new(0);
- <PalletNft<T>>::destroy_collection(collection, &cross_sender, &empty_budget)
+ <PalletNft<T>>::destroy_collection(collection, &cross_sender)
.map_err(Self::map_common_err_to_proxy)?;
Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -205,15 +205,6 @@
)
}
- fn burn_item_unchecked(
- &self,
- owner: &T::CrossAccountId,
- token: TokenId,
- amount: u128,
- ) -> sp_runtime::DispatchResult {
- <Pallet<T>>::burn_item_unchecked(self, owner, token, amount)
- }
-
fn transfer(
&self,
from: T::CrossAccountId,
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -245,25 +245,6 @@
token: TokenId,
amount: u128,
) -> DispatchResult {
- Self::burn_item_unchecked(collection, owner, token, amount)?;
-
- // TODO: ERC20 transfer event
- <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
- collection.id,
- token,
- owner.clone(),
- amount,
- ));
-
- Ok(())
- }
-
- pub fn burn_item_unchecked(
- collection: &RefungibleHandle<T>,
- owner: &T::CrossAccountId,
- token: TokenId,
- amount: u128,
- ) -> DispatchResult {
let total_supply = <TotalSupply<T>>::get((collection.id, token))
.checked_sub(amount)
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
@@ -318,6 +299,13 @@
<Balance<T>>::insert((collection.id, token, owner), balance);
}
<TotalSupply<T>>::insert((collection.id, token), total_supply);
+ // TODO: ERC20 transfer event
+ <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
+ collection.id,
+ token,
+ owner.clone(),
+ amount,
+ ));
Ok(())
}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -332,24 +332,15 @@
/// # Arguments
///
/// * collection_id: collection to destroy.
- #[weight =
- <SelfWeightOf<T>>::destroy_collection()
- + <SelfWeightOf<T>>::burn_children_in_collection(*max_children_to_burn)
- ]
+ #[weight = <SelfWeightOf<T>>::destroy_collection()]
#[transactional]
- pub fn destroy_collection(
- origin,
- collection_id: CollectionId,
- max_children_to_burn: u32,
- ) -> DispatchResult {
+ pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
- let budget = budget::Value::new(max_children_to_burn);
-
// =========
- T::CollectionDispatch::destroy(sender, collection, &budget)?;
+ T::CollectionDispatch::destroy(sender, collection)?;
<NftTransferBasket<T>>::remove_prefix(collection_id, None);
<FungibleTransferBasket<T>>::remove_prefix(collection_id, None);
pallets/unique/src/weights.rsdiffbeforeafterboth--- a/pallets/unique/src/weights.rs
+++ b/pallets/unique/src/weights.rs
@@ -34,7 +34,6 @@
pub trait WeightInfo {
fn create_collection() -> Weight;
fn destroy_collection() -> Weight;
- fn burn_children_in_collection(max: u32) -> Weight;
fn add_to_allow_list() -> Weight;
fn remove_from_allow_list() -> Weight;
fn set_public_access_mode() -> Weight;
@@ -74,12 +73,6 @@
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
-
- fn burn_children_in_collection(max: u32) -> Weight {
- // TODO
- (50_000_000 as Weight).saturating_mul(max as Weight)
- }
-
// Storage: Common CollectionById (r:1 w:0)
// Storage: Common Allowlist (r:0 w:1)
fn add_to_allow_list() -> Weight {
@@ -199,12 +192,6 @@
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
}
-
- fn burn_children_in_collection(max: u32) -> Weight {
- // TODO
- (50_000_000 as Weight).saturating_mul(max as Weight)
- }
-
// Storage: Common CollectionById (r:1 w:0)
// Storage: Common Allowlist (r:0 w:1)
fn add_to_allow_list() -> Weight {
runtime/common/src/dispatch.rsdiffbeforeafterboth--- a/runtime/common/src/dispatch.rs
+++ b/runtime/common/src/dispatch.rs
@@ -1,4 +1,4 @@
-use frame_support::{dispatch::{DispatchResult}, ensure};
+use frame_support::{dispatch::DispatchResult, ensure};
use pallet_evm::PrecompileResult;
use sp_core::{H160, U256};
use sp_std::{borrow::ToOwned, vec::Vec};
@@ -12,7 +12,6 @@
use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle, erc::RefungibleTokenHandle};
use up_data_structs::{
CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,
- budget::Budget,
};
pub enum CollectionDispatchT<T>
@@ -47,11 +46,7 @@
Ok(())
}
- fn destroy(
- sender: T::CrossAccountId,
- collection: CollectionHandle<T>,
- nesting_budget: &dyn Budget,
- ) -> DispatchResult {
+ fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {
match collection.mode {
CollectionMode::ReFungible => {
PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?
@@ -60,11 +55,7 @@
PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?
}
CollectionMode::NFT => {
- PalletNonfungible::destroy_collection(
- NonfungibleHandle::cast(collection),
- &sender,
- nesting_budget,
- )?
+ PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?
}
}
Ok(())