git.delta.rocks / unique-network / refs/commits / 7a034de544fd

difftreelog

refactor move ChainLimits to constants

Yaroslav Bolyukin2021-08-10parent: #fb1ebd6.patch.diff
in: master

5 files changed

modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
22
3use crate::{3use crate::{
4 Collection, CollectionById, Config, FungibleTransferBasket, NftTransferBasket,4 Collection, CollectionById, Config, FungibleTransferBasket, NftTransferBasket,
5 eth::{account::EvmBackwardsAddressMapping, map_eth_to_id}, limit,5 eth::{account::EvmBackwardsAddressMapping, map_eth_to_id},
6};6};
7use evm_coder::{Call, abi::AbiReader};7use evm_coder::{Call, abi::AbiReader};
8use frame_support::{8use frame_support::{
9 storage::{StorageMap, StorageDoubleMap},9 storage::{StorageMap, StorageDoubleMap},
10 traits::Get,
11};10};
12use sp_core::H160;11use sp_core::H160;
13use sp_std::prelude::*;12use sp_std::prelude::*;
18};17};
19use core::convert::TryInto;18use core::convert::TryInto;
20use core::marker::PhantomData;19use core::marker::PhantomData;
20use nft_data_structs::{NFT_SPONSOR_TRANSFER_TIMEOUT, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT};
2121
22struct AnyError;22struct AnyError;
2323
44 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {44 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
45 collection_limits.sponsor_transfer_timeout45 collection_limits.sponsor_transfer_timeout
46 } else {46 } else {
47 <limit!(T, NftSponsorTransferTimeout)>::get()47 NFT_SPONSOR_TRANSFER_TIMEOUT
48 };48 };
4949
50 let mut sponsor = true;50 let mut sponsor = true;
75 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {75 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
76 collection_limits.sponsor_transfer_timeout76 collection_limits.sponsor_transfer_timeout
77 } else {77 } else {
78 <limit!(T, FungibleSponsorTransferTimeout)>::get()78 FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT
79 };79 };
8080
81 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;81 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
38use core::ops::{Deref, DerefMut};38use core::ops::{Deref, DerefMut};
39use nft_data_structs::{39use nft_data_structs::{
40 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,40 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,
41 CUSTOM_DATA_LIMIT, COLLECTION_NUMBER_LIMIT, ACCOUNT_TOKEN_OWNERSHIP_LIMIT,
42 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, COLLECTION_ADMINS_LIMIT,
41 AccessMode, ChainLimits, Collection, CreateItemData, CollectionLimits, CollectionId,43 OFFCHAIN_SCHEMA_LIMIT, AccessMode, Collection, CreateItemData, CollectionLimits, CollectionId,
42 CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,44 CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,
43 FungibleItemType, ReFungibleItemType,45 FungibleItemType, ReFungibleItemType,
44};46};
243 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,245 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,
244 >;246 >;
245 type TreasuryAccountId: Get<Self::AccountId>;247 type TreasuryAccountId: Get<Self::AccountId>;
246 type ChainLimits: ChainLimits;
247}248}
248
249pub type ChainLimitsOf<T> = <T as Config>::ChainLimits;
250#[macro_export]
251macro_rules! limit {
252 ($config:ty, $limit:ident) => {
253 <$crate::ChainLimitsOf<$config> as nft_data_structs::ChainLimits>::$limit
254 }
255}
256249
257// # Used definitions250// # Used definitions
258//251//
495 let destroyed_count = DestroyedCollectionCount::get();488 let destroyed_count = DestroyedCollectionCount::get();
496489
497 // bound Total number of collections490 // bound Total number of collections
498 ensure!(created_count - destroyed_count < <limit!(T, CollectionNumberLimit)>::get(), Error::<T>::TotalCollectionsLimitExceeded);491 ensure!(created_count - destroyed_count < COLLECTION_NUMBER_LIMIT, Error::<T>::TotalCollectionsLimitExceeded);
499492
500 // check params493 // check params
501 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);494 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);
511 CreatedCollectionCount::put(next_id);504 CreatedCollectionCount::put(next_id);
512505
513 let limits = CollectionLimits {506 let limits = CollectionLimits {
514 sponsored_data_size: <limit!(T, CustomDataLimit)>::get(),507 sponsored_data_size: CUSTOM_DATA_LIMIT,
515 ..Default::default()508 ..Default::default()
516 };509 };
517510
740 match admin_arr.binary_search(&new_admin_id) {733 match admin_arr.binary_search(&new_admin_id) {
741 Ok(_) => {},734 Ok(_) => {},
742 Err(idx) => {735 Err(idx) => {
743 ensure!(admin_arr.len() < <limit!(T, CollectionAdminsLimit)>::get() as usize, Error::<T>::CollectionAdminsLimitExceeded);736 ensure!(admin_arr.len() < COLLECTION_ADMINS_LIMIT as usize, Error::<T>::CollectionAdminsLimitExceeded);
744 admin_arr.insert(idx, new_admin_id);737 admin_arr.insert(idx, new_admin_id);
745 <AdminList<T>>::insert(collection_id, admin_arr);738 <AdminList<T>>::insert(collection_id, admin_arr);
746 }739 }
864857
865 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]858 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]
866 #[transactional]859 #[transactional]
867 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData<ChainLimitsOf<T>>) -> DispatchResult {860 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {
868 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);861 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
869 let collection = Self::get_collection(collection_id)?;862 let collection = Self::get_collection(collection_id)?;
870863
895 .map(|data| { data.data_size() })888 .map(|data| { data.data_size() })
896 .sum())]889 .sum())]
897 #[transactional]890 #[transactional]
898 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData<ChainLimitsOf<T>>>) -> DispatchResult {891 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {
899892
900 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);893 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);
901 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);894 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1140 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1133 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
11411134
1142 // check schema limit1135 // check schema limit
1143 ensure!(schema.len() as u32 <= <limit!(T, OffchainSchemaLimit)>::get(), "");1136 ensure!(schema.len() as u32 <= OFFCHAIN_SCHEMA_LIMIT, "");
11441137
1145 target_collection.offchain_schema = schema;1138 target_collection.offchain_schema = schema;
1146 target_collection.save()1139 target_collection.save()
1170 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1163 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
11711164
1172 // check schema limit1165 // check schema limit
1173 ensure!(schema.len() as u32 <= <limit!(T, ConstOnChainSchemaLimit)>::get(), "");1166 ensure!(schema.len() as u32 <= CONST_ON_CHAIN_SCHEMA_LIMIT, "");
11741167
1175 target_collection.const_on_chain_schema = schema;1168 target_collection.const_on_chain_schema = schema;
1176 target_collection.save()1169 target_collection.save()
1200 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1193 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
12011194
1202 // check schema limit1195 // check schema limit
1203 ensure!(schema.len() as u32 <= <limit!(T, VariableOnChainSchemaLimit)>::get(), "");1196 ensure!(schema.len() as u32 <= VARIABLE_ON_CHAIN_SCHEMA_LIMIT, "");
12041197
1205 target_collection.variable_on_chain_schema = schema;1198 target_collection.variable_on_chain_schema = schema;
1206 target_collection.save()1199 target_collection.save()
1221 // collection bounds1214 // collection bounds
1222 ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&1215 ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&
1223 new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP &&1216 new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP &&
1224 new_limits.sponsored_data_size <= <ChainLimitsOf<T> as ChainLimits>::CustomDataLimit::get(),1217 new_limits.sponsored_data_size <= CUSTOM_DATA_LIMIT,
1225 Error::<T>::CollectionLimitBoundsExceeded);1218 Error::<T>::CollectionLimitBoundsExceeded);
12261219
1227 // token_limit check prev1220 // token_limit check prev
1246 sender: &T::CrossAccountId,1239 sender: &T::CrossAccountId,
1247 collection: &CollectionHandle<T>,1240 collection: &CollectionHandle<T>,
1248 owner: &T::CrossAccountId,1241 owner: &T::CrossAccountId,
1249 data: CreateItemData<ChainLimitsOf<T>>,1242 data: CreateItemData,
1250 ) -> DispatchResult {1243 ) -> DispatchResult {
1251 Self::can_create_items_in_collection(collection, sender, owner, 1)?;1244 Self::can_create_items_in_collection(collection, sender, owner, 1)?;
1252 Self::validate_create_item_args(collection, &data)?;1245 Self::validate_create_item_args(collection, &data)?;
1457 Self::token_exists(collection, item_id)?;1450 Self::token_exists(collection, item_id)?;
14581451
1459 ensure!(1452 ensure!(
1460 <limit!(T, CustomDataLimit)>::get() >= data.len() as u32,1453 CUSTOM_DATA_LIMIT >= data.len() as u32,
1461 Error::<T>::TokenVariableDataLimitExceeded1454 Error::<T>::TokenVariableDataLimitExceeded
1462 );1455 );
14631456
1484 sender: &T::CrossAccountId,1477 sender: &T::CrossAccountId,
1485 collection: &CollectionHandle<T>,1478 collection: &CollectionHandle<T>,
1486 owner: &T::CrossAccountId,1479 owner: &T::CrossAccountId,
1487 items_data: Vec<CreateItemData<ChainLimitsOf<T>>>,1480 items_data: Vec<CreateItemData>,
1488 ) -> DispatchResult {1481 ) -> DispatchResult {
1489 Self::can_create_items_in_collection(collection, sender, owner, items_data.len() as u32)?;1482 Self::can_create_items_in_collection(collection, sender, owner, items_data.len() as u32)?;
14901483
15981591
1599 fn validate_create_item_args(1592 fn validate_create_item_args(
1600 target_collection: &CollectionHandle<T>,1593 target_collection: &CollectionHandle<T>,
1601 data: &CreateItemData<ChainLimitsOf<T>>,1594 data: &CreateItemData,
1602 ) -> DispatchResult {1595 ) -> DispatchResult {
1603 match target_collection.mode {1596 match target_collection.mode {
1604 CollectionMode::NFT => {1597 CollectionMode::NFT => {
1605 if let CreateItemData::NFT(data) = data {1598 if let CreateItemData::NFT(data) = data {
1606 // check sizes1599 // check sizes
1607 ensure!(1600 ensure!(
1608 <limit!(T, CustomDataLimit)>::get() >= data.const_data.len() as u32,1601 CUSTOM_DATA_LIMIT >= data.const_data.len() as u32,
1609 Error::<T>::TokenConstDataLimitExceeded1602 Error::<T>::TokenConstDataLimitExceeded
1610 );1603 );
1611 ensure!(1604 ensure!(
1612 <limit!(T, CustomDataLimit)>::get() >= data.variable_data.len() as u32,1605 CUSTOM_DATA_LIMIT >= data.variable_data.len() as u32,
1613 Error::<T>::TokenVariableDataLimitExceeded1606 Error::<T>::TokenVariableDataLimitExceeded
1614 );1607 );
1615 } else {1608 } else {
1626 if let CreateItemData::ReFungible(data) = data {1619 if let CreateItemData::ReFungible(data) = data {
1627 // check sizes1620 // check sizes
1628 ensure!(1621 ensure!(
1629 <limit!(T, CustomDataLimit)>::get() >= data.const_data.len() as u32,1622 CUSTOM_DATA_LIMIT >= data.const_data.len() as u32,
1630 Error::<T>::TokenConstDataLimitExceeded1623 Error::<T>::TokenConstDataLimitExceeded
1631 );1624 );
1632 ensure!(1625 ensure!(
1633 <limit!(T, CustomDataLimit)>::get() >= data.variable_data.len() as u32,1626 CUSTOM_DATA_LIMIT >= data.variable_data.len() as u32,
1634 Error::<T>::TokenVariableDataLimitExceeded1627 Error::<T>::TokenVariableDataLimitExceeded
1635 );1628 );
16361629
1655 fn create_item_no_validation(1648 fn create_item_no_validation(
1656 collection: &CollectionHandle<T>,1649 collection: &CollectionHandle<T>,
1657 owner: &T::CrossAccountId,1650 owner: &T::CrossAccountId,
1658 data: CreateItemData<ChainLimitsOf<T>>,1651 data: CreateItemData,
1659 ) -> DispatchResult {1652 ) -> DispatchResult {
1660 match data {1653 match data {
1661 CreateItemData::NFT(data) => {1654 CreateItemData::NFT(data) => {
2278 // bound Owned tokens by a single address2271 // bound Owned tokens by a single address
2279 let count = <AccountItemCount<T>>::get(owner.as_sub());2272 let count = <AccountItemCount<T>>::get(owner.as_sub());
2280 ensure!(2273 ensure!(
2281 count < <limit!(T, AccountTokenOwnershipLimit)>::get(),2274 count < ACCOUNT_TOKEN_OWNERSHIP_LIMIT,
2282 Error::<T>::AddressOwnershipLimitExceeded2275 Error::<T>::AddressOwnershipLimitExceeded
2283 );2276 );
22842277
modifiedpallets/nft/src/sponsorship.rsdiffbeforeafterboth
1use crate::{1use crate::{
2 Config, Call, CollectionById, CreateItemBasket, VariableMetaDataBasket,2 Config, Call, CollectionById, CreateItemBasket, VariableMetaDataBasket,
3 ReFungibleTransferBasket, FungibleTransferBasket, NftTransferBasket,3 ReFungibleTransferBasket, FungibleTransferBasket, NftTransferBasket, CreateItemData,
4 CreateItemData, CollectionMode, limit,4 CollectionMode,
5};5};
6use core::marker::PhantomData;6use core::marker::PhantomData;
7use up_sponsorship::SponsorshipHandler;7use up_sponsorship::SponsorshipHandler;
8use frame_support::{8use frame_support::{
9 traits::{IsSubType, Get},9 traits::{IsSubType},
10 storage::{StorageMap, StorageDoubleMap},10 storage::{StorageMap, StorageDoubleMap},
11};11};
12use nft_data_structs::{TokenId, CollectionId};12use nft_data_structs::{
13 TokenId, CollectionId, NFT_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
14 FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
15};
1316
14pub struct NftSponsorshipHandler<T>(PhantomData<T>);17pub struct NftSponsorshipHandler<T>(PhantomData<T>);
15impl<T: Config> NftSponsorshipHandler<T> {18impl<T: Config> NftSponsorshipHandler<T> {
16 pub fn withdraw_create_item(19 pub fn withdraw_create_item(
17 who: &T::AccountId,20 who: &T::AccountId,
18 collection_id: &CollectionId,21 collection_id: &CollectionId,
19 _properties: &CreateItemData<T::ChainLimits>,22 _properties: &CreateItemData,
20 ) -> Option<T::AccountId> {23 ) -> Option<T::AccountId> {
21 let collection = CollectionById::<T>::get(collection_id)?;24 let collection = CollectionById::<T>::get(collection_id)?;
2225
61 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {64 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
62 collection_limits.sponsor_transfer_timeout65 collection_limits.sponsor_transfer_timeout
63 } else {66 } else {
64 <limit!(T, NftSponsorTransferTimeout)>::get()67 NFT_SPONSOR_TRANSFER_TIMEOUT
65 };68 };
6669
67 let mut sponsored = true;70 let mut sponsored = true;
83 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {86 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
84 collection_limits.sponsor_transfer_timeout87 collection_limits.sponsor_transfer_timeout
85 } else {88 } else {
86 <limit!(T, FungibleSponsorTransferTimeout)>::get()89 FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT
87 };90 };
8891
89 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;92 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
106 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {109 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
107 collection_limits.sponsor_transfer_timeout110 collection_limits.sponsor_transfer_timeout
108 } else {111 } else {
109 <limit!(T, ReFungibleSponsorTransferTimeout)>::get()112 REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT
110 };113 };
111114
112 let mut sponsored = true;115 let mut sponsored = true;
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
28pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;28pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
29pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;29pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
30
31pub const COLLECTION_NUMBER_LIMIT: u32 = 100000;
32pub const CUSTOM_DATA_LIMIT: u32 = 2048;
33pub const COLLECTION_ADMINS_LIMIT: u64 = 5;
34pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = 1000000;
35
36// Timeouts for item types in passed blocks
37pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;
38pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;
39pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;
40
41// Schema limits
42pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 1024;
43pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;
44pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;
45
46/// How much items can be created per single
47/// create_many call
48pub const MAX_ITEMS_PER_BATCH: u32 = 200;
49
50parameter_types! {
51 pub const CustomDataLimit: u32 = CUSTOM_DATA_LIMIT;
52}
3053
31pub type CollectionId = u32;54pub type CollectionId = u32;
32pub type TokenId = u32;55pub type TokenId = u32;
203 }226 }
204}227}
205
206pub trait ChainLimits {
207 type CollectionNumberLimit: Get<u32>;
208 type AccountTokenOwnershipLimit: Get<u32>;
209 type CollectionAdminsLimit: Get<u64>;
210 type CustomDataLimit: Get<u32>;
211
212 // Timeouts for item types in passed blocks
213 type NftSponsorTransferTimeout: Get<u32>;
214 type FungibleSponsorTransferTimeout: Get<u32>;
215 type ReFungibleSponsorTransferTimeout: Get<u32>;
216
217 // Schema limits
218 type OffchainSchemaLimit: Get<u32>;
219 type VariableOnChainSchemaLimit: Get<u32>;
220 type ConstOnChainSchemaLimit: Get<u32>;
221
222 /// How much items can be created per single
223 /// create_many call
224 type MaxItemsPerBatch: Get<u32>;
225}
226228
227/// BoundedVec doesn't supports serde229/// BoundedVec doesn't supports serde
228#[cfg(feature = "serde1")]230#[cfg(feature = "serde1")]
257 }259 }
258}260}
259261
260#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative)]262#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative)]
261#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]263#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
262#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]264#[derivative(Debug)]
263pub struct CreateNftData<T: ChainLimits> {265pub struct CreateNftData {
264 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]266 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
265 #[derivative(Debug = "ignore")]267 #[derivative(Debug = "ignore")]
266 pub const_data: BoundedVec<u8, T::CustomDataLimit>,268 pub const_data: BoundedVec<u8, CustomDataLimit>,
267 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]269 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
268 #[derivative(Debug = "ignore")]270 #[derivative(Debug = "ignore")]
269 pub variable_data: BoundedVec<u8, T::CustomDataLimit>,271 pub variable_data: BoundedVec<u8, CustomDataLimit>,
270}272}
271273
272#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq)]274#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq)]
275 pub value: u128,277 pub value: u128,
276}278}
277279
278#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative)]280#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative)]
279#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]281#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
280#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]282#[derivative(Debug)]
281pub struct CreateReFungibleData<T: ChainLimits> {283pub struct CreateReFungibleData {
282 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]284 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
283 #[derivative(Debug = "ignore")]285 #[derivative(Debug = "ignore")]
284 pub const_data: BoundedVec<u8, T::CustomDataLimit>,286 pub const_data: BoundedVec<u8, CustomDataLimit>,
285 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]287 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
286 #[derivative(Debug = "ignore")]288 #[derivative(Debug = "ignore")]
287 pub variable_data: BoundedVec<u8, T::CustomDataLimit>,289 pub variable_data: BoundedVec<u8, CustomDataLimit>,
288 pub pieces: u128,290 pub pieces: u128,
289}291}
290292
291#[derive(Encode, Decode, MaxEncodedLen, Derivative)]293#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug)]
292#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]294#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
293#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]
294pub enum CreateItemData<T: ChainLimits> {295pub enum CreateItemData {
295 NFT(CreateNftData<T>),296 NFT(CreateNftData),
296 Fungible(CreateFungibleData),297 Fungible(CreateFungibleData),
297 ReFungible(CreateReFungibleData<T>),298 ReFungible(CreateReFungibleData),
298}299}
299300
300impl<T: ChainLimits> CreateItemData<T> {301impl CreateItemData {
301 pub fn data_size(&self) -> usize {302 pub fn data_size(&self) -> usize {
302 match self {303 match self {
303 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),304 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),
307 }308 }
308}309}
309310
310impl<T: ChainLimits> From<CreateNftData<T>> for CreateItemData<T> {311impl From<CreateNftData> for CreateItemData {
311 fn from(item: CreateNftData<T>) -> Self {312 fn from(item: CreateNftData) -> Self {
312 CreateItemData::NFT(item)313 CreateItemData::NFT(item)
313 }314 }
314}315}
315316
316impl<T: ChainLimits> From<CreateReFungibleData<T>> for CreateItemData<T> {317impl From<CreateReFungibleData> for CreateItemData {
317 fn from(item: CreateReFungibleData<T>) -> Self {318 fn from(item: CreateReFungibleData) -> Self {
318 CreateItemData::ReFungible(item)319 CreateItemData::ReFungible(item)
319 }320 }
320}321}
321322
322impl<T: ChainLimits> From<CreateFungibleData> for CreateItemData<T> {323impl From<CreateFungibleData> for CreateItemData {
323 fn from(item: CreateFungibleData) -> Self {324 fn from(item: CreateFungibleData) -> Self {
324 CreateItemData::Fungible(item)325 CreateItemData::Fungible(item)
325 }326 }
modifiedruntime/src/lib.rsdiffbeforeafterboth
682 type AuthorityId = AuraId;682 type AuthorityId = AuraId;
683}683}
684
685parameter_types! {
686 pub const CollectionNumberLimit: u32 = 100000;
687 pub const AccountTokenOwnershipLimit: u32 = 1000000;
688 pub const CollectionAdminsLimit: u64 = 5;
689 pub const CustomDataLimit: u32 = 2048;
690 pub const NftSponsorTransferTimeout: u32 = 5;
691 pub const FungibleSponsorTransferTimeout: u32 = 5;
692 pub const ReFungibleSponsorTransferTimeout: u32 = 5;
693 pub const OffchainSchemaLimit: u32 = 1024;
694 pub const VariableOnChainSchemaLimit: u32 = 1024;
695 pub const ConstOnChainSchemaLimit: u32 = 1024;
696 pub const MaxItemsPerBatch: u32 = 200;
697}
698
699pub struct ChainLimits;
700impl nft_data_structs::ChainLimits for ChainLimits {
701 type CollectionNumberLimit = CollectionNumberLimit;
702 type AccountTokenOwnershipLimit = AccountTokenOwnershipLimit;
703 type CollectionAdminsLimit = CollectionAdminsLimit;
704 type CustomDataLimit = CustomDataLimit;
705 type NftSponsorTransferTimeout = NftSponsorTransferTimeout;
706 type FungibleSponsorTransferTimeout = FungibleSponsorTransferTimeout;
707 type ReFungibleSponsorTransferTimeout = ReFungibleSponsorTransferTimeout;
708 type OffchainSchemaLimit = OffchainSchemaLimit;
709 type VariableOnChainSchemaLimit = VariableOnChainSchemaLimit;
710 type ConstOnChainSchemaLimit = ConstOnChainSchemaLimit;
711 type MaxItemsPerBatch = MaxItemsPerBatch;
712}
713684
714parameter_types! {685parameter_types! {
715 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();686 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();
728 type Currency = Balances;699 type Currency = Balances;
729 type CollectionCreationPrice = CollectionCreationPrice;700 type CollectionCreationPrice = CollectionCreationPrice;
730 type TreasuryAccountId = TreasuryAccountId;701 type TreasuryAccountId = TreasuryAccountId;
731 type ChainLimits = ChainLimits;
732}702}
733703
734parameter_types! {704parameter_types! {