difftreelog
refactor move sponsoring rate limit to collection limits
in: master
1 file changed
pallets/nft/src/lib.rsdiffbeforeafterboth123 pub fraction: u128,123 pub fraction: u128,124}124}125125126#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]126#[derive(Encode, Decode, Clone, PartialEq)]127#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]127#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]128pub struct CollectionType<AccountId> {128pub struct CollectionType<T: Config> {129 pub owner: AccountId,129 pub owner: T::AccountId,130 pub mode: CollectionMode,130 pub mode: CollectionMode,131 pub access: AccessMode,131 pub access: AccessMode,132 pub decimal_points: DecimalPoints,132 pub decimal_points: DecimalPoints,136 pub mint_mode: bool,136 pub mint_mode: bool,137 pub offchain_schema: Vec<u8>,137 pub offchain_schema: Vec<u8>,138 pub schema_version: SchemaVersion,138 pub schema_version: SchemaVersion,139 pub sponsor: AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender139 pub sponsor: T::AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender140 pub sponsor_confirmed: bool, // False if sponsor address has not yet confirmed sponsorship. True otherwise.140 pub sponsor_confirmed: bool, // False if sponsor address has not yet confirmed sponsorship. True otherwise.141 pub limits: CollectionLimits, // Collection private restrictions 141 pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions 142 pub variable_on_chain_schema: Vec<u8>, //142 pub variable_on_chain_schema: Vec<u8>, //143 pub const_on_chain_schema: Vec<u8>, //143 pub const_on_chain_schema: Vec<u8>, //144}144}178178179#[derive(Encode, Decode, Debug, Clone, PartialEq)]179#[derive(Encode, Decode, Debug, Clone, PartialEq)]180#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]180#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]181pub struct CollectionLimits {181pub struct CollectionLimits<BlockNumber: Encode + Decode> {182 pub account_token_ownership_limit: u32,182 pub account_token_ownership_limit: u32,183 pub sponsored_data_size: u32,183 pub sponsored_data_size: u32,184 /// None - setVariableMetadata is not sponsored185 /// Some(v) - setVariableMetadata is sponsored 186 /// if there is v block between txs187 pub sponsored_data_rate_limit: Option<BlockNumber>,184 pub token_limit: u32,188 pub token_limit: u32,185189186 // Timeouts for item types in passed blocks190 // Timeouts for item types in passed blocks189 pub owner_can_destroy: bool,193 pub owner_can_destroy: bool,190}194}191195192impl Default for CollectionLimits {196impl<BlockNumber: Encode + Decode> Default for CollectionLimits<BlockNumber> {193 fn default() -> CollectionLimits {197 fn default() -> Self {194 CollectionLimits { 198 Self { 195 account_token_ownership_limit: 10_000_000, 199 account_token_ownership_limit: 10_000_000, 196 token_limit: u32::max_value(),200 token_limit: u32::max_value(),197 sponsored_data_size: u32::max_value(), 201 sponsored_data_size: u32::max_value(), 202 sponsored_data_rate_limit: None,198 sponsor_transfer_timeout: 14400,203 sponsor_transfer_timeout: 14400,199 owner_can_transfer: true,204 owner_can_transfer: true,200 owner_can_destroy: true205 owner_can_destroy: true419 pub AccountItemCount get(fn account_item_count): map hasher(twox_64_concat) T::AccountId => u32;424 pub AccountItemCount get(fn account_item_count): map hasher(twox_64_concat) T::AccountId => u32;420425421 // Basic collections426 // Basic collections422 pub Collection get(fn collection) config(): map hasher(identity) CollectionId => CollectionType<T::AccountId>;427 pub Collection get(fn collection) config(): map hasher(identity) CollectionId => Option<CollectionType<T>> = None;423 pub AdminList get(fn admin_list_collection): map hasher(identity) CollectionId => Vec<T::AccountId>;428 pub AdminList get(fn admin_list_collection): map hasher(identity) CollectionId => Vec<T::AccountId>;424 pub WhiteList get(fn white_list): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => bool;429 pub WhiteList get(fn white_list): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => bool;425430445450446 /// Variable metadata sponsoring451 /// Variable metadata sponsoring447 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => Option<T::BlockNumber> = None;452 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => Option<T::BlockNumber> = None;448 pub VariableMetaDataSponsoringRateLimit get(fn variable_meta_data_sponsoring_rate_limit): map hasher(identity) CollectionId => T::BlockNumber = 0.into();449453450 // Contract Sponsorship and Ownership454 // Contract Sponsorship and Ownership451 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;455 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;646 <ReFungibleTransferBasket<T>>::remove_prefix(collection_id);650 <ReFungibleTransferBasket<T>>::remove_prefix(collection_id);647651648 <VariableMetaDataBasket<T>>::remove_prefix(collection_id);652 <VariableMetaDataBasket<T>>::remove_prefix(collection_id);649 <VariableMetaDataSponsoringRateLimit<T>>::remove(collection_id);650653651 if CollectionCount::get() > 0654 if CollectionCount::get() > 0652 {655 {724 let sender = ensure_signed(origin)?;727 let sender = ensure_signed(origin)?;725728726 Self::check_owner_permissions(collection_id, sender)?;729 Self::check_owner_permissions(collection_id, sender)?;727 let mut target_collection = <Collection<T>>::get(collection_id);730 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();728 target_collection.access = mode;731 target_collection.access = mode;729 <Collection<T>>::insert(collection_id, target_collection);732 <Collection<T>>::insert(collection_id, target_collection);730733750 let sender = ensure_signed(origin)?;753 let sender = ensure_signed(origin)?;751754752 Self::check_owner_permissions(collection_id, sender)?;755 Self::check_owner_permissions(collection_id, sender)?;753 let mut target_collection = <Collection<T>>::get(collection_id);756 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();754 target_collection.mint_mode = mint_permission;757 target_collection.mint_mode = mint_permission;755 <Collection<T>>::insert(collection_id, target_collection);758 <Collection<T>>::insert(collection_id, target_collection);756759773776774 let sender = ensure_signed(origin)?;777 let sender = ensure_signed(origin)?;775 Self::check_owner_permissions(collection_id, sender)?;778 Self::check_owner_permissions(collection_id, sender)?;776 let mut target_collection = <Collection<T>>::get(collection_id);779 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();777 target_collection.owner = new_owner;780 target_collection.owner = new_owner;778 <Collection<T>>::insert(collection_id, target_collection);781 <Collection<T>>::insert(collection_id, target_collection);779782854 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {857 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {855858856 let sender = ensure_signed(origin)?;859 let sender = ensure_signed(origin)?;857 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);858860859 let mut target_collection = <Collection<T>>::get(collection_id);861 let mut target_collection = <Collection<T>>::get(collection_id).ok_or(Error::<T>::CollectionNotFound)?;860 ensure!(sender == target_collection.owner, Error::<T>::NoPermission);862 ensure!(sender == target_collection.owner, Error::<T>::NoPermission);861863862 target_collection.sponsor = new_sponsor;864 target_collection.sponsor = new_sponsor;877 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {879 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {878880879 let sender = ensure_signed(origin)?;881 let sender = ensure_signed(origin)?;880 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);881882882 let mut target_collection = <Collection<T>>::get(collection_id);883 let mut target_collection = <Collection<T>>::get(collection_id).ok_or(Error::<T>::CollectionNotFound)?;883 ensure!(sender == target_collection.sponsor, Error::<T>::ConfirmUnsetSponsorFail);884 ensure!(sender == target_collection.sponsor, Error::<T>::ConfirmUnsetSponsorFail);884885885 target_collection.sponsor_confirmed = true;886 target_collection.sponsor_confirmed = true;901 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {902 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {902903903 let sender = ensure_signed(origin)?;904 let sender = ensure_signed(origin)?;904 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);905905906 let mut target_collection = <Collection<T>>::get(collection_id);906 let mut target_collection = <Collection<T>>::get(collection_id).ok_or(Error::<T>::CollectionNotFound)?;907 ensure!(sender == target_collection.owner, Error::<T>::NoPermission);907 ensure!(sender == target_collection.owner, Error::<T>::NoPermission);908908909 target_collection.sponsor = T::AccountId::default();909 target_collection.sponsor = T::AccountId::default();944944945 Self::collection_exists(collection_id)?;945 Self::collection_exists(collection_id)?;946946947 let target_collection = <Collection<T>>::get(collection_id);947 let target_collection = <Collection<T>>::get(collection_id).unwrap();948948949 Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;949 Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;950 Self::validate_create_item_args(&target_collection, &data)?;950 Self::validate_create_item_args(&target_collection, &data)?;980 let sender = ensure_signed(origin)?;980 let sender = ensure_signed(origin)?;981981982 Self::collection_exists(collection_id)?;982 Self::collection_exists(collection_id)?;983 let target_collection = <Collection<T>>::get(collection_id);983 let target_collection = <Collection<T>>::get(collection_id).unwrap();984984985 Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;985 Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;9869861014 Self::collection_exists(collection_id)?;1014 Self::collection_exists(collection_id)?;101510151016 // Transfer permissions check1016 // Transfer permissions check1017 let target_collection = <Collection<T>>::get(collection_id);1017 let target_collection = <Collection<T>>::get(collection_id).unwrap();1018 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1018 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1019 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1019 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1020 Error::<T>::NoPermission);1020 Error::<T>::NoPermission);1090 Self::token_exists(collection_id, item_id, &sender)?;1090 Self::token_exists(collection_id, item_id, &sender)?;109110911092 // Transfer permissions check1092 // Transfer permissions check1093 let target_collection = <Collection<T>>::get(collection_id);1093 let target_collection = <Collection<T>>::get(collection_id).unwrap();1094 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1094 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1095 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1095 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1096 Error::<T>::NoPermission);1096 Error::<T>::NoPermission);1143 appoved_transfer = true;1143 appoved_transfer = true;1144 }1144 }114511451146 let target_collection = <Collection<T>>::get(collection_id);1146 let target_collection = <Collection<T>>::get(collection_id).unwrap();114711471148 // Limits check1148 // Limits check1149 Self::is_correct_transfer(collection_id, &target_collection, &recipient)?;1149 Self::is_correct_transfer(collection_id, &target_collection, &recipient)?;1218 ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);1218 ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);121912191220 // Modify permissions check1220 // Modify permissions check1221 let target_collection = <Collection<T>>::get(collection_id);1221 let target_collection = <Collection<T>>::get(collection_id).unwrap();1222 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1222 ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||1223 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1223 Self::is_owner_or_admin_permissions(collection_id, sender.clone()),1224 Error::<T>::NoPermission);1224 Error::<T>::NoPermission);1256 ) -> DispatchResult {1256 ) -> DispatchResult {1257 let sender = ensure_signed(origin)?;1257 let sender = ensure_signed(origin)?;1258 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;1258 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;1259 let mut target_collection = <Collection<T>>::get(collection_id);1259 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();1260 target_collection.schema_version = version;1260 target_collection.schema_version = version;1261 <Collection<T>>::insert(collection_id, target_collection);1261 <Collection<T>>::insert(collection_id, target_collection);126212621287 // check schema limit1287 // check schema limit1288 ensure!(schema.len() as u32 <= ChainLimit::get().offchain_schema_limit, "");1288 ensure!(schema.len() as u32 <= ChainLimit::get().offchain_schema_limit, "");128912891290 let mut target_collection = <Collection<T>>::get(collection_id);1290 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();1291 target_collection.offchain_schema = schema;1291 target_collection.offchain_schema = schema;1292 <Collection<T>>::insert(collection_id, target_collection);1292 <Collection<T>>::insert(collection_id, target_collection);129312931318 // check schema limit1318 // check schema limit1319 ensure!(schema.len() as u32 <= ChainLimit::get().const_on_chain_schema_limit, "");1319 ensure!(schema.len() as u32 <= ChainLimit::get().const_on_chain_schema_limit, "");132013201321 let mut target_collection = <Collection<T>>::get(collection_id);1321 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();1322 target_collection.const_on_chain_schema = schema;1322 target_collection.const_on_chain_schema = schema;1323 <Collection<T>>::insert(collection_id, target_collection);1323 <Collection<T>>::insert(collection_id, target_collection);132413241349 // check schema limit1349 // check schema limit1350 ensure!(schema.len() as u32 <= ChainLimit::get().variable_on_chain_schema_limit, "");1350 ensure!(schema.len() as u32 <= ChainLimit::get().variable_on_chain_schema_limit, "");135113511352 let mut target_collection = <Collection<T>>::get(collection_id);1352 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();1353 target_collection.variable_on_chain_schema = schema;1353 target_collection.variable_on_chain_schema = schema;1354 <Collection<T>>::insert(collection_id, target_collection);1354 <Collection<T>>::insert(collection_id, target_collection);135513551432 Ok(())1432 Ok(())1433 }1433 }143414341435 #[weight = <T as Config>::WeightInfo::set_variable_meta_data_sponsoring_rate_limit()]1436 pub fn set_variable_meta_data_sponsoring_rate_limit(1437 origin,1438 collection_id: CollectionId,1439 rate_limit: T::BlockNumber1440 ) -> DispatchResult {1441 let sender = ensure_signed(origin)?;1442 Self::check_collection_sponsor(collection_id.clone(), sender.clone())?;14431444 <VariableMetaDataSponsoringRateLimit<T>>::insert(collection_id, rate_limit);1445 Ok(())1446 }14471448 /// Enable the white list for a contract. Only addresses added to the white list with addToContractWhiteList will be able to call this smart contract.1435 /// Enable the white list for a contract. Only addresses added to the white list with addToContractWhiteList will be able to call this smart contract.1449 /// 1436 /// 1450 /// # Permissions1437 /// # Permissions1530 pub fn set_collection_limits(1517 pub fn set_collection_limits(1531 origin,1518 origin,1532 collection_id: u32,1519 collection_id: u32,1533 limits: CollectionLimits,1520 limits: CollectionLimits<T::BlockNumber>,1534 ) -> DispatchResult {1521 ) -> DispatchResult {1535 let sender = ensure_signed(origin)?;1522 let sender = ensure_signed(origin)?;1536 Self::check_owner_permissions(collection_id, sender.clone())?;1523 Self::check_owner_permissions(collection_id, sender.clone())?;1537 let mut target_collection = <Collection<T>>::get(collection_id);1524 let mut target_collection = <Collection<T>>::get(collection_id).unwrap();1538 let chain_limits = ChainLimit::get();1525 let chain_limits = ChainLimit::get();1539 let climits = target_collection.limits;1526 let climits = target_collection.limits;15401527156015471561 pub fn transfer_internal(sender: T::AccountId, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {1548 pub fn transfer_internal(sender: T::AccountId, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {156215491563 let target_collection = <Collection<T>>::get(collection_id);1550 let target_collection = <Collection<T>>::get(collection_id).unwrap();156415511565 // Limits check1552 // Limits check1566 Self::is_correct_transfer(collection_id, &target_collection, &recipient)?;1553 Self::is_correct_transfer(collection_id, &target_collection, &recipient)?;1587 }1574 }15881575158915761590 fn is_correct_transfer(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, recipient: &T::AccountId) -> DispatchResult {1577 fn is_correct_transfer(collection_id: CollectionId, collection: &CollectionType<T>, recipient: &T::AccountId) -> DispatchResult {159115781592 // check token limit and account token limit1579 // check token limit and account token limit1593 let account_items: u32 = <AddressTokens<T>>::get(collection_id, recipient).len() as u32;1580 let account_items: u32 = <AddressTokens<T>>::get(collection_id, recipient).len() as u32;1596 Ok(())1583 Ok(())1597 }1584 }159815851599 fn can_create_items_in_collection(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {1586 fn can_create_items_in_collection(collection_id: CollectionId, collection: &CollectionType<T>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {160015871601 // check token limit and account token limit1588 // check token limit and account token limit1602 let total_items: u32 = ItemListIndex::get(collection_id);1589 let total_items: u32 = ItemListIndex::get(collection_id);1613 Ok(())1600 Ok(())1614 }1601 }161516021616 fn validate_create_item_args(target_collection: &CollectionType<T::AccountId>, data: &CreateItemData) -> DispatchResult {1603 fn validate_create_item_args(target_collection: &CollectionType<T>, data: &CreateItemData) -> DispatchResult {1617 match target_collection.mode1604 match target_collection.mode1618 {1605 {1619 CollectionMode::NFT => {1606 CollectionMode::NFT => {1852 fn check_owner_permissions(collection_id: CollectionId, subject: T::AccountId) -> DispatchResult {1839 fn check_owner_permissions(collection_id: CollectionId, subject: T::AccountId) -> DispatchResult {1853 Self::collection_exists(collection_id)?;1840 Self::collection_exists(collection_id)?;185418411855 let target_collection = <Collection<T>>::get(collection_id);1842 let target_collection = <Collection<T>>::get(collection_id).unwrap();1856 ensure!(1843 ensure!(1857 subject == target_collection.owner,1844 subject == target_collection.owner,1858 Error::<T>::NoPermission1845 Error::<T>::NoPermission1862 }1849 }186318501864 fn is_owner_or_admin_permissions(collection_id: CollectionId, subject: T::AccountId) -> bool {1851 fn is_owner_or_admin_permissions(collection_id: CollectionId, subject: T::AccountId) -> bool {1865 let target_collection = <Collection<T>>::get(collection_id);1852 let target_collection = <Collection<T>>::get(collection_id).unwrap();1866 let mut result: bool = subject == target_collection.owner;1853 let mut result: bool = subject == target_collection.owner;1867 let exists = <AdminList<T>>::contains_key(collection_id);1854 let exists = <AdminList<T>>::contains_key(collection_id);186818551894 subject: T::AccountId,1881 subject: T::AccountId,1895 ) -> DispatchResult {1882 ) -> DispatchResult {1896 Self::collection_exists(collection_id)?;1883 Self::collection_exists(collection_id)?;1897 let collection = <Collection<T>>::get(collection_id);1884 let collection = <Collection<T>>::get(collection_id).unwrap();1898 1885 1899 ensure!(1886 ensure!(1900 collection.sponsor_confirmed &&1887 collection.sponsor_confirmed &&1905 }1892 }190618931907 fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {1894 fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {1908 let target_collection = <Collection<T>>::get(collection_id);1895 let target_collection = <Collection<T>>::get(collection_id).unwrap();190918961910 match target_collection.mode {1897 match target_collection.mode {1911 CollectionMode::NFT => {1898 CollectionMode::NFT => {1938 item_id: TokenId,1925 item_id: TokenId,1939 owner: &T::AccountId1926 owner: &T::AccountId1940 ) -> DispatchResult {1927 ) -> DispatchResult {1941 let target_collection = <Collection<T>>::get(collection_id);1928 let target_collection = <Collection<T>>::get(collection_id).unwrap();1942 let exists = match target_collection.mode1929 let exists = match target_collection.mode1943 {1930 {1944 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),1931 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),2127 Ok(())2114 Ok(())2128 }2115 }212921162130 fn init_collection(item: &CollectionType<T::AccountId>) {2117 fn init_collection(item: &CollectionType<T>) {2131 // check params2118 // check params2132 assert!(2119 assert!(2133 item.decimal_points <= MAX_DECIMAL_POINTS,2120 item.decimal_points <= MAX_DECIMAL_POINTS,2384 // Parse call to extract collection ID and access collection sponsor2371 // Parse call to extract collection ID and access collection sponsor2385 let mut sponsor: T::AccountId = match IsSubType::<Call<T>>::is_sub_type(call) {2372 let mut sponsor: T::AccountId = match IsSubType::<Call<T>>::is_sub_type(call) {2386 Some(Call::create_item(collection_id, _owner, _properties)) => {2373 Some(Call::create_item(collection_id, _owner, _properties)) => {2374 let collection = <Collection<T>>::get(collection_id).unwrap();238723752388 // sponsor timeout2376 // sponsor timeout2389 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;2377 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;239023782391 let limit = <Collection<T>>::get(collection_id).limits.sponsor_transfer_timeout;2379 let limit = collection.limits.sponsor_transfer_timeout;2392 let mut sponsored = true;2380 let mut sponsored = true;2393 if <CreateItemBasket<T>>::contains_key((collection_id, &who)) {2381 if <CreateItemBasket<T>>::contains_key((collection_id, &who)) {2394 let last_tx_block = <CreateItemBasket<T>>::get((collection_id, &who));2382 let last_tx_block = <CreateItemBasket<T>>::get((collection_id, &who));2402 }2390 }240323912404 // check free create limit2392 // check free create limit2405 if (<Collection<T>>::get(collection_id).limits.sponsored_data_size >= (_properties.len() as u32)) &&2393 if (collection.limits.sponsored_data_size >= (_properties.len() as u32)) &&2406 (<Collection<T>>::get(collection_id).sponsor_confirmed) &&2394 (collection.sponsor_confirmed) &&2407 (sponsored)2395 (sponsored)2408 {2396 {2409 <Collection<T>>::get(collection_id).sponsor2397 collection.sponsor2410 } else {2398 } else {2411 T::AccountId::default()2399 T::AccountId::default()2412 }2400 }2413 }2401 }2414 Some(Call::transfer(_new_owner, collection_id, item_id, _value)) => {2402 Some(Call::transfer(_new_owner, collection_id, item_id, _value)) => {2403 let collection = <Collection<T>>::get(collection_id).unwrap();2415 2404 2416 let mut sponsor_transfer = false;2405 let mut sponsor_transfer = false;2417 if <Collection<T>>::get(collection_id).sponsor_confirmed {2406 if collection.sponsor_confirmed {241824072419 let collection_limits = <Collection<T>>::get(collection_id).limits;2408 let collection_limits = collection.limits;2420 let collection_mode = <Collection<T>>::get(collection_id).mode;2409 let collection_mode = collection.mode;2421 2410 2422 // sponsor timeout2411 // sponsor timeout2423 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;2412 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;2501 if !sponsor_transfer {2490 if !sponsor_transfer {2502 T::AccountId::default()2491 T::AccountId::default()2503 } else {2492 } else {2504 <Collection<T>>::get(collection_id).sponsor2493 collection.sponsor2505 }2494 }2506 }2495 }250724962508 Some(Call::set_variable_meta_data(collection_id, item_id, data)) => {2497 Some(Call::set_variable_meta_data(collection_id, item_id, data)) => {2509 let mut sponsor_metadata_changes = false;2498 let mut sponsor_metadata_changes = false;24992500 let collection = <Collection<T>>::get(collection_id).unwrap();251025012511 let collection = <Collection<T>>::get(collection_id);2512 if2502 if2513 collection.sponsor_confirmed &&2503 collection.sponsor_confirmed &&2514 // Can't sponsor fungible collection, this tx will be rejected2504 // Can't sponsor fungible collection, this tx will be rejected2515 // as invalid2505 // as invalid2516 !matches!(collection.mode, CollectionMode::Fungible(_)) &&2506 !matches!(collection.mode, CollectionMode::Fungible(_)) &&2517 data.len() <= collection.limits.sponsored_data_size as usize2507 data.len() <= collection.limits.sponsored_data_size as usize2518 {2508 {2519 let rate_limit = <VariableMetaDataSponsoringRateLimit<T>>::get(collection_id);2509 if let Some(rate_limit) = collection.limits.sponsored_data_rate_limit {2520 if rate_limit > 0.into() {2521 // sponsor timeout2522 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;2510 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;252325112524 if <VariableMetaDataBasket<T>>::get(collection_id, item_id)2512 if <VariableMetaDataBasket<T>>::get(collection_id, item_id)2525 .map(|last_block| block_number - last_block >= rate_limit)2513 .map(|last_block| block_number - last_block > rate_limit)2526 .unwrap_or(true) 2514 .unwrap_or(true) 2527 {2515 {2528 sponsor_metadata_changes = true;2516 sponsor_metadata_changes = true;2534 if !sponsor_metadata_changes {2522 if !sponsor_metadata_changes {2535 T::AccountId::default()2523 T::AccountId::default()2536 } else {2524 } else {2537 <Collection<T>>::get(collection_id).sponsor2525 collection.sponsor2538 }2526 }2539 }2527 }25402528