git.delta.rocks / unique-network / refs/commits / 2050a76c8808

difftreelog

feat external-internal api collection creation segreation

Fahrrader2022-06-08parent: #0cb9e74.patch.diff
in: master

11 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
36 },36 },
37 error,37 error,
38 })?;38 })?;
39 handle.check_is_internal().map_err(|error| DispatchErrorWithPostInfo {
40 post_info: PostDispatchInfo {
41 actual_weight: Some(dispatch_weight::<T>()),
42 pays_fee: Pays::Yes,
43 },
44 error,
45 })?;
39 let dispatched = T::CollectionDispatch::dispatch(handle);46 let dispatched = T::CollectionDispatch::dispatch(handle);
40 let mut result = call(dispatched.as_dyn());47 let mut result = call(dispatched.as_dyn());
41 match &mut result {48 match &mut result {
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
316}316}
317317
318fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {318fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {
319 // TODO possibly delete for the lack of transaction
319 collection320 collection
320 .check_is_mutable()321 .check_is_internal()
321 .map_err(dispatch_to_evm::<T>)?;322 .map_err(dispatch_to_evm::<T>)?;
322 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());323 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
323 Ok(())324 Ok(())
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
149 ))149 ))
150 }150 }
151 pub fn save(self) -> Result<(), DispatchError> {151 pub fn save(self) -> Result<(), DispatchError> {
152 self.check_is_mutable()?;
153 <CollectionById<T>>::insert(self.id, self.collection);152 <CollectionById<T>>::insert(self.id, self.collection);
154 Ok(())153 Ok(())
155 }154 }
156155
157 pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {156 pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {
158 self.check_is_mutable()?;
159 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);157 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);
160 Ok(())158 Ok(())
161 }159 }
162160
163 pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {161 pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {
164 self.check_is_mutable()?;
165
166 if self.collection.sponsorship.pending_sponsor() != Some(sender) {162 if self.collection.sponsorship.pending_sponsor() != Some(sender) {
167 return Ok(false);163 return Ok(false);
171 Ok(true)167 Ok(true)
172 }168 }
173169
174 /// Checks that collection is can be mutate.170 /// Checks that the collection was created with, and must be operated upon through **Unique API**.
175 /// Now check only `external_collection` flag and if it **true**, than return `CollectionIsReadOnly` error.171 /// Now check only the `external_collection` flag and if it's **true**, then return `CollectionIsExternal` error.
176 pub fn check_is_mutable(&self) -> DispatchResult {172 pub fn check_is_internal(&self) -> DispatchResult {
177 if self.external_collection {173 if self.external_collection {
178 return Err(<Error<T>>::CollectionIsReadOnly)?;174 return Err(<Error<T>>::CollectionIsExternal)?;
179 }175 }
180176
181 Ok(())177 Ok(())
182 }178 }
179
180 /// Checks that the collection was created with, and must be operated upon through an **assimilated API**.
181 /// Now check only the `external_collection` flag and if it's **false**, then return `CollectionIsInternal` error.
182 pub fn check_is_external(&self) -> DispatchResult {
183 if !self.external_collection {
184 return Err(<Error<T>>::CollectionIsInternal)?;
185 }
186
187 Ok(())
188 }
183}189}
184190
185impl<T: Config> Deref for CollectionHandle<T> {191impl<T: Config> Deref for CollectionHandle<T> {
449 /// Empty property keys are forbidden455 /// Empty property keys are forbidden
450 EmptyPropertyKey,456 EmptyPropertyKey,
451457
452 /// Collection is read only458 /// Tried to access an external collection with an internal API
459 CollectionIsExternal,
460
461 /// Tried to access an internal collection with an external API
453 CollectionIsReadOnly,462 CollectionIsInternal,
454 }463 }
455464
456 #[pallet::storage]465 #[pallet::storage]
754 pub fn init_collection(763 pub fn init_collection(
755 owner: T::CrossAccountId,764 owner: T::CrossAccountId,
756 data: CreateCollectionData<T::AccountId>,765 data: CreateCollectionData<T::AccountId>,
766 is_external: bool,
757 ) -> Result<CollectionId, DispatchError> {767 ) -> Result<CollectionId, DispatchError> {
758 {768 {
759 ensure!(769 ensure!(
797 Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)807 Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)
798 })808 })
799 .unwrap_or_else(|| Ok(CollectionPermissions::default()))?,809 .unwrap_or_else(|| Ok(CollectionPermissions::default()))?,
800 external_collection: false,810 external_collection: is_external,
801 };811 };
802812
803 let mut collection_properties = up_data_structs::CollectionProperties::get();813 let mut collection_properties = up_data_structs::CollectionProperties::get();
854 collection: CollectionHandle<T>,864 collection: CollectionHandle<T>,
855 sender: &T::CrossAccountId,865 sender: &T::CrossAccountId,
856 ) -> DispatchResult {866 ) -> DispatchResult {
857 collection.check_is_mutable()?;
858 ensure!(867 ensure!(
859 collection.limits.owner_can_destroy(),868 collection.limits.owner_can_destroy(),
860 <Error<T>>::NoPermission,869 <Error<T>>::NoPermission,
884 sender: &T::CrossAccountId,893 sender: &T::CrossAccountId,
885 property: Property,894 property: Property,
886 ) -> DispatchResult {895 ) -> DispatchResult {
887 collection.check_is_mutable()?;
888 collection.check_is_owner_or_admin(sender)?;896 collection.check_is_owner_or_admin(sender)?;
889897
890 CollectionProperties::<T>::try_mutate(collection.id, |properties| {898 CollectionProperties::<T>::try_mutate(collection.id, |properties| {
930 sender: &T::CrossAccountId,938 sender: &T::CrossAccountId,
931 properties: Vec<Property>,939 properties: Vec<Property>,
932 ) -> DispatchResult {940 ) -> DispatchResult {
933 collection.check_is_mutable()?;
934
935 for property in properties {941 for property in properties {
936 Self::set_collection_property(collection, sender, property)?;942 Self::set_collection_property(collection, sender, property)?;
944 sender: &T::CrossAccountId,950 sender: &T::CrossAccountId,
945 property_key: PropertyKey,951 property_key: PropertyKey,
946 ) -> DispatchResult {952 ) -> DispatchResult {
947 collection.check_is_mutable()?;
948 collection.check_is_owner_or_admin(sender)?;953 collection.check_is_owner_or_admin(sender)?;
949954
950 CollectionProperties::<T>::try_mutate(collection.id, |properties| {955 CollectionProperties::<T>::try_mutate(collection.id, |properties| {
966 sender: &T::CrossAccountId,971 sender: &T::CrossAccountId,
967 property_keys: Vec<PropertyKey>,972 property_keys: Vec<PropertyKey>,
968 ) -> DispatchResult {973 ) -> DispatchResult {
969 collection.check_is_mutable()?;
970
971 for key in property_keys {974 for key in property_keys {
972 Self::delete_collection_property(collection, sender, key)?;975 Self::delete_collection_property(collection, sender, key)?;
992 sender: &T::CrossAccountId,995 sender: &T::CrossAccountId,
993 property_permission: PropertyKeyPermission,996 property_permission: PropertyKeyPermission,
994 ) -> DispatchResult {997 ) -> DispatchResult {
995 collection.check_is_mutable()?;
996 collection.check_is_owner_or_admin(sender)?;998 collection.check_is_owner_or_admin(sender)?;
997999
998 let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);1000 let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);
1024 sender: &T::CrossAccountId,1026 sender: &T::CrossAccountId,
1025 property_permissions: Vec<PropertyKeyPermission>,1027 property_permissions: Vec<PropertyKeyPermission>,
1026 ) -> DispatchResult {1028 ) -> DispatchResult {
1027 collection.check_is_mutable()?;
1028
1029 for prop_pemission in property_permissions {1029 for prop_pemission in property_permissions {
1030 Self::set_property_permission(collection, sender, prop_pemission)?;1030 Self::set_property_permission(collection, sender, prop_pemission)?;
1113 user: &T::CrossAccountId,1113 user: &T::CrossAccountId,
1114 allowed: bool,1114 allowed: bool,
1115 ) -> DispatchResult {1115 ) -> DispatchResult {
1116 collection.check_is_mutable()?;
1117 collection.check_is_owner_or_admin(sender)?;1116 collection.check_is_owner_or_admin(sender)?;
11181117
1119 // =========1118 // =========
1133 user: &T::CrossAccountId,1132 user: &T::CrossAccountId,
1134 admin: bool,1133 admin: bool,
1135 ) -> DispatchResult {1134 ) -> DispatchResult {
1136 collection.check_is_mutable()?;
1137 collection.check_is_owner_or_admin(sender)?;1135 collection.check_is_owner_or_admin(sender)?;
11381136
1139 let was_admin = <IsAdmin<T>>::get((collection.id, user));1137 let was_admin = <IsAdmin<T>>::get((collection.id, user));
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
137 owner: T::CrossAccountId,137 owner: T::CrossAccountId,
138 data: CreateCollectionData<T::AccountId>,138 data: CreateCollectionData<T::AccountId>,
139 ) -> Result<CollectionId, DispatchError> {139 ) -> Result<CollectionId, DispatchError> {
140 <PalletCommon<T>>::init_collection(owner, data)140 <PalletCommon<T>>::init_collection(owner, data, false)
141 }141 }
142 pub fn destroy_collection(142 pub fn destroy_collection(
143 collection: FungibleHandle<T>,143 collection: FungibleHandle<T>,
168 owner: &T::CrossAccountId,168 owner: &T::CrossAccountId,
169 amount: u128,169 amount: u128,
170 ) -> DispatchResult {170 ) -> DispatchResult {
171 collection.check_is_mutable()?;
172
173 let total_supply = <TotalSupply<T>>::get(collection.id)171 let total_supply = <TotalSupply<T>>::get(collection.id)
174 .checked_sub(amount)172 .checked_sub(amount)
216 amount: u128,214 amount: u128,
217 nesting_budget: &dyn Budget,215 nesting_budget: &dyn Budget,
218 ) -> DispatchResult {216 ) -> DispatchResult {
219 collection.check_is_mutable()?;
220
221 ensure!(217 ensure!(
222 collection.limits.transfers_enabled(),218 collection.limits.transfers_enabled(),
287 data: BTreeMap<T::CrossAccountId, u128>,283 data: BTreeMap<T::CrossAccountId, u128>,
288 nesting_budget: &dyn Budget,284 nesting_budget: &dyn Budget,
289 ) -> DispatchResult {285 ) -> DispatchResult {
290 collection.check_is_mutable()?;
291
292 if !collection.is_owner_or_admin(sender) {286 if !collection.is_owner_or_admin(sender) {
293 ensure!(287 ensure!(
390 spender: &T::CrossAccountId,384 spender: &T::CrossAccountId,
391 amount: u128,385 amount: u128,
392 ) -> DispatchResult {386 ) -> DispatchResult {
393 collection.check_is_mutable()?;
394 if collection.permissions.access() == AccessMode::AllowList {387 if collection.permissions.access() == AccessMode::AllowList {
395 collection.check_allowlist(owner)?;388 collection.check_allowlist(owner)?;
396 collection.check_allowlist(spender)?;389 collection.check_allowlist(spender)?;
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
304 pub fn init_collection(304 pub fn init_collection(
305 owner: T::CrossAccountId,305 owner: T::CrossAccountId,
306 data: CreateCollectionData<T::AccountId>,306 data: CreateCollectionData<T::AccountId>,
307 is_external: bool,
307 ) -> Result<CollectionId, DispatchError> {308 ) -> Result<CollectionId, DispatchError> {
308 <PalletCommon<T>>::init_collection(owner, data)309 <PalletCommon<T>>::init_collection(owner, data, is_external)
309 }310 }
310 pub fn destroy_collection(311 pub fn destroy_collection(
311 collection: NonfungibleHandle<T>,312 collection: NonfungibleHandle<T>,
336 sender: &T::CrossAccountId,337 sender: &T::CrossAccountId,
337 token: TokenId,338 token: TokenId,
338 ) -> DispatchResult {339 ) -> DispatchResult {
339 collection.check_is_mutable()?;
340
341 let token_data =340 let token_data =
342 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;341 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
458 &property.key,457 &property.key,
459 is_token_create,458 is_token_create,
460 )?;459 )?;
461 collection.check_is_mutable()?;
462460
463 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {461 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
464 let property = property.clone();462 let property = property.clone();
496 token_id: TokenId,494 token_id: TokenId,
497 property_key: PropertyKey,495 property_key: PropertyKey,
498 ) -> DispatchResult {496 ) -> DispatchResult {
499 collection.check_is_mutable()?;
500 Self::check_token_change_permission(collection, sender, token_id, &property_key, false)?;497 Self::check_token_change_permission(collection, sender, token_id, &property_key, false)?;
501498
502 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {499 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
574 token_id: TokenId,571 token_id: TokenId,
575 property_keys: Vec<PropertyKey>,572 property_keys: Vec<PropertyKey>,
576 ) -> DispatchResult {573 ) -> DispatchResult {
577 collection.check_is_mutable()?;
578
579 for key in property_keys {574 for key in property_keys {
580 Self::delete_token_property(collection, sender, token_id, key)?;575 Self::delete_token_property(collection, sender, token_id, key)?;
622 token: TokenId,617 token: TokenId,
623 nesting_budget: &dyn Budget,618 nesting_budget: &dyn Budget,
624 ) -> DispatchResult {619 ) -> DispatchResult {
625 collection.check_is_mutable()?;
626
627 ensure!(620 ensure!(
628 collection.limits.transfers_enabled(),621 collection.limits.transfers_enabled(),
902 token: TokenId,895 token: TokenId,
903 spender: Option<&T::CrossAccountId>,896 spender: Option<&T::CrossAccountId>,
904 ) -> DispatchResult {897 ) -> DispatchResult {
905 collection.check_is_mutable()?;
906
907 if collection.permissions.access() == AccessMode::AllowList {898 if collection.permissions.access() == AccessMode::AllowList {
908 collection.check_allowlist(sender)?;899 collection.check_allowlist(sender)?;
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
235 Self::unique_collection_id(collection_id)?,235 Self::unique_collection_id(collection_id)?,
236 misc::CollectionType::Regular,236 misc::CollectionType::Regular,
237 )?;237 )?;
238 collection.check_is_external()?;
238239
239 <PalletNft<T>>::destroy_collection(collection, &cross_sender)240 <PalletNft<T>>::destroy_collection(collection, &cross_sender)
240 .map_err(Self::map_unique_err_to_proxy)?;241 .map_err(Self::map_unique_err_to_proxy)?;
256 ) -> DispatchResult {257 ) -> DispatchResult {
257 let sender = ensure_signed(origin)?;258 let sender = ensure_signed(origin)?;
258259
260 let collection = Self::get_nft_collection(Self::unique_collection_id(collection_id)?)?;
261 collection.check_is_external()?;
262
259 let new_issuer = T::Lookup::lookup(new_issuer)?;263 let new_issuer = T::Lookup::lookup(new_issuer)?;
260264
261 Self::change_collection_owner(265 Self::change_collection_owner(
287 Self::unique_collection_id(collection_id)?,291 Self::unique_collection_id(collection_id)?,
288 misc::CollectionType::Regular,292 misc::CollectionType::Regular,
289 )?;293 )?;
294 collection.check_is_external()?;
290295
291 Self::check_collection_owner(&collection, &cross_sender)?;296 Self::check_collection_owner(&collection, &cross_sender)?;
292297
319 let sender = T::CrossAccountId::from_sub(sender);324 let sender = T::CrossAccountId::from_sub(sender);
320 let cross_owner = T::CrossAccountId::from_sub(owner.clone());325 let cross_owner = T::CrossAccountId::from_sub(owner.clone());
321326
327 let collection = Self::get_typed_nft_collection(
328 Self::unique_collection_id(collection_id)?,
329 misc::CollectionType::Regular,
330 )?;
331 collection.check_is_external()?;
332
322 let royalty_info = royalty_amount.map(|amount| rmrk_traits::RoyaltyInfo {333 let royalty_info = royalty_amount.map(|amount| rmrk_traits::RoyaltyInfo {
323 recipient: recipient.unwrap_or_else(|| owner.clone()),334 recipient: recipient.unwrap_or_else(|| owner.clone()),
324 amount,335 amount,
325 });336 });
326337
327 let collection = Self::get_typed_nft_collection(
328 Self::unique_collection_id(collection_id)?,
329 misc::CollectionType::Regular,
330 )?;
331
332 let nft_id = Self::create_nft(338 let nft_id = Self::create_nft(
333 &sender,339 &sender,
334 &cross_owner,340 &cross_owner,
382 let sender = ensure_signed(origin)?;388 let sender = ensure_signed(origin)?;
383 let cross_sender = T::CrossAccountId::from_sub(sender.clone());389 let cross_sender = T::CrossAccountId::from_sub(sender.clone());
384390
391 let collection = Self::get_typed_nft_collection(
392 Self::unique_collection_id(collection_id)?,
393 misc::CollectionType::Regular,
394 )?;
395 collection.check_is_external()?;
396
385 Self::destroy_nft(397 Self::destroy_nft(
386 cross_sender,398 cross_sender,
387 Self::unique_collection_id(collection_id)?,399 Self::unique_collection_id(collection_id)?,
411 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;423 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
412 let nft_id = rmrk_nft_id.into();424 let nft_id = rmrk_nft_id.into();
413425
426 let collection =
427 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
428 collection.check_is_external()?;
429
414 let token_data =430 let token_data =
415 <TokenData<T>>::get((collection_id, nft_id)).ok_or(<Error<T>>::NoAvailableNftId)?;431 <TokenData<T>>::get((collection_id, nft_id)).ok_or(<Error<T>>::NoAvailableNftId)?;
416432
417 let from = token_data.owner;433 let from = token_data.owner;
418434
419 let collection =
420 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
421
422 ensure!(435 ensure!(
423 Self::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Transferable)?,436 Self::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Transferable)?,
424 <Error<T>>::NonTransferable437 <Error<T>>::NonTransferable
516529
517 let collection =530 let collection =
518 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;531 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
532 collection.check_is_external()?;
519533
520 let new_cross_owner = match new_owner {534 let new_cross_owner = match new_owner {
521 RmrkAccountIdOrCollectionNftTuple::AccountId(ref account_id) => {535 RmrkAccountIdOrCollectionNftTuple::AccountId(ref account_id) => {
581 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;595 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
582 let nft_id = rmrk_nft_id.into();596 let nft_id = rmrk_nft_id.into();
583597
598 let collection =
599 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
600 collection.check_is_external()?;
601
584 Self::destroy_nft(cross_sender, collection_id, nft_id).map_err(|err| {602 Self::destroy_nft(cross_sender, collection_id, nft_id).map_err(|err| {
585 if err == <CommonError<T>>::NoPermission.into()603 if err == <CommonError<T>>::NoPermission.into()
586 || err == <CommonError<T>>::ApprovedValueTooLow.into()604 || err == <CommonError<T>>::ApprovedValueTooLow.into()
613631
614 let collection_id = Self::unique_collection_id(rmrk_collection_id)632 let collection_id = Self::unique_collection_id(rmrk_collection_id)
615 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;633 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;
634 let collection =
635 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
636 collection.check_is_external()?;
616637
617 let nft_id = rmrk_nft_id.into();638 let nft_id = rmrk_nft_id.into();
618 let resource_id = rmrk_resource_id.into();639 let resource_id = rmrk_resource_id.into();
666687
667 let collection_id = Self::unique_collection_id(rmrk_collection_id)688 let collection_id = Self::unique_collection_id(rmrk_collection_id)
668 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;689 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;
690 let collection =
691 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
692 collection.check_is_external()?;
669693
670 let nft_id = rmrk_nft_id.into();694 let nft_id = rmrk_nft_id.into();
671 let resource_id = rmrk_resource_id.into();695 let resource_id = rmrk_resource_id.into();
720 let sender = T::CrossAccountId::from_sub(sender);744 let sender = T::CrossAccountId::from_sub(sender);
721745
722 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;746 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
747 let collection =
748 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
749 collection.check_is_external()?;
750
723 let budget = budget::Value::new(NESTING_BUDGET);751 let budget = budget::Value::new(NESTING_BUDGET);
724752
725 match maybe_nft_id {753 match maybe_nft_id {
775803
776 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;804 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
777 let nft_id = rmrk_nft_id.into();805 let nft_id = rmrk_nft_id.into();
806
807 let collection =
808 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
809 collection.check_is_external()?;
810
778 let budget = budget::Value::new(NESTING_BUDGET);811 let budget = budget::Value::new(NESTING_BUDGET);
779812
780 Self::ensure_nft_type(collection_id, nft_id, NftType::Regular)?;813 Self::ensure_nft_type(collection_id, nft_id, NftType::Regular)?;
799 #[transactional]832 #[transactional]
800 pub fn add_basic_resource(833 pub fn add_basic_resource(
801 origin: OriginFor<T>,834 origin: OriginFor<T>,
802 collection_id: RmrkCollectionId,835 rmrk_collection_id: RmrkCollectionId,
803 nft_id: RmrkNftId,836 nft_id: RmrkNftId,
804 resource: RmrkBasicResource,837 resource: RmrkBasicResource,
805 ) -> DispatchResult {838 ) -> DispatchResult {
806 let sender = ensure_signed(origin.clone())?;839 let sender = ensure_signed(origin.clone())?;
807840
841 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
842 let collection =
843 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
844 collection.check_is_external()?;
845
808 let resource_id = Self::resource_add(846 let resource_id = Self::resource_add(
809 sender,847 sender,
810 Self::unique_collection_id(collection_id)?,848 collection_id,
811 nft_id.into(),849 nft_id.into(),
812 [850 [
813 Self::rmrk_property(TokenType, &NftType::Resource)?,851 Self::rmrk_property(TokenType, &NftType::Resource)?,
831 #[transactional]869 #[transactional]
832 pub fn add_composable_resource(870 pub fn add_composable_resource(
833 origin: OriginFor<T>,871 origin: OriginFor<T>,
834 collection_id: RmrkCollectionId,872 rmrk_collection_id: RmrkCollectionId,
835 nft_id: RmrkNftId,873 nft_id: RmrkNftId,
836 _resource_id: RmrkBoundedResource,874 _resource_id: RmrkBoundedResource,
837 resource: RmrkComposableResource,875 resource: RmrkComposableResource,
838 ) -> DispatchResult {876 ) -> DispatchResult {
839 let sender = ensure_signed(origin.clone())?;877 let sender = ensure_signed(origin.clone())?;
840878
879 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
880 let collection =
881 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
882 collection.check_is_external()?;
883
841 let resource_id = Self::resource_add(884 let resource_id = Self::resource_add(
842 sender,885 sender,
843 Self::unique_collection_id(collection_id)?,886 collection_id,
844 nft_id.into(),887 nft_id.into(),
845 [888 [
846 Self::rmrk_property(TokenType, &NftType::Resource)?,889 Self::rmrk_property(TokenType, &NftType::Resource)?,
866 #[transactional]909 #[transactional]
867 pub fn add_slot_resource(910 pub fn add_slot_resource(
868 origin: OriginFor<T>,911 origin: OriginFor<T>,
869 collection_id: RmrkCollectionId,912 rmrk_collection_id: RmrkCollectionId,
870 nft_id: RmrkNftId,913 nft_id: RmrkNftId,
871 resource: RmrkSlotResource,914 resource: RmrkSlotResource,
872 ) -> DispatchResult {915 ) -> DispatchResult {
873 let sender = ensure_signed(origin.clone())?;916 let sender = ensure_signed(origin.clone())?;
874917
918 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
919 let collection =
920 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
921 collection.check_is_external()?;
922
875 let resource_id = Self::resource_add(923 let resource_id = Self::resource_add(
876 sender,924 sender,
877 Self::unique_collection_id(collection_id)?,925 collection_id,
878 nft_id.into(),926 nft_id.into(),
879 [927 [
880 Self::rmrk_property(TokenType, &NftType::Resource)?,928 Self::rmrk_property(TokenType, &NftType::Resource)?,
900 #[transactional]948 #[transactional]
901 pub fn remove_resource(949 pub fn remove_resource(
902 origin: OriginFor<T>,950 origin: OriginFor<T>,
903 collection_id: RmrkCollectionId,951 rmrk_collection_id: RmrkCollectionId,
904 nft_id: RmrkNftId,952 nft_id: RmrkNftId,
905 resource_id: RmrkResourceId,953 resource_id: RmrkResourceId,
906 ) -> DispatchResult {954 ) -> DispatchResult {
907 let sender = ensure_signed(origin.clone())?;955 let sender = ensure_signed(origin.clone())?;
908956
909 Self::resource_remove(957 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
910 sender,958 let collection =
911 Self::unique_collection_id(collection_id)?,959 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
912 nft_id.into(),960 collection.check_is_external()?;
961
913 resource_id.into(),962 Self::resource_remove(sender, collection_id, nft_id.into(), resource_id.into())?;
914 )?;
915963
916 Self::deposit_event(Event::ResourceRemoval {964 Self::deposit_event(Event::ResourceRemoval {
917 nft_id,965 nft_id,
968 data: CreateCollectionData<T::AccountId>,1016 data: CreateCollectionData<T::AccountId>,
969 properties: impl Iterator<Item = Property>,1017 properties: impl Iterator<Item = Property>,
970 ) -> Result<CollectionId, DispatchError> {1018 ) -> Result<CollectionId, DispatchError> {
971 let collection_id = <PalletNft<T>>::init_collection(sender, data);1019 let collection_id = <PalletNft<T>>::init_collection(sender, data, true);
9721020
973 if let Err(DispatchError::Arithmetic(_)) = &collection_id {1021 if let Err(DispatchError::Arithmetic(_)) = &collection_id {
974 return Err(<Error<T>>::NoAvailableCollectionId.into());1022 return Err(<Error<T>>::NoAvailableCollectionId.into());
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
95 };95 };
9696
97 let collection_id_res = <PalletNft<T>>::init_collection(cross_sender.clone(), data);97 let collection_id_res =
98 <PalletNft<T>>::init_collection(cross_sender.clone(), data, true);
9899
99 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {100 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
100 return Err(<Error<T>>::NoAvailableBaseId.into());101 return Err(<Error<T>>::NoAvailableBaseId.into());
155 misc::CollectionType::Base,156 misc::CollectionType::Base,
156 )157 )
157 .map_err(|_| <Error<T>>::BaseDoesntExist)?;158 .map_err(|_| <Error<T>>::BaseDoesntExist)?;
159 collection.check_is_external()?;
158160
159 if theme.name.as_slice() == b"default" {161 if theme.name.as_slice() == b"default" {
160 <BaseHasDefaultTheme<T>>::insert(collection_id, true);162 <BaseHasDefaultTheme<T>>::insert(collection_id, true);
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
200 owner: T::CrossAccountId,200 owner: T::CrossAccountId,
201 data: CreateCollectionData<T::AccountId>,201 data: CreateCollectionData<T::AccountId>,
202 ) -> Result<CollectionId, DispatchError> {202 ) -> Result<CollectionId, DispatchError> {
203 <PalletCommon<T>>::init_collection(owner, data)203 <PalletCommon<T>>::init_collection(owner, data, false)
204 }204 }
205 pub fn destroy_collection(205 pub fn destroy_collection(
206 collection: RefungibleHandle<T>,206 collection: RefungibleHandle<T>,
234 }234 }
235235
236 pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {236 pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {
237 collection.check_is_mutable()?;
238 let burnt = <TokensBurnt<T>>::get(collection.id)237 let burnt = <TokensBurnt<T>>::get(collection.id)
239 .checked_add(1)238 .checked_add(1)
240 .ok_or(ArithmeticError::Overflow)?;239 .ok_or(ArithmeticError::Overflow)?;
254 token: TokenId,253 token: TokenId,
255 amount: u128,254 amount: u128,
256 ) -> DispatchResult {255 ) -> DispatchResult {
257 collection.check_is_mutable()?;
258 let total_supply = <TotalSupply<T>>::get((collection.id, token))256 let total_supply = <TotalSupply<T>>::get((collection.id, token))
259 .checked_sub(amount)257 .checked_sub(amount)
260 .ok_or(<CommonError<T>>::TokenValueTooLow)?;258 .ok_or(<CommonError<T>>::TokenValueTooLow)?;
327 amount: u128,325 amount: u128,
328 nesting_budget: &dyn Budget,326 nesting_budget: &dyn Budget,
329 ) -> DispatchResult {327 ) -> DispatchResult {
330 collection.check_is_mutable()?;
331 ensure!(328 ensure!(
332 collection.limits.transfers_enabled(),329 collection.limits.transfers_enabled(),
333 <CommonError<T>>::TransferNotAllowed330 <CommonError<T>>::TransferNotAllowed
576 token: TokenId,573 token: TokenId,
577 amount: u128,574 amount: u128,
578 ) -> DispatchResult {575 ) -> DispatchResult {
579 collection.check_is_mutable()?;
580 if collection.permissions.access() == AccessMode::AllowList {576 if collection.permissions.access() == AccessMode::AllowList {
581 collection.check_allowlist(sender)?;577 collection.check_allowlist(sender)?;
582 collection.check_allowlist(spender)?;578 collection.check_allowlist(spender)?;
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
93 };93 };
9494
95 let collection_id = <pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data)95 let collection_id =
96 <pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, false)
96 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;97 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
9798
98 let address = pallet_common::eth::collection_id_to_address(collection_id);99 let address = pallet_common::eth::collection_id_to_address(collection_id);
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
304 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {304 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {
305 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);305 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
306 let collection = <CollectionHandle<T>>::try_get(collection_id)?;306 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
307 collection.check_is_mutable()?;307 collection.check_is_internal()?;
308308
309 // =========309 // =========
310310
339339
340 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);340 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
341 let collection = <CollectionHandle<T>>::try_get(collection_id)?;341 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
342 collection.check_is_internal()?;
342343
343 <PalletCommon<T>>::toggle_allowlist(344 <PalletCommon<T>>::toggle_allowlist(
344 &collection,345 &collection,
373374
374 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);375 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
375 let collection = <CollectionHandle<T>>::try_get(collection_id)?;376 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
377 collection.check_is_internal()?;
376378
377 <PalletCommon<T>>::toggle_allowlist(379 <PalletCommon<T>>::toggle_allowlist(
378 &collection,380 &collection,
407 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);409 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
408410
409 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;411 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
410 target_collection.check_is_mutable()?;412 target_collection.check_is_internal()?;
411 target_collection.check_is_owner(&sender)?;413 target_collection.check_is_owner(&sender)?;
412414
413 target_collection.owner = new_owner.clone();415 target_collection.owner = new_owner.clone();
437 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {439 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {
438 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);440 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
439 let collection = <CollectionHandle<T>>::try_get(collection_id)?;441 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
442 collection.check_is_internal()?;
440443
441 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(444 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(
442 collection_id,445 collection_id,
463 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {466 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {
464 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);467 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
465 let collection = <CollectionHandle<T>>::try_get(collection_id)?;468 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
469 collection.check_is_internal()?;
466470
467 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(471 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(
468 collection_id,472 collection_id,
488492
489 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;493 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
490 target_collection.check_is_owner(&sender)?;494 target_collection.check_is_owner(&sender)?;
495 target_collection.check_is_internal()?;
491496
492 target_collection.set_sponsor(new_sponsor.clone())?;497 target_collection.set_sponsor(new_sponsor.clone())?;
493498
512 let sender = ensure_signed(origin)?;517 let sender = ensure_signed(origin)?;
513518
514 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;519 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
520 target_collection.check_is_internal()?;
515 ensure!(521 ensure!(
516 target_collection.confirm_sponsorship(&sender)?,522 target_collection.confirm_sponsorship(&sender)?,
517 Error::<T>::ConfirmUnsetSponsorFail523 Error::<T>::ConfirmUnsetSponsorFail
540 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);546 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
541547
542 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;548 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
549 target_collection.check_is_internal()?;
543 target_collection.check_is_owner(&sender)?;550 target_collection.check_is_owner(&sender)?;
544551
545 target_collection.sponsorship = SponsorshipState::Disabled;552 target_collection.sponsorship = SponsorshipState::Disabled;
704 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {711 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {
705 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);712 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
706 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;713 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
714 target_collection.check_is_internal()?;
707 target_collection.check_is_owner(&sender)?;715 target_collection.check_is_owner(&sender)?;
708716
709 // =========717 // =========
858 ) -> DispatchResult {866 ) -> DispatchResult {
859 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);867 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
860 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;868 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
869 target_collection.check_is_internal()?;
861 target_collection.check_is_owner(&sender)?;870 target_collection.check_is_owner(&sender)?;
862 let old_limit = &target_collection.limits;871 let old_limit = &target_collection.limits;
863872
879 ) -> DispatchResult {888 ) -> DispatchResult {
880 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);889 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
881 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;890 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
891 target_collection.check_is_internal()?;
882 target_collection.check_is_owner(&sender)?;892 target_collection.check_is_owner(&sender)?;
883 let old_limit = &target_collection.permissions;893 let old_limit = &target_collection.permissions;
884894
modifiedruntime/common/src/dispatch.rsdiffbeforeafterboth
35 data: CreateCollectionData<T::AccountId>,35 data: CreateCollectionData<T::AccountId>,
36 ) -> DispatchResult {36 ) -> DispatchResult {
37 let _id = match data.mode {37 let _id = match data.mode {
38 CollectionMode::NFT => <PalletNonfungible<T>>::init_collection(sender, data)?,38 CollectionMode::NFT => <PalletNonfungible<T>>::init_collection(sender, data, false)?,
39 CollectionMode::Fungible(decimal_points) => {39 CollectionMode::Fungible(decimal_points) => {
40 // check params40 // check params
41 ensure!(41 ensure!(