difftreelog
feat implement setVariableMetadata sponsoring
in: master
3 files changed
pallets/nft/src/default_weights.rsdiffbeforeafterboth127 .saturating_add(DbWeight::get().reads(0 as Weight))127 .saturating_add(DbWeight::get().reads(0 as Weight))128 .saturating_add(DbWeight::get().writes(2 as Weight))128 .saturating_add(DbWeight::get().writes(2 as Weight))129 } 129 } 130 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight {131 (3_500_000 as Weight)132 .saturating_add(DbWeight::get().reads(2 as Weight))133 .saturating_add(DbWeight::get().writes(1 as Weight))134 }130 fn toggle_contract_white_list() -> Weight {135 fn toggle_contract_white_list() -> Weight {131 (3_000_000 as Weight)136 (3_000_000 as Weight)132 .saturating_add(DbWeight::get().reads(0 as Weight))137 .saturating_add(DbWeight::get().reads(0 as Weight))pallets/nft/src/lib.rsdiffbeforeafterboth247 fn set_schema_version() -> Weight;247 fn set_schema_version() -> Weight;248 fn set_chain_limits() -> Weight;248 fn set_chain_limits() -> Weight;249 fn set_contract_sponsoring_rate_limit() -> Weight;249 fn set_contract_sponsoring_rate_limit() -> Weight;250 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight;250 fn toggle_contract_white_list() -> Weight;251 fn toggle_contract_white_list() -> Weight;251 fn add_to_contract_white_list() -> Weight;252 fn add_to_contract_white_list() -> Weight;252 fn remove_from_contract_white_list() -> Weight;253 fn remove_from_contract_white_list() -> Weight;442 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => T::BlockNumber;443 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => T::BlockNumber;443 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;444 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;445446 /// Variable metadata sponsoring447 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();444449445 // Contract Sponsorship and Ownership450 // Contract Sponsorship and Ownership446 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;451 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;640 <FungibleTransferBasket<T>>::remove_prefix(collection_id);645 <FungibleTransferBasket<T>>::remove_prefix(collection_id);641 <ReFungibleTransferBasket<T>>::remove_prefix(collection_id);646 <ReFungibleTransferBasket<T>>::remove_prefix(collection_id);647648 <VariableMetaDataBasket<T>>::remove_prefix(collection_id);649 <VariableMetaDataSponsoringRateLimit<T>>::remove(collection_id);642650643 if CollectionCount::get() > 0651 if CollectionCount::get() > 0644 {652 {1424 Ok(())1432 Ok(())1425 }1433 }14341435 #[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 }142614471427 /// Enable the white list for a contract. Only addresses added to the white list with addToContractWhiteList will be able to call this smart contract.1448 /// Enable the white list for a contract. Only addresses added to the white list with addToContractWhiteList will be able to call this smart contract.1428 /// 1449 /// 1866 Ok(())1887 Ok(())1867 }1888 }18891890 fn check_collection_sponsor(1891 collection_id: CollectionId,1892 subject: T::AccountId,1893 ) -> DispatchResult {1894 Self::collection_exists(collection_id)?;1895 let collection = <Collection<T>>::get(collection_id);1896 1897 ensure!(1898 collection.sponsor_confirmed &&1899 collection.sponsor == subject,1900 Error::<T>::NoPermission,1901 );1902 Ok(())1903 }186819041869 fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {1905 fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {1870 let target_collection = <Collection<T>>::get(collection_id);1906 let target_collection = <Collection<T>>::get(collection_id);2467 }2503 }2468 }2504 }25052506 Some(Call::set_variable_meta_data(collection_id, item_id, data)) => {2507 let mut sponsor_metadata_changes = false;25082509 let collection = <Collection<T>>::get(collection_id);2510 if2511 collection.sponsor_confirmed &&2512 // Can't sponsor fungible collection, this tx will be rejected2513 // as invalid2514 !matches!(collection.mode, CollectionMode::Fungible(_)) &&2515 data.len() <= collection.limits.sponsored_data_size as usize2516 {2517 let rate_limit = <VariableMetaDataSponsoringRateLimit<T>>::get(collection_id);2518 if rate_limit > 0.into() {2519 // sponsor timeout2520 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;25212522 if <VariableMetaDataBasket<T>>::get(collection_id, item_id)2523 .map(|last_block| block_number - last_block >= rate_limit)2524 .unwrap_or(true) 2525 {2526 sponsor_metadata_changes = true;2527 <VariableMetaDataBasket<T>>::insert(collection_id, item_id, block_number);2528 }2529 }2530 }25312532 if !sponsor_metadata_changes {2533 T::AccountId::default()2534 } else {2535 <Collection<T>>::get(collection_id).sponsor2536 }2537 }246925382470 _ => T::AccountId::default(),2539 _ => T::AccountId::default(),2471 };2540 };runtime/src/nft_weights.rsdiffbeforeafterboth133 .saturating_add(DbWeight::get().reads(0 as Weight))133 .saturating_add(DbWeight::get().reads(0 as Weight))134 .saturating_add(DbWeight::get().writes(2 as Weight))134 .saturating_add(DbWeight::get().writes(2 as Weight))135 } 135 } 136 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight {137 (3_500_000 as Weight)138 .saturating_add(DbWeight::get().reads(1 as Weight))139 .saturating_add(DbWeight::get().writes(2 as Weight))140 }136 fn toggle_contract_white_list() -> Weight {141 fn toggle_contract_white_list() -> Weight {137 (3_000_000 as Weight)142 (3_000_000 as Weight)138 .saturating_add(DbWeight::get().reads(0 as Weight))143 .saturating_add(DbWeight::get().reads(0 as Weight))