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

difftreelog

refactor move ChainLimits to runtime config

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

6 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
202 nft_item_id: vec![],202 nft_item_id: vec![],
203 fungible_item_id: vec![],203 fungible_item_id: vec![],
204 refungible_item_id: vec![],204 refungible_item_id: vec![],
205 chain_limit: ChainLimits {
206 collection_numbers_limit: 100000,
207 account_token_ownership_limit: 1000000,
208 collections_admins_limit: 5,
209 custom_data_limit: 2048,
210 nft_sponsor_transfer_timeout: 15,
211 fungible_sponsor_transfer_timeout: 15,
212 refungible_sponsor_transfer_timeout: 15,
213 offchain_schema_limit: 1024,
214 variable_on_chain_schema_limit: 1024,
215 const_on_chain_schema_limit: 1024,
216 },
217 },205 },
218 parachain_info: nft_runtime::ParachainInfoConfig { parachain_id: id },206 parachain_info: nft_runtime::ParachainInfoConfig { parachain_id: id },
219 aura: nft_runtime::AuraConfig {207 aura: nft_runtime::AuraConfig {
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
1//! Implements EVM sponsoring logic via OnChargeEVMTransaction1//! Implements EVM sponsoring logic via OnChargeEVMTransaction
22
3use crate::{3use crate::{
4 ChainLimit, Collection, CollectionById, Config, FungibleTransferBasket, NftTransferBasket,4 Collection, CollectionById, Config, FungibleTransferBasket, NftTransferBasket,
5 eth::{account::EvmBackwardsAddressMapping, map_eth_to_id},5 eth::{account::EvmBackwardsAddressMapping, map_eth_to_id}, limit,
6};6};
7use evm_coder::{Call, abi::AbiReader};7use evm_coder::{Call, abi::AbiReader};
8use frame_support::{8use frame_support::{
9 storage::{StorageMap, StorageDoubleMap, StorageValue},9 storage::{StorageMap, StorageDoubleMap},
10 traits::Get,
10};11};
11use sp_core::H160;12use sp_core::H160;
12use sp_std::prelude::*;13use sp_std::prelude::*;
43 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {44 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
44 collection_limits.sponsor_transfer_timeout45 collection_limits.sponsor_transfer_timeout
45 } else {46 } else {
46 ChainLimit::get().nft_sponsor_transfer_timeout47 <limit!(T, NftSponsorTransferTimeout)>::get()
47 };48 };
4849
49 let mut sponsor = true;50 let mut sponsor = true;
74 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {75 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
75 collection_limits.sponsor_transfer_timeout76 collection_limits.sponsor_transfer_timeout
76 } else {77 } else {
77 ChainLimit::get().fungible_sponsor_transfer_timeout78 <limit!(T, FungibleSponsorTransferTimeout)>::get()
78 };79 };
7980
80 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
31 StorageValue, transactional,31 StorageValue, transactional,
32};32};
3333
34use frame_system::{self as system, ensure_signed, ensure_root};34use frame_system::{self as system, ensure_signed};
35use sp_core::H160;35use sp_core::H160;
36use sp_std::vec;36use sp_std::vec;
37use sp_runtime::sp_std::prelude::Vec;37use sp_runtime::sp_std::prelude::Vec;
243 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,243 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,
244 >;244 >;
245 type TreasuryAccountId: Get<Self::AccountId>;245 type TreasuryAccountId: Get<Self::AccountId>;
246 type ChainLimits: ChainLimits;
246}247}
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}
247256
248// # Used definitions257// # Used definitions
249//258//
280 ItemListIndex: map hasher(blake2_128_concat) CollectionId => TokenId;289 ItemListIndex: map hasher(blake2_128_concat) CollectionId => TokenId;
281 //#endregion290 //#endregion
282
283 //#region Chain limits struct
284 pub ChainLimit get(fn chain_limit) config(): ChainLimits;
285 //#endregion
286291
287 //#region Bound counters292 //#region Bound counters
288 /// Amount of collections destroyed, used for total amount tracking with293 /// Amount of collections destroyed, used for total amount tracking with
486 _ => 0491 _ => 0
487 };492 };
488
489 let chain_limit = ChainLimit::get();
490493
491 let created_count = CreatedCollectionCount::get();494 let created_count = CreatedCollectionCount::get();
492 let destroyed_count = DestroyedCollectionCount::get();495 let destroyed_count = DestroyedCollectionCount::get();
493496
494 // bound Total number of collections497 // bound Total number of collections
495 ensure!(created_count - destroyed_count < chain_limit.collection_numbers_limit, Error::<T>::TotalCollectionsLimitExceeded);498 ensure!(created_count - destroyed_count < <limit!(T, CollectionNumberLimit)>::get(), Error::<T>::TotalCollectionsLimitExceeded);
496499
497 // check params500 // check params
498 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);501 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);
508 CreatedCollectionCount::put(next_id);511 CreatedCollectionCount::put(next_id);
509512
510 let limits = CollectionLimits {513 let limits = CollectionLimits {
511 sponsored_data_size: chain_limit.custom_data_limit,514 sponsored_data_size: <limit!(T, CustomDataLimit)>::get(),
512 ..Default::default()515 ..Default::default()
513 };516 };
514517
737 match admin_arr.binary_search(&new_admin_id) {740 match admin_arr.binary_search(&new_admin_id) {
738 Ok(_) => {},741 Ok(_) => {},
739 Err(idx) => {742 Err(idx) => {
740 let limits = ChainLimit::get();
741 ensure!(admin_arr.len() < limits.collections_admins_limit as usize, Error::<T>::CollectionAdminsLimitExceeded);743 ensure!(admin_arr.len() < <limit!(T, CollectionAdminsLimit)>::get() as usize, Error::<T>::CollectionAdminsLimitExceeded);
742 admin_arr.insert(idx, new_admin_id);744 admin_arr.insert(idx, new_admin_id);
743 <AdminList<T>>::insert(collection_id, admin_arr);745 <AdminList<T>>::insert(collection_id, admin_arr);
744 }746 }
862864
863 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]865 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]
864 #[transactional]866 #[transactional]
865 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {867 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData<ChainLimitsOf<T>>) -> DispatchResult {
866 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);868 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
867 let collection = Self::get_collection(collection_id)?;869 let collection = Self::get_collection(collection_id)?;
868870
893 .map(|data| { data.data_size() })895 .map(|data| { data.data_size() })
894 .sum())]896 .sum())]
895 #[transactional]897 #[transactional]
896 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {898 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData<ChainLimitsOf<T>>>) -> DispatchResult {
897899
898 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);900 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);
899 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);901 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1138 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1140 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
11391141
1140 // check schema limit1142 // check schema limit
1141 ensure!(schema.len() as u32 <= ChainLimit::get().offchain_schema_limit, "");1143 ensure!(schema.len() as u32 <= <limit!(T, OffchainSchemaLimit)>::get(), "");
11421144
1143 target_collection.offchain_schema = schema;1145 target_collection.offchain_schema = schema;
1144 target_collection.save()1146 target_collection.save()
1168 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1170 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
11691171
1170 // check schema limit1172 // check schema limit
1171 ensure!(schema.len() as u32 <= ChainLimit::get().const_on_chain_schema_limit, "");1173 ensure!(schema.len() as u32 <= <limit!(T, ConstOnChainSchemaLimit)>::get(), "");
11721174
1173 target_collection.const_on_chain_schema = schema;1175 target_collection.const_on_chain_schema = schema;
1174 target_collection.save()1176 target_collection.save()
1198 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;1200 Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
11991201
1200 // check schema limit1202 // check schema limit
1201 ensure!(schema.len() as u32 <= ChainLimit::get().variable_on_chain_schema_limit, "");1203 ensure!(schema.len() as u32 <= <limit!(T, VariableOnChainSchemaLimit)>::get(), "");
12021204
1203 target_collection.variable_on_chain_schema = schema;1205 target_collection.variable_on_chain_schema = schema;
1204 target_collection.save()1206 target_collection.save()
1205 }1207 }
1206
1207 // Sudo permissions function
1208 #[weight = <T as Config>::WeightInfo::set_chain_limits()]
1209 #[transactional]
1210 pub fn set_chain_limits(
1211 origin,
1212 limits: ChainLimits
1213 ) -> DispatchResult {
1214
1215 #[cfg(not(feature = "runtime-benchmarks"))]
1216 ensure_root(origin)?;
1217
1218 <ChainLimit>::put(limits);
1219 Ok(())
1220 }
12211208
1222 #[weight = <T as Config>::WeightInfo::set_collection_limits()]1209 #[weight = <T as Config>::WeightInfo::set_collection_limits()]
1223 #[transactional]1210 #[transactional]
1230 let mut target_collection = Self::get_collection(collection_id)?;1217 let mut target_collection = Self::get_collection(collection_id)?;
1231 Self::check_owner_permissions(&target_collection, sender.as_sub())?;1218 Self::check_owner_permissions(&target_collection, sender.as_sub())?;
1232 let old_limits = &target_collection.limits;1219 let old_limits = &target_collection.limits;
1233 let chain_limits = ChainLimit::get();
12341220
1235 // collection bounds1221 // collection bounds
1236 ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&1222 ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&
1237 new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP &&1223 new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP &&
1238 new_limits.sponsored_data_size <= chain_limits.custom_data_limit,1224 new_limits.sponsored_data_size <= <ChainLimitsOf<T> as ChainLimits>::CustomDataLimit::get(),
1239 Error::<T>::CollectionLimitBoundsExceeded);1225 Error::<T>::CollectionLimitBoundsExceeded);
12401226
1241 // token_limit check prev1227 // token_limit check prev
1260 sender: &T::CrossAccountId,1246 sender: &T::CrossAccountId,
1261 collection: &CollectionHandle<T>,1247 collection: &CollectionHandle<T>,
1262 owner: &T::CrossAccountId,1248 owner: &T::CrossAccountId,
1263 data: CreateItemData,1249 data: CreateItemData<ChainLimitsOf<T>>,
1264 ) -> DispatchResult {1250 ) -> DispatchResult {
1265 Self::can_create_items_in_collection(collection, sender, owner, 1)?;1251 Self::can_create_items_in_collection(collection, sender, owner, 1)?;
1266 Self::validate_create_item_args(collection, &data)?;1252 Self::validate_create_item_args(collection, &data)?;
1471 Self::token_exists(collection, item_id)?;1457 Self::token_exists(collection, item_id)?;
14721458
1473 ensure!(1459 ensure!(
1474 ChainLimit::get().custom_data_limit >= data.len() as u32,1460 <limit!(T, CustomDataLimit)>::get() >= data.len() as u32,
1475 Error::<T>::TokenVariableDataLimitExceeded1461 Error::<T>::TokenVariableDataLimitExceeded
1476 );1462 );
14771463
1498 sender: &T::CrossAccountId,1484 sender: &T::CrossAccountId,
1499 collection: &CollectionHandle<T>,1485 collection: &CollectionHandle<T>,
1500 owner: &T::CrossAccountId,1486 owner: &T::CrossAccountId,
1501 items_data: Vec<CreateItemData>,1487 items_data: Vec<CreateItemData<ChainLimitsOf<T>>>,
1502 ) -> DispatchResult {1488 ) -> DispatchResult {
1503 Self::can_create_items_in_collection(collection, sender, owner, items_data.len() as u32)?;1489 Self::can_create_items_in_collection(collection, sender, owner, items_data.len() as u32)?;
15041490
16121598
1613 fn validate_create_item_args(1599 fn validate_create_item_args(
1614 target_collection: &CollectionHandle<T>,1600 target_collection: &CollectionHandle<T>,
1615 data: &CreateItemData,1601 data: &CreateItemData<ChainLimitsOf<T>>,
1616 ) -> DispatchResult {1602 ) -> DispatchResult {
1617 match target_collection.mode {1603 match target_collection.mode {
1618 CollectionMode::NFT => {1604 CollectionMode::NFT => {
1619 if let CreateItemData::NFT(data) = data {1605 if let CreateItemData::NFT(data) = data {
1620 // check sizes1606 // check sizes
1621 ensure!(1607 ensure!(
1622 ChainLimit::get().custom_data_limit >= data.const_data.len() as u32,1608 <limit!(T, CustomDataLimit)>::get() >= data.const_data.len() as u32,
1623 Error::<T>::TokenConstDataLimitExceeded1609 Error::<T>::TokenConstDataLimitExceeded
1624 );1610 );
1625 ensure!(1611 ensure!(
1626 ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32,1612 <limit!(T, CustomDataLimit)>::get() >= data.variable_data.len() as u32,
1627 Error::<T>::TokenVariableDataLimitExceeded1613 Error::<T>::TokenVariableDataLimitExceeded
1628 );1614 );
1629 } else {1615 } else {
1640 if let CreateItemData::ReFungible(data) = data {1626 if let CreateItemData::ReFungible(data) = data {
1641 // check sizes1627 // check sizes
1642 ensure!(1628 ensure!(
1643 ChainLimit::get().custom_data_limit >= data.const_data.len() as u32,1629 <limit!(T, CustomDataLimit)>::get() >= data.const_data.len() as u32,
1644 Error::<T>::TokenConstDataLimitExceeded1630 Error::<T>::TokenConstDataLimitExceeded
1645 );1631 );
1646 ensure!(1632 ensure!(
1647 ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32,1633 <limit!(T, CustomDataLimit)>::get() >= data.variable_data.len() as u32,
1648 Error::<T>::TokenVariableDataLimitExceeded1634 Error::<T>::TokenVariableDataLimitExceeded
1649 );1635 );
16501636
1669 fn create_item_no_validation(1655 fn create_item_no_validation(
1670 collection: &CollectionHandle<T>,1656 collection: &CollectionHandle<T>,
1671 owner: &T::CrossAccountId,1657 owner: &T::CrossAccountId,
1672 data: CreateItemData,1658 data: CreateItemData<ChainLimitsOf<T>>,
1673 ) -> DispatchResult {1659 ) -> DispatchResult {
1674 match data {1660 match data {
1675 CreateItemData::NFT(data) => {1661 CreateItemData::NFT(data) => {
2292 // bound Owned tokens by a single address2278 // bound Owned tokens by a single address
2293 let count = <AccountItemCount<T>>::get(owner.as_sub());2279 let count = <AccountItemCount<T>>::get(owner.as_sub());
2294 ensure!(2280 ensure!(
2295 count < ChainLimit::get().account_token_ownership_limit,2281 count < <limit!(T, AccountTokenOwnershipLimit)>::get(),
2296 Error::<T>::AddressOwnershipLimitExceeded2282 Error::<T>::AddressOwnershipLimitExceeded
2297 );2283 );
22982284
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, ChainLimit,3 ReFungibleTransferBasket, FungibleTransferBasket, NftTransferBasket,
4 CreateItemData, CollectionMode,4 CreateItemData, CollectionMode, limit,
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,9 traits::{IsSubType, Get},
10 storage::{StorageMap, StorageDoubleMap, StorageValue},10 storage::{StorageMap, StorageDoubleMap},
11};11};
12use nft_data_structs::{TokenId, CollectionId};12use nft_data_structs::{TokenId, CollectionId};
1313
16 pub fn withdraw_create_item(16 pub fn withdraw_create_item(
17 who: &T::AccountId,17 who: &T::AccountId,
18 collection_id: &CollectionId,18 collection_id: &CollectionId,
19 _properties: &CreateItemData,19 _properties: &CreateItemData<T::ChainLimits>,
20 ) -> Option<T::AccountId> {20 ) -> Option<T::AccountId> {
21 let collection = CollectionById::<T>::get(collection_id)?;21 let collection = CollectionById::<T>::get(collection_id)?;
2222
47 item_id: &TokenId,47 item_id: &TokenId,
48 ) -> Option<T::AccountId> {48 ) -> Option<T::AccountId> {
49 let collection = CollectionById::<T>::get(collection_id)?;49 let collection = CollectionById::<T>::get(collection_id)?;
50 let limits = ChainLimit::get();
5150
52 let mut sponsor_transfer = false;51 let mut sponsor_transfer = false;
53 if collection.sponsorship.confirmed() {52 if collection.sponsorship.confirmed() {
62 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {61 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
63 collection_limits.sponsor_transfer_timeout62 collection_limits.sponsor_transfer_timeout
64 } else {63 } else {
65 limits.nft_sponsor_transfer_timeout64 <limit!(T, NftSponsorTransferTimeout)>::get()
66 };65 };
6766
68 let mut sponsored = true;67 let mut sponsored = true;
84 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {83 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
85 collection_limits.sponsor_transfer_timeout84 collection_limits.sponsor_transfer_timeout
86 } else {85 } else {
87 limits.fungible_sponsor_transfer_timeout86 <limit!(T, FungibleSponsorTransferTimeout)>::get()
88 };87 };
8988
90 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;89 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
107 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {106 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
108 collection_limits.sponsor_transfer_timeout107 collection_limits.sponsor_transfer_timeout
109 } else {108 } else {
110 limits.refungible_sponsor_transfer_timeout109 <limit!(T, ReFungibleSponsorTransferTimeout)>::get()
111 };110 };
112111
113 let mut sponsored = true;112 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
31// TODO: Somehow use ChainLimits for BoundedVec len calculation?
32// Do we need ChainLimits anyway, if we can change them via forkless upgrades?
33parameter_types! {
34pub const MaxDataSize: u32 = 2048;
35// TODO: This limit isn't checked for substrate create_multiple_items call
36pub const MaxItemsPerBatch: u32 = 200;
37}
3830
39pub type CollectionId = u32;31pub type CollectionId = u32;
40pub type TokenId = u32;32pub type TokenId = u32;
211 }203 }
212}204}
213205
214#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
215#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
216pub struct ChainLimits {206pub trait ChainLimits {
217 pub collection_numbers_limit: u32,207 type CollectionNumberLimit: Get<u32>;
218 pub account_token_ownership_limit: u32,208 type AccountTokenOwnershipLimit: Get<u32>;
219 pub collections_admins_limit: u64,209 type CollectionAdminsLimit: Get<u64>;
220 pub custom_data_limit: u32,210 type CustomDataLimit: Get<u32>;
221211
222 // Timeouts for item types in passed blocks212 // Timeouts for item types in passed blocks
223 pub nft_sponsor_transfer_timeout: u32,213 type NftSponsorTransferTimeout: Get<u32>;
224 pub fungible_sponsor_transfer_timeout: u32,214 type FungibleSponsorTransferTimeout: Get<u32>;
225 pub refungible_sponsor_transfer_timeout: u32,215 type ReFungibleSponsorTransferTimeout: Get<u32>;
226216
227 // Schema limits217 // Schema limits
228 pub offchain_schema_limit: u32,218 type OffchainSchemaLimit: Get<u32>;
229 pub variable_on_chain_schema_limit: u32,219 type VariableOnChainSchemaLimit: Get<u32>;
230 pub const_on_chain_schema_limit: 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>;
231}225}
232226
233/// BoundedVec doesn't supports serde227/// BoundedVec doesn't supports serde
263 }257 }
264}258}
265259
266#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative, Clone, PartialEq)]260#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative)]
267#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]261#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
268#[derivative(Debug)]262#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]
269pub struct CreateNftData {263pub struct CreateNftData<T: ChainLimits> {
270 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]264 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
271 #[derivative(Debug = "ignore")]265 #[derivative(Debug = "ignore")]
272 pub const_data: BoundedVec<u8, MaxDataSize>,266 pub const_data: BoundedVec<u8, T::CustomDataLimit>,
273 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]267 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
274 #[derivative(Debug = "ignore")]268 #[derivative(Debug = "ignore")]
275 pub variable_data: BoundedVec<u8, MaxDataSize>,269 pub variable_data: BoundedVec<u8, T::CustomDataLimit>,
276}270}
277271
278#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq)]272#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq)]
281 pub value: u128,275 pub value: u128,
282}276}
283277
284#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative, Clone, PartialEq)]278#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative)]
285#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]279#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
286#[derivative(Debug)]280#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]
287pub struct CreateReFungibleData {281pub struct CreateReFungibleData<T: ChainLimits> {
288 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]282 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
289 #[derivative(Debug = "ignore")]283 #[derivative(Debug = "ignore")]
290 pub const_data: BoundedVec<u8, MaxDataSize>,284 pub const_data: BoundedVec<u8, T::CustomDataLimit>,
291 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]285 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
292 #[derivative(Debug = "ignore")]286 #[derivative(Debug = "ignore")]
293 pub variable_data: BoundedVec<u8, MaxDataSize>,287 pub variable_data: BoundedVec<u8, T::CustomDataLimit>,
294 pub pieces: u128,288 pub pieces: u128,
295}289}
296290
297#[derive(Encode, Decode, MaxEncodedLen, Debug, Clone, PartialEq)]291#[derive(Encode, Decode, MaxEncodedLen, Derivative)]
298#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]292#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
293#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]
299pub enum CreateItemData {294pub enum CreateItemData<T: ChainLimits> {
300 NFT(CreateNftData),295 NFT(CreateNftData<T>),
301 Fungible(CreateFungibleData),296 Fungible(CreateFungibleData),
302 ReFungible(CreateReFungibleData),297 ReFungible(CreateReFungibleData<T>),
303}298}
304299
305impl CreateItemData {300impl<T: ChainLimits> CreateItemData<T> {
306 pub fn data_size(&self) -> usize {301 pub fn data_size(&self) -> usize {
307 match self {302 match self {
308 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),303 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),
312 }307 }
313}308}
314309
315impl From<CreateNftData> for CreateItemData {310impl<T: ChainLimits> From<CreateNftData<T>> for CreateItemData<T> {
316 fn from(item: CreateNftData) -> Self {311 fn from(item: CreateNftData<T>) -> Self {
317 CreateItemData::NFT(item)312 CreateItemData::NFT(item)
318 }313 }
319}314}
320315
321impl From<CreateReFungibleData> for CreateItemData {316impl<T: ChainLimits> From<CreateReFungibleData<T>> for CreateItemData<T> {
322 fn from(item: CreateReFungibleData) -> Self {317 fn from(item: CreateReFungibleData<T>) -> Self {
323 CreateItemData::ReFungible(item)318 CreateItemData::ReFungible(item)
324 }319 }
325}320}
326321
327impl From<CreateFungibleData> for CreateItemData {322impl<T: ChainLimits> From<CreateFungibleData> for CreateItemData<T> {
328 fn from(item: CreateFungibleData) -> Self {323 fn from(item: CreateFungibleData) -> Self {
329 CreateItemData::Fungible(item)324 CreateItemData::Fungible(item)
330 }325 }
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}
684713
685parameter_types! {714parameter_types! {
686 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();715 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();
699 type Currency = Balances;728 type Currency = Balances;
700 type CollectionCreationPrice = CollectionCreationPrice;729 type CollectionCreationPrice = CollectionCreationPrice;
701 type TreasuryAccountId = TreasuryAccountId;730 type TreasuryAccountId = TreasuryAccountId;
731 type ChainLimits = ChainLimits;
702}732}
703733
704parameter_types! {734parameter_types! {