referrerpolicy=no-referrer-when-downgrade

pallet_uniques/
types.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Various basic types for use in the Uniques pallet.
19
20use super::*;
21use frame_support::{
22	pallet_prelude::{BoundedVec, MaxEncodedLen},
23	traits::Get,
24};
25use scale_info::TypeInfo;
26
27/// A type alias for handling balance deposits.
28pub type DepositBalanceOf<T, I = ()> =
29	<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
30/// A type alias representing the details of a collection.
31pub type CollectionDetailsFor<T, I> =
32	CollectionDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
33/// A type alias for the details of a single item.
34pub type ItemDetailsFor<T, I> = ItemDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
35/// A type alias to represent the price of an item.
36pub type ItemPrice<T, I = ()> =
37	<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
38
39#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
40pub struct CollectionDetails<AccountId, DepositBalance> {
41	/// Can change `owner`, `issuer`, `freezer` and `admin` accounts.
42	pub owner: AccountId,
43	/// Can mint tokens.
44	pub issuer: AccountId,
45	/// Can thaw tokens, force transfers and burn tokens from any account.
46	pub admin: AccountId,
47	/// Can freeze tokens.
48	pub freezer: AccountId,
49	/// The total balance deposited for the all storage associated with this collection.
50	/// Used by `destroy`.
51	pub total_deposit: DepositBalance,
52	/// If `true`, then no deposit is needed to hold items of this collection.
53	pub free_holding: bool,
54	/// The total number of outstanding items of this collection.
55	pub items: u32,
56	/// The total number of outstanding item metadata of this collection.
57	pub item_metadatas: u32,
58	/// The total number of attributes for this collection.
59	pub attributes: u32,
60	/// Whether the collection is frozen for non-admin transfers.
61	pub is_frozen: bool,
62}
63
64/// Witness data for the destroy transactions.
65#[derive(
66	Copy,
67	Clone,
68	Encode,
69	Decode,
70	DecodeWithMemTracking,
71	Eq,
72	PartialEq,
73	RuntimeDebug,
74	TypeInfo,
75	MaxEncodedLen,
76)]
77pub struct DestroyWitness {
78	/// The total number of outstanding items of this collection.
79	#[codec(compact)]
80	pub items: u32,
81	/// The total number of items in this collection that have outstanding item metadata.
82	#[codec(compact)]
83	pub item_metadatas: u32,
84	#[codec(compact)]
85	/// The total number of attributes for this collection.
86	pub attributes: u32,
87}
88
89impl<AccountId, DepositBalance> CollectionDetails<AccountId, DepositBalance> {
90	pub fn destroy_witness(&self) -> DestroyWitness {
91		DestroyWitness {
92			items: self.items,
93			item_metadatas: self.item_metadatas,
94			attributes: self.attributes,
95		}
96	}
97}
98
99/// Information concerning the ownership of a single unique item.
100#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
101pub struct ItemDetails<AccountId, DepositBalance> {
102	/// The owner of this item.
103	pub owner: AccountId,
104	/// The approved transferrer of this item, if one is set.
105	pub approved: Option<AccountId>,
106	/// Whether the item can be transferred or not.
107	pub is_frozen: bool,
108	/// The amount held in the pallet's default account for this item. Free-hold items will have
109	/// this as zero.
110	pub deposit: DepositBalance,
111}
112
113#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
114#[scale_info(skip_type_params(StringLimit))]
115#[codec(mel_bound(DepositBalance: MaxEncodedLen))]
116pub struct CollectionMetadata<DepositBalance, StringLimit: Get<u32>> {
117	/// The balance deposited for this metadata.
118	///
119	/// This pays for the data stored in this struct.
120	pub deposit: DepositBalance,
121	/// General information concerning this collection. Limited in length by `StringLimit`. This
122	/// will generally be either a JSON dump or the hash of some JSON which can be found on a
123	/// hash-addressable global publication system such as IPFS.
124	pub data: BoundedVec<u8, StringLimit>,
125	/// Whether the collection's metadata may be changed by a non Force origin.
126	pub is_frozen: bool,
127}
128
129#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
130#[scale_info(skip_type_params(StringLimit))]
131#[codec(mel_bound(DepositBalance: MaxEncodedLen))]
132pub struct ItemMetadata<DepositBalance, StringLimit: Get<u32>> {
133	/// The balance deposited for this metadata.
134	///
135	/// This pays for the data stored in this struct.
136	pub deposit: DepositBalance,
137	/// General information concerning this item. Limited in length by `StringLimit`. This will
138	/// generally be either a JSON dump or the hash of some JSON which can be found on a
139	/// hash-addressable global publication system such as IPFS.
140	pub data: BoundedVec<u8, StringLimit>,
141	/// Whether the item metadata may be changed by a non Force origin.
142	pub is_frozen: bool,
143}
144
145pub mod asset_strategies {
146	use super::*;
147	use frame_support::traits::tokens::asset_ops::common_strategies::{
148		Admin, ConfigValue, Owner, PredefinedId, WithConfig,
149	};
150
151	pub struct Attribute<'a>(pub &'a [u8]);
152
153	pub type CollectionManagers<AccountId> =
154		(ConfigValue<Owner<AccountId>>, ConfigValue<Admin<AccountId>>);
155
156	pub type WithCollectionConfig<T, I = ()> = WithConfig<
157		CollectionManagers<<T as frame_system::Config>::AccountId>,
158		PredefinedId<<T as Config<I>>::CollectionId>,
159	>;
160
161	pub type WithItemConfig<T, I = ()> = WithConfig<
162		ConfigValue<Owner<<T as frame_system::Config>::AccountId>>,
163		PredefinedId<(<T as Config<I>>::CollectionId, <T as Config<I>>::ItemId)>,
164	>;
165}