git.delta.rocks / unique-network / refs/commits / e1f471473559

difftreelog

doc: unique pallet complete

Farhad Hakimov2022-07-16parent: #611e753.patch.diff
in: master

2 files changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -14,6 +14,8 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
+//! Implementation of CollectionHelpers contract.
+
 use core::marker::PhantomData;
 use evm_coder::{execution::*, generate_stubgen, solidity_interface, weight, types::*};
 use ethereum as _;
@@ -33,7 +35,8 @@
 use sp_std::vec::Vec;
 use alloc::format;
 
-struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);
+/// See [`CollectionHelpersCall`]
+pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);
 impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {
 	fn recorder(&self) -> &SubstrateRecorder<T> {
 		&self.0
@@ -44,8 +47,14 @@
 	}
 }
 
+/// @title Contract, which allows users to operate with collections
 #[solidity_interface(name = "CollectionHelpers", events(CollectionHelpersEvents))]
 impl<T: Config + pallet_nonfungible::Config> EvmCollectionHelpers<T> {
+	/// Create an NFT collection
+	/// @param name Name of the collection
+	/// @param description Informative description of the collection
+	/// @param token_prefix Token prefix to represent the collection tokens in UI and user applications
+	/// @return address Address of the newly created collection
 	#[weight(<SelfWeightOf<T>>::create_collection())]
 	fn create_nonfungible_collection(
 		&mut self,
@@ -100,6 +109,9 @@
 		Ok(address)
 	}
 
+	/// Check if a collection exists
+	/// @param collection_address Address of the collection in question
+	/// @return bool Does the collection exist?
 	fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {
 		if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {
 			let collection_id = id;
@@ -110,6 +122,7 @@
 	}
 }
 
+/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]
 pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);
 impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelpersOnMethodCall<T> {
 	fn is_reserved(contract: &sp_core::H160) -> bool {
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
16
17//! # Unique Pallet
18//!
19//! A pallet governing Unique transactions.
20//!
21//! - [`Config`]
22//! - [`Call`]
23//! - [`Pallet`]
24//!
25//! ## Overview
26//!
27//! The Unique pallet's purpose is to be the primary interface between
28//! external users and the inner structure of the Unique chains.
29//!
30//! It also contains an implementation of [`CollectionHelpers`](eth),
31//! an Ethereum contract dealing with collection operations.
32//!
33//! ## Interface
34//!
35//! ### Dispatchables
36//!
37//! - `create_collection` - Create a collection of tokens. **Deprecated**, use `create_collection_ex`.
38//! - `create_collection_ex` - Create a collection of tokens with explicit parameters.
39//! - `destroy_collection` - Destroy a collection if no tokens exist within.
40//! - `add_to_allow_list` - Add an address to allow list.
41//! - `remove_from_allow_list` - Remove an address from allow list.
42//! - `change_collection_owner` - Change the owner of the collection.
43//! - `add_collection_admin` - Add an admin to a collection.
44//! - `remove_collection_admin` - Remove admin of a collection.
45//! - `set_collection_sponsor` - Invite a new collection sponsor.
46//! - `confirm_sponsorship` - Confirm own sponsorship of a collection, becoming the sponsor.
47//! - `remove_collection_sponsor` - Remove a sponsor from a collection.
48//! - `create_item` - Create an item within a collection.
49//! - `create_multiple_items` - Create multiple items within a collection.
50//! - `set_collection_properties` - Add or change collection properties.
51//! - `delete_collection_properties` - Delete specified collection properties.
52//! - `set_token_properties` - Add or change token properties.
53//! - `delete_token_properties` - Delete token properties.
54//! - `set_token_property_permissions` - Add or change token property permissions of a collection.
55//! - `create_multiple_items_ex` - Create multiple items within a collection with explicitly specified initial parameters.
56//! - `set_transfers_enabled_flag` - Completely allow or disallow transfers for a particular collection.
57//! - `burn_item` - Destroy an item.
58//! - `burn_from` - Destroy an item on behalf of the owner as a non-owner account.
59//! - `transfer` - Change ownership of the token.
60//! - `transfer_from` - Change ownership of the token on behalf of the owner as a non-owner account.
61//! - `approve` - Allow a non-permissioned address to transfer or burn an item.
62//! - `set_collection_limits` - Set specific limits of a collection.
63//! - `set_collection_permissions` - Set specific permissions of a collection.
64//! - `repartition` - Re-partition a refungible token, while owning all of its parts.
1665
17#![recursion_limit = "1024"]66#![recursion_limit = "1024"]
18#![cfg_attr(not(feature = "std"), no_std)]67#![cfg_attr(not(feature = "std"), no_std)]
54pub mod weights;103pub mod weights;
55use weights::WeightInfo;104use weights::WeightInfo;
56105
106/// Maximum number of levels of depth in the token nesting tree.
57const NESTING_BUDGET: u32 = 5;107pub const NESTING_BUDGET: u32 = 5;
58108
59decl_error! {109decl_error! {
60 /// Error for non-fungible-token module.110 /// Errors for the common Unique transactions.
61 pub enum Error for Module<T: Config> {111 pub enum Error for Module<T: Config> {
62 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.112 /// Decimal_points parameter must be lower than [`up_data_structs::MAX_DECIMAL_POINTS`].
63 CollectionDecimalPointLimitExceeded,113 CollectionDecimalPointLimitExceeded,
64 /// This address is not set as sponsor, use setCollectionSponsor first.114 /// This address is not set as sponsor, use setCollectionSponsor first.
65 ConfirmUnsetSponsorFail,115 ConfirmUnsetSponsorFail,
66 /// Length of items properties must be greater than 0.116 /// Length of items properties must be greater than 0.
67 EmptyArgument,117 EmptyArgument,
68 /// Repertition is only supported by refungible collection118 /// Repertition is only supported by refungible collection.
69 RepartitionCalledOnNonRefungibleCollection,119 RepartitionCalledOnNonRefungibleCollection,
70 }120 }
71}121}
72122
123/// Configuration trait of this pallet.
73pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {124pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {
125 /// Overarching event type.
74 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;126 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
75127
76 /// Weight information for extrinsics in this pallet.128 /// Weight information for extrinsics in this pallet.
77 type WeightInfo: WeightInfo;129 type WeightInfo: WeightInfo;
130
131 /// Weight information for common pallet operations.
78 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;132 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;
133
134 /// Weight info information for extra refungible pallet operations.
79 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;135 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;
80}136}
81137
88 /// Collection sponsor was removed144 /// Collection sponsor was removed
89 ///145 ///
90 /// # Arguments146 /// # Arguments
91 ///
92 /// * collection_id: Globally unique collection identifier.147 /// * collection_id: ID of the affected collection.
93 CollectionSponsorRemoved(CollectionId),148 CollectionSponsorRemoved(CollectionId),
94149
95 /// Collection admin was added150 /// Collection admin was added
96 ///151 ///
97 /// # Arguments152 /// # Arguments
98 ///
99 /// * collection_id: Globally unique collection identifier.153 /// * collection_id: ID of the affected collection.
100 ///
101 /// * admin: Admin address.154 /// * admin: Admin address.
102 CollectionAdminAdded(CollectionId, CrossAccountId),155 CollectionAdminAdded(CollectionId, CrossAccountId),
103156
104 /// Collection owned was changed157 /// Collection owned was changed
105 ///158 ///
106 /// # Arguments159 /// # Arguments
107 ///
108 /// * collection_id: Globally unique collection identifier.160 /// * collection_id: ID of the affected collection.
109 ///
110 /// * owner: New owner address.161 /// * owner: New owner address.
111 CollectionOwnedChanged(CollectionId, AccountId),162 CollectionOwnedChanged(CollectionId, AccountId),
112163
113 /// Collection sponsor was set164 /// Collection sponsor was set
114 ///165 ///
115 /// # Arguments166 /// # Arguments
116 ///
117 /// * collection_id: Globally unique collection identifier.167 /// * collection_id: ID of the affected collection.
118 ///
119 /// * owner: New sponsor address.168 /// * owner: New sponsor address.
120 CollectionSponsorSet(CollectionId, AccountId),169 CollectionSponsorSet(CollectionId, AccountId),
121170
122 /// New sponsor was confirm171 /// New sponsor was confirm
123 ///172 ///
124 /// # Arguments173 /// # Arguments
125 ///
126 /// * collection_id: Globally unique collection identifier.174 /// * collection_id: ID of the affected collection.
127 ///
128 /// * sponsor: New sponsor address.175 /// * sponsor: New sponsor address.
129 SponsorshipConfirmed(CollectionId, AccountId),176 SponsorshipConfirmed(CollectionId, AccountId),
130177
131 /// Collection admin was removed178 /// Collection admin was removed
132 ///179 ///
133 /// # Arguments180 /// # Arguments
134 ///
135 /// * collection_id: Globally unique collection identifier.181 /// * collection_id: ID of the affected collection.
136 ///
137 /// * admin: Admin address.182 /// * admin: Removed admin address.
138 CollectionAdminRemoved(CollectionId, CrossAccountId),183 CollectionAdminRemoved(CollectionId, CrossAccountId),
139184
140 /// Address was removed from the allow list185 /// Address was removed from the allow list
141 ///186 ///
142 /// # Arguments187 /// # Arguments
143 ///
144 /// * collection_id: Globally unique collection identifier.188 /// * collection_id: ID of the affected collection.
145 ///
146 /// * user: Address.189 /// * user: Address of the removed account.
147 AllowListAddressRemoved(CollectionId, CrossAccountId),190 AllowListAddressRemoved(CollectionId, CrossAccountId),
148191
149 /// Address was added to the allow list192 /// Address was added to the allow list
150 ///193 ///
151 /// # Arguments194 /// # Arguments
152 ///
153 /// * collection_id: Globally unique collection identifier.195 /// * collection_id: ID of the affected collection.
154 ///
155 /// * user: Address.196 /// * user: Address of the added account.
156 AllowListAddressAdded(CollectionId, CrossAccountId),197 AllowListAddressAdded(CollectionId, CrossAccountId),
157198
158 /// Collection limits were set199 /// Collection limits were set
159 ///200 ///
160 /// # Arguments201 /// # Arguments
161 ///
162 /// * collection_id: Globally unique collection identifier.202 /// * collection_id: ID of the affected collection.
163 CollectionLimitSet(CollectionId),203 CollectionLimitSet(CollectionId),
164204
165 /// Collection permissions were set205 /// Collection permissions were set
166 ///206 ///
167 /// # Arguments207 /// # Arguments
168 ///
169 /// * collection_id: Globally unique collection identifier.208 /// * collection_id: ID of the affected collection.
170 CollectionPermissionSet(CollectionId),209 CollectionPermissionSet(CollectionId),
171 }210 }
172}211}
232}271}
233272
234decl_module! {273decl_module! {
274 /// Type alias to Pallet, to be used by construct_runtime.
235 pub struct Module<T: Config> for enum Call275 pub struct Module<T: Config> for enum Call
236 where276 where
237 origin: T::Origin277 origin: T::Origin
252 0292 0
253 }293 }
254294
255 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner of the collection is set to the address that signed the transaction and can be changed later.295 /// DEPRECATED - use create_collection_ex. Create a Collection of tokens.
296 ///
297 /// Each Token may have multiple properties encoded as an array of bytes
298 /// of certain length. The initial owner of the collection is set
299 /// to the address that signed the transaction and can be changed later.
300 ///
301 /// Prefer [`create_collection_ex`](Call::create_collection_ex) instead.
256 ///302 ///
257 /// # Permissions303 /// # Permissions
258 ///304 ///
259 /// * Anyone.305 /// * Anyone - becomes the owner of the new collection.
260 ///306 ///
261 /// # Arguments307 /// # Arguments
262 ///308 ///
263 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.309 /// * `collection_name`: UTF-16 string with collection name (limit 64 characters),
310 /// will be stored as zero-terminated.
264 /// * collection_description - UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.311 /// * `collection_description`: UTF-16 string with collection description (limit 256 characters),
312 /// will be stored as zero-terminated.
265 /// * token_prefix - UTF-8 string with token prefix.313 /// * `token_prefix`: UTF-8 string with token prefix.
266 /// * mode - [CollectionMode] collection type and type dependent data.314 /// * `mode`: [`CollectionMode`] and type dependent data.
267 // returns collection ID315 // returns collection ID
268 #[weight = <SelfWeightOf<T>>::create_collection()]316 #[weight = <SelfWeightOf<T>>::create_collection()]
269 #[transactional]317 #[transactional]
284 }334 }
285335
286 /// Create a collection with explicit parameters.336 /// Create a collection with explicit parameters.
287 /// Prefer it to the deprecated [`created_collection`] method.337 /// Prefer it to the deprecated [`create_collection`](Call::create_collection) method.
288 ///338 ///
289 /// # Permissions339 /// # Permissions
290 ///340 ///
291 /// * Anyone.341 /// * Anyone - becomes the owner of the new collection.
292 ///342 ///
293 /// # Arguments343 /// # Arguments
294 ///344 ///
295 /// * data: explicit create-collection data.345 /// * `data`: Explicit data of a collection used for its creation.
296 #[weight = <SelfWeightOf<T>>::create_collection()]346 #[weight = <SelfWeightOf<T>>::create_collection()]
297 #[transactional]347 #[transactional]
298 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {348 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {
305 Ok(())355 Ok(())
306 }356 }
307357
308 /// Destroy the collection if no tokens exist within.358 /// Destroy a collection if no tokens exist within.
309 ///359 ///
310 /// # Permissions360 /// # Permissions
311 ///361 ///
312 /// * Collection Owner362 /// * Collection owner
313 ///363 ///
314 /// # Arguments364 /// # Arguments
315 ///365 ///
316 /// * collection_id - collection to destroy.366 /// * `collection_id`: Collection to destroy.
317 #[weight = <SelfWeightOf<T>>::destroy_collection()]367 #[weight = <SelfWeightOf<T>>::destroy_collection()]
318 #[transactional]368 #[transactional]
319 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {369 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {
340 ///390 ///
341 /// # Permissions391 /// # Permissions
342 ///392 ///
343 /// * Collection Owner393 /// * Collection owner
344 /// * Collection Admin394 /// * Collection admin
345 ///395 ///
346 /// # Arguments396 /// # Arguments
347 ///397 ///
348 /// * collection_id.398 /// * `collection_id`: ID of the modified collection.
349 /// * address.399 /// * `address`: ID of the address to be added to the allowlist.
350 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]400 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]
351 #[transactional]401 #[transactional]
352 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{402 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{
374 ///424 ///
375 /// # Permissions425 /// # Permissions
376 ///426 ///
377 /// * Collection Owner427 /// * Collection owner
378 /// * Collection Admin428 /// * Collection admin
379 ///429 ///
380 /// # Arguments430 /// # Arguments
381 ///431 ///
382 /// * collection_id.432 /// * `collection_id`: ID of the modified collection.
383 /// * address.433 /// * `address`: ID of the address to be removed from the allowlist.
384 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]434 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]
385 #[transactional]435 #[transactional]
386 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{436 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{
408 ///458 ///
409 /// # Permissions459 /// # Permissions
410 ///460 ///
411 /// * Collection Owner461 /// * Collection owner
412 ///462 ///
413 /// # Arguments463 /// # Arguments
414 ///464 ///
415 /// * collection_id.465 /// * `collection_id`: ID of the modified collection.
416 /// * new_owner.466 /// * `new_owner`: ID of the account that will become the owner.
417 #[weight = <SelfWeightOf<T>>::change_collection_owner()]467 #[weight = <SelfWeightOf<T>>::change_collection_owner()]
418 #[transactional]468 #[transactional]
419 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {469 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {
433 target_collection.save()483 target_collection.save()
434 }484 }
435485
436 /// Adds an admin of the collection.486 /// Add an admin to a collection.
437 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.487 ///
488 /// NFT Collection can be controlled by multiple admin addresses
489 /// (some which can also be servers, for example). Admins can issue
490 /// and burn NFTs, as well as add and remove other admins,
491 /// but cannot change NFT or Collection ownership.
438 ///492 ///
439 /// # Permissions493 /// # Permissions
440 ///494 ///
441 /// * Collection Owner495 /// * Collection owner
442 /// * Collection Admin496 /// * Collection admin
443 ///497 ///
444 /// # Arguments498 /// # Arguments
445 ///499 ///
446 /// * collection_id - ID of the Collection to add admin for.500 /// * `collection_id`: ID of the Collection to add an admin for.
447 /// * new_admin - Address of new admin to add.501 /// * `new_admin`: Address of new admin to add.
448 #[weight = <SelfWeightOf<T>>::add_collection_admin()]502 #[weight = <SelfWeightOf<T>>::add_collection_admin()]
449 #[transactional]503 #[transactional]
450 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin: T::CrossAccountId) -> DispatchResult {504 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin: T::CrossAccountId) -> DispatchResult {
460 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin, true)514 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin, true)
461 }515 }
462516
463 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.517 /// Remove admin of a collection.
518 ///
519 /// An admin address can remove itself. List of admins may become empty,
520 /// in which case only Collection Owner will be able to add an Admin.
464 ///521 ///
465 /// # Permissions522 /// # Permissions
466 ///523 ///
467 /// * Collection Owner524 /// * Collection owner
468 /// * Collection Admin525 /// * Collection admin
469 ///526 ///
470 /// # Arguments527 /// # Arguments
471 ///528 ///
472 /// * collection_id - ID of the Collection to remove admin for.529 /// * `collection_id`: ID of the collection to remove the admin for.
473 /// * account_id - Address of admin to remove.530 /// * `account_id`: Address of the admin to remove.
474 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]531 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]
475 #[transactional]532 #[transactional]
476 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {533 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {
486 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)543 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)
487 }544 }
488545
546 /// Set (invite) a new collection sponsor.
489 /// Set (invite) a new collection sponsor. If successful, confirmation from the sponsor-to-be will be pending.547 /// If successful, confirmation from the sponsor-to-be will be pending.
490 ///548 ///
491 /// # Permissions549 /// # Permissions
492 ///550 ///
493 /// * Collection Owner551 /// * Collection owner
494 /// * Collection Admin552 /// * Collection admin
495 ///553 ///
496 /// # Arguments554 /// # Arguments
497 ///555 ///
498 /// * collection_id.556 /// * `collection_id`: ID of the modified collection.
499 /// * new_sponsor.557 /// * `new_sponsor`: ID of the account of the sponsor-to-be.
500 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]558 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]
501 #[transactional]559 #[transactional]
502 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {560 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {
516 target_collection.save()574 target_collection.save()
517 }575 }
518576
519 /// Confirm own sponsorship of a collection.577 /// Confirm own sponsorship of a collection, becoming the sponsor.
578 /// An invitation must be pending, see [`set_collection_sponsor`](Call::set_collection_sponsor).
579 ///
580 /// Sponsor can pay the fees of a transaction instead of the sender,
581 /// but only within specified limits.
520 ///582 ///
521 /// # Permissions583 /// # Permissions
522 ///584 ///
523 /// * Sponsor-to-be585 /// * Sponsor-to-be
524 ///586 ///
525 /// # Arguments587 /// # Arguments
526 ///588 ///
527 /// * collection_id.589 /// * `collection_id`: ID of the collection with the pending sponsor.
528 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]590 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]
529 #[transactional]591 #[transactional]
530 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {592 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {
545 target_collection.save()607 target_collection.save()
546 }608 }
547609
548 /// Switch back to pay-per-own-transaction model.610 /// Remove a sponsor from a collection, making everyone pay for their own transactions.
549 ///611 ///
550 /// # Permissions612 /// # Permissions
551 ///613 ///
552 /// * Collection Owner614 /// * Collection owner
553 ///615 ///
554 /// # Arguments616 /// # Arguments
555 ///617 ///
556 /// * collection_id.618 /// * `collection_id`: ID of the collection with the sponsor to remove.
557 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]619 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]
558 #[transactional]620 #[transactional]
559 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {621 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {
571 target_collection.save()633 target_collection.save()
572 }634 }
573635
574 /// Create a concrete instance of NFT Collection created with CreateCollection method.636 /// Mint an item within a collection.
637 ///
638 /// A collection must exist first, see [`create_collection_ex`](Call::create_collection_ex).
575 ///639 ///
576 /// # Permissions640 /// # Permissions
577 ///641 ///
578 /// * Collection Owner642 /// * Collection owner
579 /// * Collection Admin643 /// * Collection admin
580 /// * Anyone if644 /// * Anyone if
581 /// * Allow List is enabled, and645 /// * Allow List is enabled, and
582 /// * Address is added to allow list, and646 /// * Address is added to allow list, and
583 /// * MintPermission is enabled (see SetMintPermission method)647 /// * MintPermission is enabled (see [`set_collection_permissions`](Call::set_collection_permissions))
584 ///648 ///
585 /// # Arguments649 /// # Arguments
586 ///650 ///
587 /// * collection_id - ID of the collection.651 /// * `collection_id`: ID of the collection to which an item would belong.
588 /// * owner - Address, initial owner of the NFT.652 /// * `owner`: Address of the initial owner of the item.
589 /// * data - Token data to store on chain.653 /// * `data`: Token data describing the item to store on chain.
590 #[weight = T::CommonWeightInfo::create_item()]654 #[weight = T::CommonWeightInfo::create_item()]
591 #[transactional]655 #[transactional]
592 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {656 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {
596 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))660 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))
597 }661 }
598662
599 /// Create multiple items in a collection created with CreateCollection method.663 /// Create multiple items within a collection.
664 ///
665 /// A collection must exist first, see [`create_collection_ex`](Call::create_collection_ex).
600 ///666 ///
601 /// # Permissions667 /// # Permissions
602 ///668 ///
603 /// * Collection Owner669 /// * Collection owner
604 /// * Collection Admin670 /// * Collection admin
605 /// * Anyone if671 /// * Anyone if
606 /// * Allow List is enabled, and672 /// * Allow List is enabled, and
607 /// * Address is added to allow list, and673 /// * Address is added to the allow list, and
608 /// * MintPermission is enabled (see SetMintPermission method)674 /// * MintPermission is enabled (see [`set_collection_permissions`](Call::set_collection_permissions))
609 ///675 ///
610 /// # Arguments676 /// # Arguments
611 ///677 ///
612 /// * collection_id - ID of the collection.678 /// * `collection_id`: ID of the collection to which the tokens would belong.
613 /// * owner - Address, initial owner of the NFT.679 /// * `owner`: Address of the initial owner of the tokens.
614 /// * items_data - Array items properties. Each property is an array of bytes itself, see [`create_item`].680 /// * `items_data`: Vector of data describing each item to be created.
615 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]681 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]
616 #[transactional]682 #[transactional]
617 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {683 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {
626 ///692 ///
627 /// # Permissions693 /// # Permissions
628 ///694 ///
629 /// * Collection Owner695 /// * Collection owner
630 /// * Collection Admin696 /// * Collection admin
631 ///697 ///
632 /// # Arguments698 /// # Arguments
633 ///699 ///
634 /// * collection_id.700 /// * `collection_id`: ID of the modified collection.
635 /// * properties - Vector of key-value pairs stored as the collection's metadata. Keys support Latin letters, `-`, `_`, and `.` as symbols.701 /// * `properties`: Vector of key-value pairs stored as the collection's metadata.
702 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
636 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]703 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]
637 #[transactional]704 #[transactional]
638 pub fn set_collection_properties(705 pub fn set_collection_properties(
656 ///723 ///
657 /// # Arguments724 /// # Arguments
658 ///725 ///
659 /// * collection_id.726 /// * `collection_id`: ID of the modified collection.
660 /// * property_keys - Vector of keys of the properties to be deleted.727 /// * `property_keys`: Vector of keys of the properties to be deleted.
728 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
661 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]729 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]
662 #[transactional]730 #[transactional]
663 pub fn delete_collection_properties(731 pub fn delete_collection_properties(
673 }741 }
674742
675 /// Add or change token properties according to collection's permissions.743 /// Add or change token properties according to collection's permissions.
744 /// Currently properties only work with NFTs.
676 ///745 ///
677 /// # Permissions746 /// # Permissions
678 ///747 ///
679 /// * Depends on collection's token property permissions and specified property mutability:748 /// * Depends on collection's token property permissions and specified property mutability:
680 /// * Collection Owner749 /// * Collection owner
681 /// * Collection Admin750 /// * Collection admin
682 /// * Token Owner751 /// * Token owner
752 ///
753 /// See [`set_token_property_permissions`](Call::set_token_property_permissions).
683 ///754 ///
684 /// # Arguments755 /// # Arguments
685 ///756 ///
686 /// * collection_id.757 /// * `collection_id: ID of the collection to which the token belongs.
687 /// * token_id.758 /// * `token_id`: ID of the modified token.
688 /// * properties - Vector of key-value pairs stored as the token's metadata. Keys support Latin letters, `-`, `_`, and `.` as symbols.759 /// * `properties`: Vector of key-value pairs stored as the token's metadata.
760 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
689 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]761 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]
690 #[transactional]762 #[transactional]
691 pub fn set_token_properties(763 pub fn set_token_properties(
702 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties, &budget))774 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties, &budget))
703 }775 }
704776
705 /// Delete specified token properties.777 /// Delete specified token properties. Currently properties only work with NFTs.
706 ///778 ///
707 /// # Permissions779 /// # Permissions
708 ///780 ///
709 /// * Depends on collection's token property permissions and specified property mutability:781 /// * Depends on collection's token property permissions and specified property mutability:
710 /// * Collection Owner782 /// * Collection owner
711 /// * Collection Admin783 /// * Collection admin
712 /// * Token Owner784 /// * Token owner
713 ///785 ///
714 /// # Arguments786 /// # Arguments
715 ///787 ///
716 /// * collection_id.788 /// * `collection_id`: ID of the collection to which the token belongs.
717 /// * token_id.789 /// * `token_id`: ID of the modified token.
718 /// * property_keys - Vector of keys of the properties to be deleted.790 /// * `property_keys`: Vector of keys of the properties to be deleted.
791 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
719 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]792 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]
720 #[transactional]793 #[transactional]
721 pub fn delete_token_properties(794 pub fn delete_token_properties(
733 }806 }
734807
735 /// Add or change token property permissions of a collection.808 /// Add or change token property permissions of a collection.
809 ///
810 /// Without a permission for a particular key, a property with that key
811 /// cannot be created in a token.
736 ///812 ///
737 /// # Permissions813 /// # Permissions
738 ///814 ///
739 /// * Collection Owner815 /// * Collection owner
740 /// * Collection Admin816 /// * Collection admin
741 ///817 ///
742 /// # Arguments818 /// # Arguments
743 ///819 ///
744 /// * collection_id.820 /// * `collection_id`: ID of the modified collection.
745 /// * property_permissions - Vector of permissions for property keys. Keys support Latin letters, `-`, `_`, and `.` as symbols.821 /// * `property_permissions`: Vector of permissions for property keys.
822 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
746 #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]823 #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]
747 #[transactional]824 #[transactional]
748 pub fn set_token_property_permissions(825 pub fn set_token_property_permissions(
757 dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))834 dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))
758 }835 }
759836
760 /// Create multiple items inside a collection with explicitly specified initial parameters.837 /// Create multiple items within a collection with explicitly specified initial parameters.
761 ///838 ///
762 /// # Permissions839 /// # Permissions
763 ///840 ///
764 /// * Collection Owner841 /// * Collection owner
765 /// * Collection Admin842 /// * Collection admin
766 /// * Anyone if843 /// * Anyone if
767 /// * Allow List is enabled, and844 /// * Allow List is enabled, and
768 /// * Address is added to allow list, and845 /// * Address is added to allow list, and
769 /// * MintPermission is enabled (see SetMintPermission method)846 /// * MintPermission is enabled (see [`set_collection_permissions`](Call::set_collection_permissions))
770 ///847 ///
771 /// # Arguments848 /// # Arguments
772 ///849 ///
773 /// * collection_id - ID of the collection.850 /// * `collection_id`: ID of the collection to which the tokens would belong.
774 /// * data - Explicit item creation data.851 /// * `data`: Explicit item creation data.
775 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]852 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]
776 #[transactional]853 #[transactional]
777 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {854 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {
781 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))858 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))
782 }859 }
783860
784 /// Set transfers_enabled value for particular collection.861 /// Completely allow or disallow transfers for a particular collection.
785 ///862 ///
786 /// # Permissions863 /// # Permissions
787 ///864 ///
788 /// * Collection Owner865 /// * Collection owner
789 ///866 ///
790 /// # Arguments867 /// # Arguments
791 ///868 ///
792 /// * collection_id - ID of the collection.869 /// * `collection_id`: ID of the collection.
793 /// * value - New flag value.870 /// * `value`: New value of the flag, are transfers allowed?
794 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]871 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]
795 #[transactional]872 #[transactional]
796 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {873 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {
805 target_collection.save()882 target_collection.save()
806 }883 }
807884
808 /// Destroy a concrete instance of NFT.885 /// Destroy an item.
809 ///886 ///
810 /// # Permissions887 /// # Permissions
811 ///888 ///
812 /// * Collection Owner889 /// * Collection owner
813 /// * Collection Admin890 /// * Collection admin
814 /// * Current NFT Owner891 /// * Current item owner
815 ///892 ///
816 /// # Arguments893 /// # Arguments
817 ///894 ///
818 /// * collection_id - ID of the collection.895 /// * `collection_id`: ID of the collection to which the item belongs.
819 /// * item_id - ID of NFT to burn.896 /// * `item_id`: ID of item to burn.
897 /// * `value`: Number of parts of the item to destroy.
898 /// * Non-Fungible Mode: There is always 1 NFT.
899 /// * Fungible Mode: The desired number of parts to burn.
900 /// * Re-Fungible Mode: The desired number of parts to burn.
820 #[weight = T::CommonWeightInfo::burn_item()]901 #[weight = T::CommonWeightInfo::burn_item()]
821 #[transactional]902 #[transactional]
822 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {903 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {
833 Ok(post_info)914 Ok(post_info)
834 }915 }
835916
836 /// Destroy a concrete instance of NFT on behalf of the owner.917 /// Destroy a token on behalf of the owner as a non-owner account.
837 /// See also: [`approve`]918 /// See also: [`approve`](Call::approve).
919 ///
920 /// After this method executes, one approval is removed from the total so that
921 /// the approved address will not be able to transfer this item again from this owner.
838 ///922 ///
839 /// # Permissions923 /// # Permissions
840 ///924 ///
841 /// * Collection Owner.925 /// * Collection owner
842 /// * Collection Admin.926 /// * Collection admin
843 /// * Current NFT Owner.927 /// * Current token owner
928 /// * Address approved by current item owner
844 ///929 ///
845 /// # Arguments930 /// # Arguments
846 ///931 ///
932 /// * `from`: The owner of the burning item.
847 /// * collection_id - ID of the collection.933 /// * `collection_id`: ID of the collection to which the item belongs.
848 /// * item_id - ID of NFT to burn.934 /// * `item_id`: ID of item to burn.
849 /// * from - The owner of the item from whom it is taken away.935 /// * `value`: Number of parts to burn.
936 /// * Non-Fungible Mode: There is always 1 NFT.
937 /// * Fungible Mode: The desired number of parts to burn.
938 /// * Re-Fungible Mode: The desired number of parts to burn.
850 #[weight = T::CommonWeightInfo::burn_from()]939 #[weight = T::CommonWeightInfo::burn_from()]
851 #[transactional]940 #[transactional]
852 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {941 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {
860 ///949 ///
861 /// # Permissions950 /// # Permissions
862 ///951 ///
863 /// * Collection Owner952 /// * Collection owner
864 /// * Collection Admin953 /// * Collection admin
865 /// * Current NFT owner954 /// * Current token owner
866 ///955 ///
867 /// # Arguments956 /// # Arguments
868 ///957 ///
869 /// * recipient - Address of token recipient.958 /// * `recipient`: Address of token recipient.
870 ///959 /// * `collection_id`: ID of the collection the item belongs to.
871 /// * collection_id.
872 ///
873 /// * item_id - ID of the item960 /// * `item_id`: ID of the item.
874 /// * Non-Fungible Mode: Required.961 /// * Non-Fungible Mode: Required.
875 /// * Fungible Mode: Ignored.962 /// * Fungible Mode: Ignored.
876 /// * Re-Fungible Mode: Required.963 /// * Re-Fungible Mode: Required.
877 ///964 ///
878 /// * value - Amount to transfer.965 /// * `value`: Amount to transfer.
879 /// * Non-Fungible Mode: Ignored966 /// * Non-Fungible Mode: There is always 1 NFT.
880 /// * Fungible Mode: Must specify transferred amount967 /// * Fungible Mode: The desired number of parts to transfer.
881 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)968 /// * Re-Fungible Mode: The desired number of parts to transfer.
882 #[weight = T::CommonWeightInfo::transfer()]969 #[weight = T::CommonWeightInfo::transfer()]
883 #[transactional]970 #[transactional]
884 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {971 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {
888 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))975 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))
889 }976 }
890977
891 /// Set, change, or remove approved address to transfer the ownership of the NFT.978 /// Allow a non-permissioned address to transfer or burn an item.
892 ///979 ///
893 /// # Permissions980 /// # Permissions
894 ///981 ///
895 /// * Collection Owner982 /// * Collection owner
896 /// * Collection Admin983 /// * Collection admin
897 /// * Current NFT owner984 /// * Current item owner
898 ///985 ///
899 /// # Arguments986 /// # Arguments
900 ///987 ///
901 /// * approved - Address that is approved to transfer this NFT or zero (if needed to remove approval).988 /// * `spender`: Account to be approved to make specific transactions on non-owned tokens.
902 /// * collection_id.989 /// * `collection_id`: ID of the collection the item belongs to.
903 /// * item_id - ID of the item.990 /// * `item_id`: ID of the item transactions on which are now approved.
991 /// * `amount`: Number of approved transactions overwriting the current number,
992 /// e.g. set to `0` to remove approval.
904 #[weight = T::CommonWeightInfo::approve()]993 #[weight = T::CommonWeightInfo::approve()]
905 #[transactional]994 #[transactional]
906 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {995 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {
909 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))998 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))
910 }999 }
9111000
912 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.1001 /// Change ownership of an item on behalf of the owner as a non-owner account.
1002 /// See the [`approve`](Call::approve) method for additional information.
1003 ///
1004 /// After this method executes, one approval is removed from the total so that
1005 /// the approved address will not be able to transfer this item again from this owner.
913 ///1006 ///
914 /// # Permissions1007 /// # Permissions
915 ///1008 ///
916 /// * Collection Owner1009 /// * Collection owner
917 /// * Collection Admin1010 /// * Collection admin
918 /// * Current NFT owner1011 /// * Current item owner
919 /// * Address approved by current NFT owner1012 /// * Address approved by current item owner
920 ///1013 ///
921 /// # Arguments1014 /// # Arguments
922 ///1015 ///
923 /// * from - Address that currently owns the token.1016 /// * `from`: Address that currently owns the token.
924 /// * recipient - Address of the new token-owner-to-be.1017 /// * `recipient`: Address of the new token-owner-to-be.
925 /// * collection_id.1018 /// * `collection_id`: ID of the collection the item.
926 /// * item_id - ID of the item to be transferred.1019 /// * `item_id`: ID of the item to be transferred.
927 /// * value - Amount to transfer.1020 /// * `value`: Amount of parts to transfer.
1021 /// * Non-Fungible Mode: There is always 1 NFT.
1022 /// * Fungible Mode: The desired number of parts to transfer.
1023 /// * Re-Fungible Mode: The desired number of parts to transfer.
928 #[weight = T::CommonWeightInfo::transfer_from()]1024 #[weight = T::CommonWeightInfo::transfer_from()]
929 #[transactional]1025 #[transactional]
930 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {1026 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {
938 ///1034 ///
939 /// # Permissions1035 /// # Permissions
940 ///1036 ///
941 /// * Collection Owner1037 /// * Collection owner
942 /// * Collection Admin1038 /// * Collection admin
943 ///1039 ///
944 /// # Arguments1040 /// # Arguments
945 ///1041 ///
946 /// * collection_id.1042 /// * `collection_id`: ID of the modified collection.
947 /// * new_limit - New limits of the collection. They will overwrite the current ones.1043 /// * `new_limit`: New limits of the collection. They will overwrite the current ones.
948 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1044 #[weight = <SelfWeightOf<T>>::set_collection_limits()]
949 #[transactional]1045 #[transactional]
950 pub fn set_collection_limits(1046 pub fn set_collection_limits(
971 ///1067 ///
972 /// # Permissions1068 /// # Permissions
973 ///1069 ///
974 /// * Collection Owner1070 /// * Collection owner
975 /// * Collection Admin1071 /// * Collection admin
976 ///1072 ///
977 /// # Arguments1073 /// # Arguments
978 ///1074 ///
979 /// * collection_id.1075 /// * `collection_id`: ID of the modified collection.
980 /// * new_permission - New permissions of the collection. They will overwrite the current ones.1076 /// * `new_permission`: New permissions of the collection. They will overwrite the current ones.
981 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1077 #[weight = <SelfWeightOf<T>>::set_collection_limits()]
982 #[transactional]1078 #[transactional]
983 pub fn set_collection_permissions(1079 pub fn set_collection_permissions(
1004 ///1100 ///
1005 /// # Permissions1101 /// # Permissions
1006 ///1102 ///
1007 /// * Token Owner (must own every part)1103 /// * Token owner (must own every part)
1008 ///1104 ///
1009 /// # Arguments1105 /// # Arguments
1010 ///1106 ///
1011 /// * collection_id.1107 /// * `collection_id`: ID of the collection the RFT belongs to.
1012 /// * token_id - ID of the RFT.1108 /// * `token_id`: ID of the RFT.
1013 /// * amount - New number of parts into which the token shall be partitioned.1109 /// * `amount`: New number of parts into which the token shall be partitioned.
1014 #[weight = T::RefungibleExtensionsWeightInfo::repartition()]1110 #[weight = T::RefungibleExtensionsWeightInfo::repartition()]
1015 #[transactional]1111 #[transactional]
1016 pub fn repartition(1112 pub fn repartition(