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

difftreelog

refactor(pallet-unique) switch to #[pallet] macro

Yaroslav Bolyukin2023-04-17parent: #2993020.patch.diff
in: master

3 files changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -27,7 +27,7 @@
 	dispatch::CollectionDispatch,
 	erc::{CollectionHelpersEvents, static_property::key},
 	eth::{map_eth_to_id, collection_id_to_address},
-	Pallet as PalletCommon,
+	Pallet as PalletCommon, CollectionHandle,
 };
 use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
 use pallet_evm_coder_substrate::{
@@ -262,7 +262,7 @@
 		let collection =
 			pallet_common::eth::map_eth_to_id(&collection).ok_or("not a collection address")?;
 		let mut collection =
-			<crate::CollectionHandle<T>>::new(collection).ok_or("collection not found")?;
+			<CollectionHandle<T>>::new(collection).ok_or("collection not found")?;
 
 		if !matches!(
 			collection.mode,
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
7373
74extern crate alloc;74extern crate alloc;
7575
76use frame_support::{76pub use pallet::*;
77 decl_module, decl_storage, decl_error,
78 dispatch::DispatchResult,
79 ensure, fail,
80 weights::{Weight},
81 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},
82 BoundedVec,
83};
84use scale_info::TypeInfo;
85use frame_system::{self as system, ensure_signed, ensure_root};77use frame_support::pallet_prelude::*;
86use sp_std::{vec, vec::Vec};
87use up_data_structs::{78use frame_system::pallet_prelude::*;
88 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
89 MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,
90 MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,
91 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,
92 CreateCollectionData, CreateItemExData, budget, Property, PropertyKey, PropertyKeyPermission,
93};
94use pallet_evm::account::CrossAccountId;
95use pallet_common::{
96 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,
97 dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,
98};
99pub mod eth;79pub mod eth;
10080
101#[cfg(feature = "runtime-benchmarks")]81#[cfg(feature = "runtime-benchmarks")]
102pub mod benchmarking;82pub mod benchmarking;
103pub mod weights;83pub mod weights;
104use weights::WeightInfo;
10584
106/// A maximum number of levels of depth in the token nesting tree.85#[frame_support::pallet]
107pub const NESTING_BUDGET: u32 = 5;86pub mod pallet {
87 use super::*;
10888
109decl_error! {89 use frame_support::{
90 dispatch::DispatchResult,
91 ensure, fail,
92 weights::{Weight},
93 pallet_prelude::{*},
94 BoundedVec,
95 storage::Key,
96 };
97 use frame_system::pallet_prelude::*;
98 use scale_info::TypeInfo;
99 use frame_system::{self as system, ensure_signed, ensure_root};
100 use sp_std::{vec, vec::Vec};
101 use up_data_structs::{
102 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
103 MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,
104 MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,
105 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode,
106 TokenId, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,
107 PropertyKeyPermission,
108 };
109 use pallet_evm::account::CrossAccountId;
110 use pallet_common::{
111 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,
112 dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,
113 };
114 use weights::WeightInfo;
115
116 /// A maximum number of levels of depth in the token nesting tree.
117 pub const NESTING_BUDGET: u32 = 5;
118
110 /// Errors for the common Unique transactions.119 /// Errors for the common Unique transactions.
111 pub enum Error for Module<T: Config> {120 #[pallet::error]
121 pub enum Error<T> {
112 /// Decimal_points parameter must be lower than [`up_data_structs::MAX_DECIMAL_POINTS`].122 /// Decimal_points parameter must be lower than [`up_data_structs::MAX_DECIMAL_POINTS`].
113 CollectionDecimalPointLimitExceeded,123 CollectionDecimalPointLimitExceeded,
114 /// Length of items properties must be greater than 0.124 /// Length of items properties must be greater than 0.
115 EmptyArgument,125 EmptyArgument,
116 /// Repertition is only supported by refungible collection.126 /// Repertition is only supported by refungible collection.
117 RepartitionCalledOnNonRefungibleCollection,127 RepartitionCalledOnNonRefungibleCollection,
118 }128 }
119}
120129
121/// Configuration trait of this pallet.130 /// Configuration trait of this pallet.
131 #[pallet::config]
122pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {132 pub trait Config: frame_system::Config + pallet_common::Config + Sized + TypeInfo {
123 /// Weight information for extrinsics in this pallet.133 /// Weight information for extrinsics in this pallet.
124 type WeightInfo: WeightInfo;134 type WeightInfo: WeightInfo;
125135
126 /// Weight information for common pallet operations.136 /// Weight information for common pallet operations.
127 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;137 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;
128138
129 /// Weight info information for extra refungible pallet operations.139 /// Weight info information for extra refungible pallet operations.
130 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;140 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;
131}141 }
132142
143 #[pallet::pallet]
133type SelfWeightOf<T> = <T as Config>::WeightInfo;144 pub struct Pallet<T>(_);
134145
135// # Used definitions146 pub type SelfWeightOf<T> = <T as Config>::WeightInfo;
136//
137// ## User control levels
138//
139// chain-controlled - key is uncontrolled by user
140// i.e autoincrementing index
141// can use non-cryptographic hash
142// real - key is controlled by user
143// but it is hard to generate enough colliding values, i.e owner of signed txs
144// can use non-cryptographic hash
145// controlled - key is completly controlled by users
146// i.e maps with mutable keys
147// should use cryptographic hash
148//
149// ## User control level downgrade reasons
150//
151// ?1 - chain-controlled -> controlled
152// collections/tokens can be destroyed, resulting in massive holes
153// ?2 - chain-controlled -> controlled
154// same as ?1, but can be only added, resulting in easier exploitation
155// ?3 - real -> controlled
156// no confirmation required, so addresses can be easily generated
157decl_storage! {
158 trait Store for Module<T: Config> as Unique {
159147
160 //#region Private members148 // # Used definitions
149 //
150 // ## User control levels
161 /// Used for migrations151 //
152 // chain-controlled - key is uncontrolled by user
153 // i.e autoincrementing index
162 ChainVersion: u64;154 // can use non-cryptographic hash
155 // real - key is controlled by user
163 //#endregion156 // but it is hard to generate enough colliding values, i.e owner of signed txs
157 // can use non-cryptographic hash
158 // controlled - key is completly controlled by users
159 // i.e maps with mutable keys
160 // should use cryptographic hash
161 //
162 // ## User control level downgrade reasons
163 //
164 // ?1 - chain-controlled -> controlled
165 // collections/tokens can be destroyed, resulting in massive holes
166 // ?2 - chain-controlled -> controlled
167 // same as ?1, but can be only added, resulting in easier exploitation
168 // ?3 - real -> controlled
169 // no confirmation required, so addresses can be easily generated
164170
165 //#region Tokens transfer sponosoring rate limit baskets171 //#region Private members
166 /// (Collection id (controlled?2), who created (real))172 /// Used for migrations
167 /// TODO: Off chain worker should remove from this map when collection gets removed173 #[pallet::storage]
168 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;
169 /// Collection id (controlled?2), token id (controlled?2)174 pub type ChainVersion<T> = StorageValue<_, u64, ValueQuery>;
170 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;
171 /// Collection id (controlled?2), owning user (real)
172 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;
173 /// Collection id (controlled?2), token id (controlled?2)
174 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;
175 //#endregion175 //#endregion
176176
177 /// Variable metadata sponsoring177 //#region Tokens transfer sponosoring rate limit baskets
178 /// (Collection id (controlled?2), who created (real))
178 /// Collection id (controlled?2), token id (controlled?2)179 /// TODO: Off chain worker should remove from this map when collection gets removed
180 #[pallet::storage]
181 #[pallet::getter(fn create_item_busket)]
182 pub type CreateItemBasket<T: Config> = StorageMap<
183 Hasher = Blake2_128Concat,
184 Key = (CollectionId, T::AccountId),
185 Value = T::BlockNumber,
186 QueryKind = OptionQuery,
187 >;
188 /// Collection id (controlled?2), token id (controlled?2)
179 #[deprecated]189 #[pallet::storage]
190 #[pallet::getter(fn nft_transfer_basket)]
180 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;191 pub type NftTransferBasket<T: Config> = StorageDoubleMap<
192 Hasher1 = Blake2_128Concat,
193 Key1 = CollectionId,
194 Hasher2 = Blake2_128Concat,
195 Key2 = TokenId,
196 Value = T::BlockNumber,
197 QueryKind = OptionQuery,
198 >;
181 /// Last sponsoring of token property setting // todo:doc rephrase this and the following199 /// Collection id (controlled?2), owning user (real)
200 #[pallet::storage]
201 #[pallet::getter(fn fungible_transfer_basket)]
202 pub type FungibleTransferBasket<T: Config> = StorageDoubleMap<
203 Hasher1 = Blake2_128Concat,
182 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;204 Key1 = CollectionId,
205 Hasher2 = Twox64Concat,
206 Key2 = T::AccountId,
207 Value = T::BlockNumber,
208 QueryKind = OptionQuery,
209 >;
210 /// Collection id (controlled?2), token id (controlled?2)
211 #[pallet::storage]
212 #[pallet::getter(fn refungible_transfer_basket)]
213 pub type ReFungibleTransferBasket<T: Config> = StorageNMap<
214 Key = (
215 Key<Blake2_128Concat, CollectionId>,
216 Key<Blake2_128Concat, TokenId>,
217 Key<Twox64Concat, T::AccountId>,
218 ),
219 Value = T::BlockNumber,
220 QueryKind = OptionQuery,
221 >;
222 //#endregion
183223
184 /// Last sponsoring of NFT approval in a collection224 /// Last sponsoring of token property setting // todo:doc rephrase this and the following
185 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;225 #[pallet::storage]
186 /// Last sponsoring of fungible tokens approval in a collection226 #[pallet::getter(fn token_property_basket)]
187 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;227 pub type TokenPropertyBasket<T: Config> = StorageDoubleMap<
188 /// Last sponsoring of RFT approval in a collection228 Hasher1 = Blake2_128Concat,
229 Key1 = CollectionId,
189 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;230 Hasher2 = Blake2_128Concat,
231 Key2 = TokenId,
232 Value = T::BlockNumber,
190 }233 QueryKind = OptionQuery,
191}234 >;
192235
193decl_module! {236 /// Last sponsoring of NFT approval in a collection
194 /// Type alias to Pallet, to be used by construct_runtime.237 #[pallet::storage]
238 #[pallet::getter(fn nft_approve_basket)]
239 pub type NftApproveBasket<T: Config> = StorageDoubleMap<
240 Hasher1 = Blake2_128Concat,
241 Key1 = CollectionId,
242 Hasher2 = Blake2_128Concat,
243 Key2 = TokenId,
244 Value = T::BlockNumber,
245 QueryKind = OptionQuery,
246 >;
247 /// Last sponsoring of fungible tokens approval in a collection
195 pub struct Module<T: Config> for enum Call248 #[pallet::storage]
249 #[pallet::getter(fn fungible_approve_basket)]
250 pub type FungibleApproveBasket<T: Config> = StorageDoubleMap<
251 Hasher1 = Blake2_128Concat,
196 where252 Key1 = CollectionId,
197 origin: T::RuntimeOrigin253 Hasher2 = Twox64Concat,
254 Key2 = T::AccountId,
255 Value = T::BlockNumber,
198 {256 QueryKind = OptionQuery,
199 type Error = Error<T>;257 >;
258 /// Last sponsoring of RFT approval in a collection
259 #[pallet::storage]
260 #[pallet::getter(fn refungible_approve_basket)]
261 pub type RefungibleApproveBasket<T: Config> = StorageNMap<
262 Key = (
263 Key<Blake2_128Concat, CollectionId>,
264 Key<Blake2_128Concat, TokenId>,
265 Key<Twox64Concat, T::AccountId>,
266 ),
267 Value = T::BlockNumber,
268 QueryKind = OptionQuery,
269 >;
200270
201 #[doc = "A maximum number of levels of depth in the token nesting tree."]271 #[pallet::extra_constants]
272 impl<T: Config> Pallet<T> {
273 /// A maximum number of levels of depth in the token nesting tree.
202 const NESTING_BUDGET: u32 = NESTING_BUDGET;274 fn nesting_budget() -> u32 {
275 NESTING_BUDGET
276 }
203277
204 #[doc = "Maximal length of a collection name."]278 /// Maximal length of a collection name.
205 const MAX_COLLECTION_NAME_LENGTH: u32 = MAX_COLLECTION_NAME_LENGTH;279 fn max_collection_name_length() -> u32 {
280 MAX_COLLECTION_NAME_LENGTH
281 }
206282
207 #[doc = "Maximal length of a collection description."]283 /// Maximal length of a collection description.
208 const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = MAX_COLLECTION_DESCRIPTION_LENGTH;284 fn max_collection_description_length() -> u32 {
285 MAX_COLLECTION_DESCRIPTION_LENGTH
286 }
209287
210 #[doc = "Maximal length of a token prefix."]288 /// Maximal length of a token prefix.
211 const MAX_TOKEN_PREFIX_LENGTH: u32 = MAX_TOKEN_PREFIX_LENGTH;289 fn max_token_prefix_length() -> u32 {
290 MAX_TOKEN_PREFIX_LENGTH
291 }
212292
213 #[doc = "Maximum admins per collection."]293 /// Maximum admins per collection.
214 const COLLECTION_ADMINS_LIMIT: u32 = COLLECTION_ADMINS_LIMIT;294 fn collection_admins_limit() -> u32 {
295 COLLECTION_ADMINS_LIMIT
296 }
215297
216 #[doc = "Maximal length of a property key."]298 /// Maximal length of a property key.
217 const MAX_PROPERTY_KEY_LENGTH: u32 = MAX_PROPERTY_KEY_LENGTH;299 fn max_property_key_length() -> u32 {
300 MAX_PROPERTY_KEY_LENGTH
301 }
218302
219 #[doc = "Maximal length of a property value."]303 /// Maximal length of a property value.
220 const MAX_PROPERTY_VALUE_LENGTH: u32 = MAX_PROPERTY_VALUE_LENGTH;304 fn max_property_value_length() -> u32 {
305 MAX_PROPERTY_VALUE_LENGTH
306 }
221307
222 #[doc = "A maximum number of token properties."]308 /// A maximum number of token properties.
223 const MAX_PROPERTIES_PER_ITEM: u32 = MAX_PROPERTIES_PER_ITEM;309 fn max_properties_per_item() -> u32 {
310 MAX_PROPERTIES_PER_ITEM
311 }
224312
225 #[doc = "Maximum size for all collection properties."]313 /// Maximum size for all collection properties.
226 const MAX_COLLECTION_PROPERTIES_SIZE: u32 = MAX_COLLECTION_PROPERTIES_SIZE;314 fn max_collection_properties_size() -> u32 {
315 MAX_COLLECTION_PROPERTIES_SIZE
316 }
227317
228 #[doc = "Maximum size of all token properties."]318 /// Maximum size of all token properties.
229 const MAX_TOKEN_PROPERTIES_SIZE: u32 = MAX_TOKEN_PROPERTIES_SIZE;319 fn max_token_properties_size() -> u32 {
320 MAX_TOKEN_PROPERTIES_SIZE
321 }
230322
231 #[doc = "Default NFT collection limit."]323 /// Default NFT collection limit.
232 const NFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::NFT);324 fn nft_default_collection_limits() -> CollectionLimits {
325 CollectionLimits::with_default_limits(CollectionMode::NFT)
326 }
233327
234 #[doc = "Default RFT collection limit."]328 /// Default RFT collection limit.
235 const RFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::ReFungible);329 fn rft_default_collection_limits() -> CollectionLimits {
236
237 #[doc = "Default FT collection limit."]
238 const FT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::Fungible(0));
239
240 fn on_initialize(_now: T::BlockNumber) -> Weight {
241 Weight::zero()330 CollectionLimits::with_default_limits(CollectionMode::ReFungible)
242 }331 }
243332
244 fn on_runtime_upgrade() -> Weight {333 /// Default FT collection limit.
334 fn ft_default_collection_limits() -> CollectionLimits {
245 Weight::zero()335 CollectionLimits::with_default_limits(CollectionMode::Fungible(0))
246 }336 }
337 }
247338
339 /// Type alias to Pallet, to be used by construct_runtime.
340 #[pallet::call]
341 impl<T: Config> Pallet<T> {
248 /// Create a collection of tokens.342 /// Create a collection of tokens.
249 ///343 ///
250 /// Each Token may have multiple properties encoded as an array of bytes344 /// Each Token may have multiple properties encoded as an array of bytes
270 /// returns collection ID364 /// returns collection ID
271 ///365 ///
272 /// Deprecated: `create_collection_ex` is more up-to-date and advanced, prefer it instead.366 /// Deprecated: `create_collection_ex` is more up-to-date and advanced, prefer it instead.
273 #[weight = <SelfWeightOf<T>>::create_collection()]367 #[pallet::call_index(0)]
368 #[pallet::weight(<SelfWeightOf<T>>::create_collection())]
274 fn create_collection(369 pub fn create_collection(
275 origin,370 origin: OriginFor<T>,
276 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,371 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,
277 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,372 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,
278 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,373 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
279 mode: CollectionMode374 mode: CollectionMode,
280 ) -> DispatchResult {375 ) -> DispatchResult {
281 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {376 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {
282 name: collection_name,377 name: collection_name,
299 /// # Arguments394 /// # Arguments
300 ///395 ///
301 /// * `data`: Explicit data of a collection used for its creation.396 /// * `data`: Explicit data of a collection used for its creation.
302 #[weight = <SelfWeightOf<T>>::create_collection()]397 #[pallet::call_index(1)]
398 #[pallet::weight(<SelfWeightOf<T>>::create_collection())]
303 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {399 pub fn create_collection_ex(
400 origin: OriginFor<T>,
401 data: CreateCollectionData<T::AccountId>,
402 ) -> DispatchResult {
304 let sender = ensure_signed(origin)?;403 let sender = ensure_signed(origin)?;
305404
306 // =========405 // =========
307 let sender = T::CrossAccountId::from_sub(sender);406 let sender = T::CrossAccountId::from_sub(sender);
308 let _id = T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;407 let _id =
408 T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;
309409
310 Ok(())410 Ok(())
311 }411 }
319 /// # Arguments419 /// # Arguments
320 ///420 ///
321 /// * `collection_id`: Collection to destroy.421 /// * `collection_id`: Collection to destroy.
322 #[weight = <SelfWeightOf<T>>::destroy_collection()]422 #[pallet::call_index(2)]
423 #[pallet::weight(<SelfWeightOf<T>>::destroy_collection())]
323 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {424 pub fn destroy_collection(
425 origin: OriginFor<T>,
426 collection_id: CollectionId,
427 ) -> DispatchResult {
324 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);428 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
325429
326 Self::destroy_collection_internal(sender, collection_id)430 Self::destroy_collection_internal(sender, collection_id)
337 ///441 ///
338 /// * `collection_id`: ID of the modified collection.442 /// * `collection_id`: ID of the modified collection.
339 /// * `address`: ID of the address to be added to the allowlist.443 /// * `address`: ID of the address to be added to the allowlist.
340 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]444 #[pallet::call_index(3)]
445 #[pallet::weight(<SelfWeightOf<T>>::add_to_allow_list())]
341 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{446 pub fn add_to_allow_list(
342447 origin: OriginFor<T>,
448 collection_id: CollectionId,
449 address: T::CrossAccountId,
450 ) -> DispatchResult {
343 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);451 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
344 let collection = <CollectionHandle<T>>::try_get(collection_id)?;452 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
345 collection.check_is_internal()?;453 collection.check_is_internal()?;
346454
347 <PalletCommon<T>>::toggle_allowlist(455 <PalletCommon<T>>::toggle_allowlist(&collection, &sender, &address, true)?;
348 &collection,
349 &sender,
350 &address,
351 true,
352 )?;
353456
354 Ok(())457 Ok(())
355 }458 }
365 ///468 ///
366 /// * `collection_id`: ID of the modified collection.469 /// * `collection_id`: ID of the modified collection.
367 /// * `address`: ID of the address to be removed from the allowlist.470 /// * `address`: ID of the address to be removed from the allowlist.
368 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]471 #[pallet::call_index(4)]
472 #[pallet::weight(<SelfWeightOf<T>>::remove_from_allow_list())]
369 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{473 pub fn remove_from_allow_list(
370474 origin: OriginFor<T>,
475 collection_id: CollectionId,
476 address: T::CrossAccountId,
477 ) -> DispatchResult {
371 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);478 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
372 let collection = <CollectionHandle<T>>::try_get(collection_id)?;479 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
373 collection.check_is_internal()?;480 collection.check_is_internal()?;
374481
375 <PalletCommon<T>>::toggle_allowlist(482 <PalletCommon<T>>::toggle_allowlist(&collection, &sender, &address, false)?;
376 &collection,
377 &sender,
378 &address,
379 false,
380 )?;
381483
382 Ok(())484 Ok(())
383 }485 }
392 ///494 ///
393 /// * `collection_id`: ID of the modified collection.495 /// * `collection_id`: ID of the modified collection.
394 /// * `new_owner`: ID of the account that will become the owner.496 /// * `new_owner`: ID of the account that will become the owner.
395 #[weight = <SelfWeightOf<T>>::change_collection_owner()]497 #[pallet::call_index(5)]
498 #[pallet::weight(<SelfWeightOf<T>>::change_collection_owner())]
396 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {499 pub fn change_collection_owner(
500 origin: OriginFor<T>,
501 collection_id: CollectionId,
502 new_owner: T::AccountId,
503 ) -> DispatchResult {
397 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);504 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
398 let new_owner = T::CrossAccountId::from_sub(new_owner);505 let new_owner = T::CrossAccountId::from_sub(new_owner);
399 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;506 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
416 ///523 ///
417 /// * `collection_id`: ID of the Collection to add an admin for.524 /// * `collection_id`: ID of the Collection to add an admin for.
418 /// * `new_admin`: Address of new admin to add.525 /// * `new_admin`: Address of new admin to add.
419 #[weight = <SelfWeightOf<T>>::add_collection_admin()]526 #[pallet::call_index(6)]
527 #[pallet::weight(<SelfWeightOf<T>>::add_collection_admin())]
420 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {528 pub fn add_collection_admin(
529 origin: OriginFor<T>,
530 collection_id: CollectionId,
531 new_admin_id: T::CrossAccountId,
532 ) -> DispatchResult {
421 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);533 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
422 let collection = <CollectionHandle<T>>::try_get(collection_id)?;534 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
423 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)535 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)
437 ///549 ///
438 /// * `collection_id`: ID of the collection to remove the admin for.550 /// * `collection_id`: ID of the collection to remove the admin for.
439 /// * `account_id`: Address of the admin to remove.551 /// * `account_id`: Address of the admin to remove.
440 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]552 #[pallet::call_index(7)]
553 #[pallet::weight(<SelfWeightOf<T>>::remove_collection_admin())]
441 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {554 pub fn remove_collection_admin(
555 origin: OriginFor<T>,
556 collection_id: CollectionId,
557 account_id: T::CrossAccountId,
558 ) -> DispatchResult {
442 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);559 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
443 let collection = <CollectionHandle<T>>::try_get(collection_id)?;560 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
444 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)561 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)
457 ///574 ///
458 /// * `collection_id`: ID of the modified collection.575 /// * `collection_id`: ID of the modified collection.
459 /// * `new_sponsor`: ID of the account of the sponsor-to-be.576 /// * `new_sponsor`: ID of the account of the sponsor-to-be.
460 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]577 #[pallet::call_index(8)]
578 #[pallet::weight(<SelfWeightOf<T>>::set_collection_sponsor())]
461 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {579 pub fn set_collection_sponsor(
580 origin: OriginFor<T>,
581 collection_id: CollectionId,
582 new_sponsor: T::AccountId,
583 ) -> DispatchResult {
462 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);584 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
463 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;585 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
464 target_collection.set_sponsor(&sender, new_sponsor.clone())586 target_collection.set_sponsor(&sender, new_sponsor.clone())
477 /// # Arguments599 /// # Arguments
478 ///600 ///
479 /// * `collection_id`: ID of the collection with the pending sponsor.601 /// * `collection_id`: ID of the collection with the pending sponsor.
480 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]602 #[pallet::call_index(9)]
603 #[pallet::weight(<SelfWeightOf<T>>::confirm_sponsorship())]
481 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {604 pub fn confirm_sponsorship(
605 origin: OriginFor<T>,
606 collection_id: CollectionId,
607 ) -> DispatchResult {
482 let sender = ensure_signed(origin)?;608 let sender = ensure_signed(origin)?;
483 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;609 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
484 target_collection.confirm_sponsorship(&sender)610 target_collection.confirm_sponsorship(&sender)
493 /// # Arguments619 /// # Arguments
494 ///620 ///
495 /// * `collection_id`: ID of the collection with the sponsor to remove.621 /// * `collection_id`: ID of the collection with the sponsor to remove.
496 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]622 #[pallet::call_index(10)]
623 #[pallet::weight(<SelfWeightOf<T>>::remove_collection_sponsor())]
497 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {624 pub fn remove_collection_sponsor(
625 origin: OriginFor<T>,
626 collection_id: CollectionId,
627 ) -> DispatchResult {
498 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);628 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
499 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;629 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
500 target_collection.remove_sponsor(&sender)630 target_collection.remove_sponsor(&sender)
518 /// * `collection_id`: ID of the collection to which an item would belong.648 /// * `collection_id`: ID of the collection to which an item would belong.
519 /// * `owner`: Address of the initial owner of the item.649 /// * `owner`: Address of the initial owner of the item.
520 /// * `data`: Token data describing the item to store on chain.650 /// * `data`: Token data describing the item to store on chain.
521 #[weight = T::CommonWeightInfo::create_item(&data)]651 #[pallet::call_index(11)]
652 #[pallet::weight(T::CommonWeightInfo::create_item(&data))]
522 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {653 pub fn create_item(
654 origin: OriginFor<T>,
655 collection_id: CollectionId,
656 owner: T::CrossAccountId,
657 data: CreateItemData,
658 ) -> DispatchResultWithPostInfo {
523 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);659 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
524 let budget = budget::Value::new(NESTING_BUDGET);660 let budget = budget::Value::new(NESTING_BUDGET);
525661
526 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))662 dispatch_tx::<T, _>(collection_id, |d| {
663 d.create_item(sender, owner, data, &budget)
664 })
527 }665 }
528666
529 /// Create multiple items within a collection.667 /// Create multiple items within a collection.
544 /// * `collection_id`: ID of the collection to which the tokens would belong.682 /// * `collection_id`: ID of the collection to which the tokens would belong.
545 /// * `owner`: Address of the initial owner of the tokens.683 /// * `owner`: Address of the initial owner of the tokens.
546 /// * `items_data`: Vector of data describing each item to be created.684 /// * `items_data`: Vector of data describing each item to be created.
547 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]685 #[pallet::call_index(12)]
686 #[pallet::weight(T::CommonWeightInfo::create_multiple_items(&items_data))]
548 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {687 pub fn create_multiple_items(
688 origin: OriginFor<T>,
689 collection_id: CollectionId,
690 owner: T::CrossAccountId,
691 items_data: Vec<CreateItemData>,
692 ) -> DispatchResultWithPostInfo {
549 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);693 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);
550 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);694 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
551 let budget = budget::Value::new(NESTING_BUDGET);695 let budget = budget::Value::new(NESTING_BUDGET);
552696
553 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))697 dispatch_tx::<T, _>(collection_id, |d| {
698 d.create_multiple_items(sender, owner, items_data, &budget)
699 })
554 }700 }
555701
556 /// Add or change collection properties.702 /// Add or change collection properties.
565 /// * `collection_id`: ID of the modified collection.711 /// * `collection_id`: ID of the modified collection.
566 /// * `properties`: Vector of key-value pairs stored as the collection's metadata.712 /// * `properties`: Vector of key-value pairs stored as the collection's metadata.
567 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.713 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
568 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]714 #[pallet::call_index(13)]
715 #[pallet::weight(T::CommonWeightInfo::set_collection_properties(properties.len() as u32))]
569 pub fn set_collection_properties(716 pub fn set_collection_properties(
570 origin,717 origin: OriginFor<T>,
571 collection_id: CollectionId,718 collection_id: CollectionId,
572 properties: Vec<Property>719 properties: Vec<Property>,
573 ) -> DispatchResultWithPostInfo {720 ) -> DispatchResultWithPostInfo {
574 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);721 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
575722
576 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);723 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
577724
578 dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))725 dispatch_tx::<T, _>(collection_id, |d| {
726 d.set_collection_properties(sender, properties)
727 })
579 }728 }
580729
581 /// Delete specified collection properties.730 /// Delete specified collection properties.
590 /// * `collection_id`: ID of the modified collection.739 /// * `collection_id`: ID of the modified collection.
591 /// * `property_keys`: Vector of keys of the properties to be deleted.740 /// * `property_keys`: Vector of keys of the properties to be deleted.
592 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.741 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
593 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]742 #[pallet::call_index(14)]
743 #[pallet::weight(T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32))]
594 pub fn delete_collection_properties(744 pub fn delete_collection_properties(
595 origin,745 origin: OriginFor<T>,
596 collection_id: CollectionId,746 collection_id: CollectionId,
597 property_keys: Vec<PropertyKey>,747 property_keys: Vec<PropertyKey>,
598 ) -> DispatchResultWithPostInfo {748 ) -> DispatchResultWithPostInfo {
599 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);749 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);
600750
601 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);751 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
602752
603 dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))753 dispatch_tx::<T, _>(collection_id, |d| {
754 d.delete_collection_properties(&sender, property_keys)
755 })
604 }756 }
605757
606 /// Add or change token properties according to collection's permissions.758 /// Add or change token properties according to collection's permissions.
621 /// * `token_id`: ID of the modified token.773 /// * `token_id`: ID of the modified token.
622 /// * `properties`: Vector of key-value pairs stored as the token's metadata.774 /// * `properties`: Vector of key-value pairs stored as the token's metadata.
623 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.775 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
624 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]776 #[pallet::call_index(15)]
777 #[pallet::weight(T::CommonWeightInfo::set_token_properties(properties.len() as u32))]
625 pub fn set_token_properties(778 pub fn set_token_properties(
626 origin,779 origin: OriginFor<T>,
627 collection_id: CollectionId,780 collection_id: CollectionId,
628 token_id: TokenId,781 token_id: TokenId,
629 properties: Vec<Property>782 properties: Vec<Property>,
630 ) -> DispatchResultWithPostInfo {783 ) -> DispatchResultWithPostInfo {
631 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);784 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
632785
633 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);786 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
634 let budget = budget::Value::new(NESTING_BUDGET);787 let budget = budget::Value::new(NESTING_BUDGET);
635788
636 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties, &budget))789 dispatch_tx::<T, _>(collection_id, |d| {
790 d.set_token_properties(sender, token_id, properties, &budget)
791 })
637 }792 }
638793
639 /// Delete specified token properties. Currently properties only work with NFTs.794 /// Delete specified token properties. Currently properties only work with NFTs.
651 /// * `token_id`: ID of the modified token.806 /// * `token_id`: ID of the modified token.
652 /// * `property_keys`: Vector of keys of the properties to be deleted.807 /// * `property_keys`: Vector of keys of the properties to be deleted.
653 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.808 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
654 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]809 #[pallet::call_index(16)]
810 #[pallet::weight(T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32))]
655 pub fn delete_token_properties(811 pub fn delete_token_properties(
656 origin,812 origin: OriginFor<T>,
657 collection_id: CollectionId,813 collection_id: CollectionId,
658 token_id: TokenId,814 token_id: TokenId,
659 property_keys: Vec<PropertyKey>815 property_keys: Vec<PropertyKey>,
660 ) -> DispatchResultWithPostInfo {816 ) -> DispatchResultWithPostInfo {
661 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);817 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);
662818
663 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);819 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
664 let budget = budget::Value::new(NESTING_BUDGET);820 let budget = budget::Value::new(NESTING_BUDGET);
665821
666 dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys, &budget))822 dispatch_tx::<T, _>(collection_id, |d| {
823 d.delete_token_properties(sender, token_id, property_keys, &budget)
824 })
667 }825 }
668826
669 /// Add or change token property permissions of a collection.827 /// Add or change token property permissions of a collection.
681 /// * `collection_id`: ID of the modified collection.839 /// * `collection_id`: ID of the modified collection.
682 /// * `property_permissions`: Vector of permissions for property keys.840 /// * `property_permissions`: Vector of permissions for property keys.
683 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.841 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.
684 #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]842 #[pallet::call_index(17)]
843 #[pallet::weight(T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32))]
685 pub fn set_token_property_permissions(844 pub fn set_token_property_permissions(
686 origin,845 origin: OriginFor<T>,
687 collection_id: CollectionId,846 collection_id: CollectionId,
688 property_permissions: Vec<PropertyKeyPermission>,847 property_permissions: Vec<PropertyKeyPermission>,
689 ) -> DispatchResultWithPostInfo {848 ) -> DispatchResultWithPostInfo {
690 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);849 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);
691850
692 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);851 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
693852
694 dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))853 dispatch_tx::<T, _>(collection_id, |d| {
854 d.set_token_property_permissions(&sender, property_permissions)
855 })
695 }856 }
696857
697 /// Create multiple items within a collection with explicitly specified initial parameters.858 /// Create multiple items within a collection with explicitly specified initial parameters.
709 ///870 ///
710 /// * `collection_id`: ID of the collection to which the tokens would belong.871 /// * `collection_id`: ID of the collection to which the tokens would belong.
711 /// * `data`: Explicit item creation data.872 /// * `data`: Explicit item creation data.
712 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]873 #[pallet::call_index(18)]
874 #[pallet::weight(T::CommonWeightInfo::create_multiple_items_ex(&data))]
713 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {875 pub fn create_multiple_items_ex(
876 origin: OriginFor<T>,
877 collection_id: CollectionId,
878 data: CreateItemExData<T::CrossAccountId>,
879 ) -> DispatchResultWithPostInfo {
714 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);880 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
715 let budget = budget::Value::new(NESTING_BUDGET);881 let budget = budget::Value::new(NESTING_BUDGET);
716882
717 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))883 dispatch_tx::<T, _>(collection_id, |d| {
884 d.create_multiple_items_ex(sender, data, &budget)
885 })
718 }886 }
719887
720 /// Completely allow or disallow transfers for a particular collection.888 /// Completely allow or disallow transfers for a particular collection.
727 ///895 ///
728 /// * `collection_id`: ID of the collection.896 /// * `collection_id`: ID of the collection.
729 /// * `value`: New value of the flag, are transfers allowed?897 /// * `value`: New value of the flag, are transfers allowed?
730 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]898 #[pallet::call_index(19)]
899 #[pallet::weight(<SelfWeightOf<T>>::set_transfers_enabled_flag())]
731 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {900 pub fn set_transfers_enabled_flag(
901 origin: OriginFor<T>,
902 collection_id: CollectionId,
903 value: bool,
904 ) -> DispatchResult {
732 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);905 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
733 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;906 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
734 target_collection.check_is_internal()?;907 target_collection.check_is_internal()?;
756 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.929 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.
757 /// * Fungible Mode: The desired number of pieces to burn.930 /// * Fungible Mode: The desired number of pieces to burn.
758 /// * Re-Fungible Mode: The desired number of pieces to burn.931 /// * Re-Fungible Mode: The desired number of pieces to burn.
759 #[weight = T::CommonWeightInfo::burn_item()]932 #[pallet::call_index(20)]
933 #[pallet::weight(T::CommonWeightInfo::burn_item())]
760 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {934 pub fn burn_item(
935 origin: OriginFor<T>,
936 collection_id: CollectionId,
937 item_id: TokenId,
938 value: u128,
939 ) -> DispatchResultWithPostInfo {
761 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);940 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
762941
763 let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;942 let post_info =
943 dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;
764 if value == 1 {944 if value == 1 {
765 <NftTransferBasket<T>>::remove(collection_id, item_id);945 <NftTransferBasket<T>>::remove(collection_id, item_id);
766 <NftApproveBasket<T>>::remove(collection_id, item_id);946 <NftApproveBasket<T>>::remove(collection_id, item_id);
794 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.974 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.
795 /// * Fungible Mode: The desired number of pieces to burn.975 /// * Fungible Mode: The desired number of pieces to burn.
796 /// * Re-Fungible Mode: The desired number of pieces to burn.976 /// * Re-Fungible Mode: The desired number of pieces to burn.
797 #[weight = T::CommonWeightInfo::burn_from()]977 #[pallet::call_index(21)]
978 #[pallet::weight(T::CommonWeightInfo::burn_from())]
798 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {979 pub fn burn_from(
980 origin: OriginFor<T>,
981 collection_id: CollectionId,
982 from: T::CrossAccountId,
983 item_id: TokenId,
984 value: u128,
985 ) -> DispatchResultWithPostInfo {
799 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);986 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
800 let budget = budget::Value::new(NESTING_BUDGET);987 let budget = budget::Value::new(NESTING_BUDGET);
801988
802 dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))989 dispatch_tx::<T, _>(collection_id, |d| {
990 d.burn_from(sender, from, item_id, value, &budget)
991 })
803 }992 }
804993
805 /// Change ownership of the token.994 /// Change ownership of the token.
823 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.1012 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.
824 /// * Fungible Mode: The desired number of pieces to transfer.1013 /// * Fungible Mode: The desired number of pieces to transfer.
825 /// * Re-Fungible Mode: The desired number of pieces to transfer.1014 /// * Re-Fungible Mode: The desired number of pieces to transfer.
826 #[weight = T::CommonWeightInfo::transfer()]1015 #[pallet::call_index(22)]
1016 #[pallet::weight(T::CommonWeightInfo::transfer())]
827 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {1017 pub fn transfer(
1018 origin: OriginFor<T>,
1019 recipient: T::CrossAccountId,
1020 collection_id: CollectionId,
1021 item_id: TokenId,
1022 value: u128,
1023 ) -> DispatchResultWithPostInfo {
828 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1024 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
829 let budget = budget::Value::new(NESTING_BUDGET);1025 let budget = budget::Value::new(NESTING_BUDGET);
8301026
831 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))1027 dispatch_tx::<T, _>(collection_id, |d| {
1028 d.transfer(sender, recipient, item_id, value, &budget)
1029 })
832 }1030 }
8331031
834 /// Allow a non-permissioned address to transfer or burn an item.1032 /// Allow a non-permissioned address to transfer or burn an item.
846 /// * `item_id`: ID of the item transactions on which are now approved.1044 /// * `item_id`: ID of the item transactions on which are now approved.
847 /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).1045 /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).
848 /// Set to 0 to revoke the approval.1046 /// Set to 0 to revoke the approval.
849 #[weight = T::CommonWeightInfo::approve()]1047 #[pallet::call_index(23)]
1048 #[pallet::weight(T::CommonWeightInfo::approve())]
850 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {1049 pub fn approve(
1050 origin: OriginFor<T>,
1051 spender: T::CrossAccountId,
1052 collection_id: CollectionId,
1053 item_id: TokenId,
1054 amount: u128,
1055 ) -> DispatchResultWithPostInfo {
851 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1056 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
8521057
853 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))1058 dispatch_tx::<T, _>(collection_id, |d| {
1059 d.approve(sender, spender, item_id, amount)
1060 })
854 }1061 }
8551062
856 /// Allow a non-permissioned address to transfer or burn an item from owner's eth mirror.1063 /// Allow a non-permissioned address to transfer or burn an item from owner's eth mirror.
869 /// * `item_id`: ID of the item transactions on which are now approved.1076 /// * `item_id`: ID of the item transactions on which are now approved.
870 /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).1077 /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).
871 /// Set to 0 to revoke the approval.1078 /// Set to 0 to revoke the approval.
872 #[weight = T::CommonWeightInfo::approve_from()]1079 #[pallet::call_index(24)]
1080 #[pallet::weight(T::CommonWeightInfo::approve_from())]
873 pub fn approve_from(origin, from:T::CrossAccountId, to: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {1081 pub fn approve_from(
1082 origin: OriginFor<T>,
1083 from: T::CrossAccountId,
1084 to: T::CrossAccountId,
1085 collection_id: CollectionId,
1086 item_id: TokenId,
1087 amount: u128,
1088 ) -> DispatchResultWithPostInfo {
874 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1089 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
8751090
876 dispatch_tx::<T, _>(collection_id, |d| d.approve_from(sender, from, to, item_id, amount))1091 dispatch_tx::<T, _>(collection_id, |d| {
1092 d.approve_from(sender, from, to, item_id, amount)
1093 })
877 }1094 }
8781095
879 /// Change ownership of an item on behalf of the owner as a non-owner account.1096 /// Change ownership of an item on behalf of the owner as a non-owner account.
900 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.1117 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.
901 /// * Fungible Mode: The desired number of pieces to transfer.1118 /// * Fungible Mode: The desired number of pieces to transfer.
902 /// * Re-Fungible Mode: The desired number of pieces to transfer.1119 /// * Re-Fungible Mode: The desired number of pieces to transfer.
903 #[weight = T::CommonWeightInfo::transfer_from()]1120 #[pallet::call_index(25)]
1121 #[pallet::weight(T::CommonWeightInfo::transfer_from())]
904 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {1122 pub fn transfer_from(
1123 origin: OriginFor<T>,
1124 from: T::CrossAccountId,
1125 recipient: T::CrossAccountId,
1126 collection_id: CollectionId,
1127 item_id: TokenId,
1128 value: u128,
1129 ) -> DispatchResultWithPostInfo {
905 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1130 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
906 let budget = budget::Value::new(NESTING_BUDGET);1131 let budget = budget::Value::new(NESTING_BUDGET);
9071132
908 dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))1133 dispatch_tx::<T, _>(collection_id, |d| {
1134 d.transfer_from(sender, from, recipient, item_id, value, &budget)
1135 })
909 }1136 }
9101137
911 /// Set specific limits of a collection. Empty, or None fields mean chain default.1138 /// Set specific limits of a collection. Empty, or None fields mean chain default.
920 /// * `collection_id`: ID of the modified collection.1147 /// * `collection_id`: ID of the modified collection.
921 /// * `new_limit`: New limits of the collection. Fields that are not set (None)1148 /// * `new_limit`: New limits of the collection. Fields that are not set (None)
922 /// will not overwrite the old ones.1149 /// will not overwrite the old ones.
923 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1150 #[pallet::call_index(26)]
1151 #[pallet::weight(<SelfWeightOf<T>>::set_collection_limits())]
924 pub fn set_collection_limits(1152 pub fn set_collection_limits(
925 origin,1153 origin: OriginFor<T>,
926 collection_id: CollectionId,1154 collection_id: CollectionId,
927 new_limit: CollectionLimits,1155 new_limit: CollectionLimits,
928 ) -> DispatchResult {1156 ) -> DispatchResult {
943 /// * `collection_id`: ID of the modified collection.1171 /// * `collection_id`: ID of the modified collection.
944 /// * `new_permission`: New permissions of the collection. Fields that are not set (None)1172 /// * `new_permission`: New permissions of the collection. Fields that are not set (None)
945 /// will not overwrite the old ones.1173 /// will not overwrite the old ones.
946 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1174 #[pallet::call_index(27)]
1175 #[pallet::weight(<SelfWeightOf<T>>::set_collection_limits())]
947 pub fn set_collection_permissions(1176 pub fn set_collection_permissions(
948 origin,1177 origin: OriginFor<T>,
949 collection_id: CollectionId,1178 collection_id: CollectionId,
950 new_permission: CollectionPermissions,1179 new_permission: CollectionPermissions,
951 ) -> DispatchResult {1180 ) -> DispatchResult {
952 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1181 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
953 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1182 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
954 <PalletCommon<T>>::update_permissions(1183 <PalletCommon<T>>::update_permissions(&sender, &mut target_collection, new_permission)
955 &sender,
956 &mut target_collection,
957 new_permission
958 )
959 }1184 }
9601185
961 /// Re-partition a refungible token, while owning all of its parts/pieces.1186 /// Re-partition a refungible token, while owning all of its parts/pieces.
969 /// * `collection_id`: ID of the collection the RFT belongs to.1194 /// * `collection_id`: ID of the collection the RFT belongs to.
970 /// * `token_id`: ID of the RFT.1195 /// * `token_id`: ID of the RFT.
971 /// * `amount`: New number of parts/pieces into which the token shall be partitioned.1196 /// * `amount`: New number of parts/pieces into which the token shall be partitioned.
972 #[weight = T::RefungibleExtensionsWeightInfo::repartition()]1197 #[pallet::call_index(28)]
1198 #[pallet::weight(T::RefungibleExtensionsWeightInfo::repartition())]
973 pub fn repartition(1199 pub fn repartition(
974 origin,1200 origin: OriginFor<T>,
975 collection_id: CollectionId,1201 collection_id: CollectionId,
976 token_id: TokenId,1202 token_id: TokenId,
977 amount: u128,1203 amount: u128,
995 /// * `owner`: Token owner1221 /// * `owner`: Token owner
996 /// * `operator`: Operator1222 /// * `operator`: Operator
997 /// * `approve`: Should operator status be granted or revoked?1223 /// * `approve`: Should operator status be granted or revoked?
998 #[weight = T::CommonWeightInfo::set_allowance_for_all()]1224 #[pallet::call_index(29)]
1225 #[pallet::weight(T::CommonWeightInfo::set_allowance_for_all())]
999 pub fn set_allowance_for_all(1226 pub fn set_allowance_for_all(
1000 origin,1227 origin: OriginFor<T>,
1001 collection_id: CollectionId,1228 collection_id: CollectionId,
1002 operator: T::CrossAccountId,1229 operator: T::CrossAccountId,
1003 approve: bool,1230 approve: bool,
1013 /// # Arguments1240 /// # Arguments
1014 ///1241 ///
1015 /// * `collection_id`: ID of the collection to repair.1242 /// * `collection_id`: ID of the collection to repair.
1016 #[weight = <SelfWeightOf<T>>::force_repair_collection()]1243 #[pallet::call_index(30)]
1244 #[pallet::weight(<SelfWeightOf<T>>::force_repair_collection())]
1017 pub fn force_repair_collection(1245 pub fn force_repair_collection(
1018 origin,1246 origin: OriginFor<T>,
1019 collection_id: CollectionId,1247 collection_id: CollectionId,
1020 ) -> DispatchResult {1248 ) -> DispatchResult {
1021 ensure_root(origin)?;1249 ensure_root(origin)?;
1028 ///1256 ///
1029 /// * `collection_id`: ID of the collection the item belongs to.1257 /// * `collection_id`: ID of the collection the item belongs to.
1030 /// * `item_id`: ID of the item.1258 /// * `item_id`: ID of the item.
1031 #[weight = T::CommonWeightInfo::force_repair_item()]1259 #[pallet::call_index(31)]
1260 #[pallet::weight(T::CommonWeightInfo::force_repair_item())]
1032 pub fn force_repair_item(1261 pub fn force_repair_item(
1033 origin,1262 origin: OriginFor<T>,
1034 collection_id: CollectionId,1263 collection_id: CollectionId,
1035 item_id: TokenId,1264 item_id: TokenId,
1036 ) -> DispatchResultWithPostInfo {1265 ) -> DispatchResultWithPostInfo {
1037 ensure_root(origin)?;1266 ensure_root(origin)?;
1038 dispatch_tx::<T, _>(collection_id, |d| {1267 dispatch_tx::<T, _>(collection_id, |d| d.repair_item(item_id))
1039 d.repair_item(item_id)
1040 })
1041 }1268 }
1042 }1269 }
1043}
10441270
1045impl<T: Config> Pallet<T> {1271 impl<T: Config> Pallet<T> {
1046 /// Force set `sponsor` for `collection`.1272 /// Force set `sponsor` for `collection`.
1047 ///1273 ///
1048 /// Differs from [`set_collection_sponsor`][`Pallet::set_collection_sponsor`] in that confirmation1274 /// Differs from [`set_collection_sponsor`][`Pallet::set_collection_sponsor`] in that confirmation
1049 /// from the `sponsor` is not required.1275 /// from the `sponsor` is not required.
1050 ///1276 ///
1051 /// # Arguments1277 /// # Arguments
1052 ///1278 ///
1053 /// * `sponsor`: ID of the account of the sponsor-to-be.1279 /// * `sponsor`: ID of the account of the sponsor-to-be.
1054 /// * `collection_id`: ID of the modified collection.1280 /// * `collection_id`: ID of the modified collection.
1055 pub fn force_set_sponsor(sponsor: T::AccountId, collection_id: CollectionId) -> DispatchResult {1281 pub fn force_set_sponsor(
1282 sponsor: T::AccountId,
1283 collection_id: CollectionId,
1284 ) -> DispatchResult {
1056 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1285 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
1057 target_collection.force_set_sponsor(sponsor.clone())1286 target_collection.force_set_sponsor(sponsor.clone())
1058 }1287 }
10591288
1060 /// Force remove `sponsor` for `collection`.1289 /// Force remove `sponsor` for `collection`.
1061 ///1290 ///
1062 /// Differs from `remove_sponsor` in that1291 /// Differs from `remove_sponsor` in that
1063 /// it doesn't require consent from the `owner` of the collection.1292 /// it doesn't require consent from the `owner` of the collection.
1064 ///1293 ///
1065 /// # Arguments1294 /// # Arguments
1066 ///1295 ///
1067 /// * `collection_id`: ID of the modified collection.1296 /// * `collection_id`: ID of the modified collection.
1068 pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {1297 pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {
1069 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1298 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
1070 target_collection.force_remove_sponsor()1299 target_collection.force_remove_sponsor()
1071 }1300 }
10721301
1073 #[inline(always)]1302 #[inline(always)]
1074 pub(crate) fn destroy_collection_internal(1303 pub(crate) fn destroy_collection_internal(
1075 sender: T::CrossAccountId,1304 sender: T::CrossAccountId,
1076 collection_id: CollectionId,1305 collection_id: CollectionId,
1077 ) -> DispatchResult {1306 ) -> DispatchResult {
1078 let collection = <CollectionHandle<T>>::try_get(collection_id)?;1307 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
1079 collection.check_is_internal()?;1308 collection.check_is_internal()?;
10801309
1081 T::CollectionDispatch::destroy(sender, collection)?;1310 T::CollectionDispatch::destroy(sender, collection)?;
10821311
1083 // TODO: basket cleanup should be moved elsewhere1312 // TODO: basket cleanup should be moved elsewhere
1084 // Maybe runtime dispatch.rs should perform it?1313 // Maybe runtime dispatch.rs should perform it?
10851314
1086 let _ = <NftTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1315 let _ = <NftTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
1087 let _ = <FungibleTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1316 let _ = <FungibleTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
1088 let _ = <ReFungibleTransferBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);1317 let _ = <ReFungibleTransferBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);
10891318
1090 let _ = <NftApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1319 let _ = <NftApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
1091 let _ = <FungibleApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1320 let _ = <FungibleApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);
1092 let _ = <RefungibleApproveBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);1321 let _ = <RefungibleApproveBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);
10931322
1094 Ok(())1323 Ok(())
1324 }
1095 }1325 }
1096}1326}
10971327
modifiedruntime/common/sponsoring.rsdiffbeforeafterboth
--- a/runtime/common/sponsoring.rs
+++ b/runtime/common/sponsoring.rs
@@ -18,7 +18,6 @@
 use up_sponsorship::SponsorshipHandler;
 use frame_support::{
 	traits::{IsSubType},
-	storage::{StorageMap, StorageDoubleMap, StorageNMap},
 };
 use up_data_structs::{
 	CollectionId, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, NFT_SPONSOR_TRANSFER_TIMEOUT,