difftreelog
feat implement setVariableMetadata sponsoring
in: master
3 files changed
pallets/nft/src/default_weights.rsdiffbeforeafterboth1use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};23impl crate::WeightInfo for () {4 fn create_collection() -> Weight {5 (70_000_000 as Weight)6 .saturating_add(DbWeight::get().reads(7 as Weight))7 .saturating_add(DbWeight::get().writes(5 as Weight))8 }9 fn destroy_collection() -> Weight {10 (90_000_000 as Weight)11 .saturating_add(DbWeight::get().reads(2 as Weight))12 .saturating_add(DbWeight::get().writes(5 as Weight))13 }14 fn add_to_white_list() -> Weight {15 (30_000_000 as Weight)16 .saturating_add(DbWeight::get().reads(3 as Weight))17 .saturating_add(DbWeight::get().writes(1 as Weight))18 }19 fn remove_from_white_list() -> Weight {20 (35_000_000 as Weight)21 .saturating_add(DbWeight::get().reads(3 as Weight))22 .saturating_add(DbWeight::get().writes(1 as Weight))23 }24 fn set_public_access_mode() -> Weight {25 (27_000_000 as Weight)26 .saturating_add(DbWeight::get().reads(1 as Weight))27 .saturating_add(DbWeight::get().writes(1 as Weight))28 }29 fn set_mint_permission() -> Weight {30 (27_000_000 as Weight)31 .saturating_add(DbWeight::get().reads(1 as Weight))32 .saturating_add(DbWeight::get().writes(1 as Weight))33 }34 fn change_collection_owner() -> Weight {35 (27_000_000 as Weight)36 .saturating_add(DbWeight::get().reads(1 as Weight))37 .saturating_add(DbWeight::get().writes(1 as Weight))38 }39 fn add_collection_admin() -> Weight {40 (32_000_000 as Weight)41 .saturating_add(DbWeight::get().reads(3 as Weight))42 .saturating_add(DbWeight::get().writes(1 as Weight))43 }44 fn remove_collection_admin() -> Weight {45 (50_000_000 as Weight)46 .saturating_add(DbWeight::get().reads(2 as Weight))47 .saturating_add(DbWeight::get().writes(1 as Weight))48 }49 fn set_collection_sponsor() -> Weight {50 (32_000_000 as Weight)51 .saturating_add(DbWeight::get().reads(2 as Weight))52 .saturating_add(DbWeight::get().writes(1 as Weight))53 } 54 fn confirm_sponsorship() -> Weight {55 (22_000_000 as Weight)56 .saturating_add(DbWeight::get().reads(1 as Weight))57 .saturating_add(DbWeight::get().writes(1 as Weight))58 } 59 fn remove_collection_sponsor() -> Weight {60 (24_000_000 as Weight)61 .saturating_add(DbWeight::get().reads(1 as Weight))62 .saturating_add(DbWeight::get().writes(1 as Weight))63 } 64 fn create_item(s: usize, ) -> Weight {65 (130_000_000 as Weight)66 .saturating_add((2135 as Weight).saturating_mul(s as Weight).saturating_mul(500 as Weight)) // 500 is temporary multiplier, fee for storage67 .saturating_add(DbWeight::get().reads(10 as Weight))68 .saturating_add(DbWeight::get().writes(8 as Weight))69 } 70 fn burn_item() -> Weight {71 (170_000_000 as Weight)72 .saturating_add(DbWeight::get().reads(9 as Weight))73 .saturating_add(DbWeight::get().writes(7 as Weight))74 } 75 fn transfer() -> Weight {76 (125_000_000 as Weight)77 .saturating_add(DbWeight::get().reads(7 as Weight))78 .saturating_add(DbWeight::get().writes(7 as Weight))79 } 80 fn approve() -> Weight {81 (45_000_000 as Weight)82 .saturating_add(DbWeight::get().reads(3 as Weight))83 .saturating_add(DbWeight::get().writes(1 as Weight))84 }85 fn transfer_from() -> Weight {86 (150_000_000 as Weight)87 .saturating_add(DbWeight::get().reads(9 as Weight))88 .saturating_add(DbWeight::get().writes(8 as Weight))89 }90 fn set_offchain_schema() -> Weight {91 (33_000_000 as Weight)92 .saturating_add(DbWeight::get().reads(2 as Weight))93 .saturating_add(DbWeight::get().writes(1 as Weight))94 }95 fn set_const_on_chain_schema() -> Weight {96 (11_100_000 as Weight)97 .saturating_add(DbWeight::get().reads(2 as Weight))98 .saturating_add(DbWeight::get().writes(1 as Weight))99 }100 fn set_variable_on_chain_schema() -> Weight {101 (11_100_000 as Weight)102 .saturating_add(DbWeight::get().reads(2 as Weight))103 .saturating_add(DbWeight::get().writes(1 as Weight))104 }105 fn set_variable_meta_data() -> Weight {106 (17_500_000 as Weight)107 .saturating_add(DbWeight::get().reads(2 as Weight))108 .saturating_add(DbWeight::get().writes(1 as Weight))109 }110 fn enable_contract_sponsoring() -> Weight {111 (13_000_000 as Weight)112 .saturating_add(DbWeight::get().reads(1 as Weight))113 .saturating_add(DbWeight::get().writes(1 as Weight))114 }115 fn set_schema_version() -> Weight {116 (8_500_000 as Weight)117 .saturating_add(DbWeight::get().reads(2 as Weight))118 .saturating_add(DbWeight::get().writes(1 as Weight))119 }120 fn set_chain_limits() -> Weight {121 (1_300_000 as Weight)122 .saturating_add(DbWeight::get().reads(0 as Weight))123 .saturating_add(DbWeight::get().writes(1 as Weight))124 }125 fn set_contract_sponsoring_rate_limit() -> Weight {126 (3_500_000 as Weight)127 .saturating_add(DbWeight::get().reads(0 as Weight))128 .saturating_add(DbWeight::get().writes(2 as Weight))129 } 130 fn toggle_contract_white_list() -> Weight {131 (3_000_000 as Weight)132 .saturating_add(DbWeight::get().reads(0 as Weight))133 .saturating_add(DbWeight::get().writes(2 as Weight))134 } 135 fn add_to_contract_white_list() -> Weight {136 (3_000_000 as Weight)137 .saturating_add(DbWeight::get().reads(0 as Weight))138 .saturating_add(DbWeight::get().writes(2 as Weight))139 } 140 fn remove_from_contract_white_list() -> Weight {141 (3_200_000 as Weight)142 .saturating_add(DbWeight::get().reads(0 as Weight))143 .saturating_add(DbWeight::get().writes(2 as Weight))144 }145 fn set_collection_limits() -> Weight {146 (8_900_000 as Weight)147 .saturating_add(DbWeight::get().reads(2 as Weight))148 .saturating_add(DbWeight::get().writes(1 as Weight))149 }150}1use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};23impl crate::WeightInfo for () {4 fn create_collection() -> Weight {5 (70_000_000 as Weight)6 .saturating_add(DbWeight::get().reads(7 as Weight))7 .saturating_add(DbWeight::get().writes(5 as Weight))8 }9 fn destroy_collection() -> Weight {10 (90_000_000 as Weight)11 .saturating_add(DbWeight::get().reads(2 as Weight))12 .saturating_add(DbWeight::get().writes(5 as Weight))13 }14 fn add_to_white_list() -> Weight {15 (30_000_000 as Weight)16 .saturating_add(DbWeight::get().reads(3 as Weight))17 .saturating_add(DbWeight::get().writes(1 as Weight))18 }19 fn remove_from_white_list() -> Weight {20 (35_000_000 as Weight)21 .saturating_add(DbWeight::get().reads(3 as Weight))22 .saturating_add(DbWeight::get().writes(1 as Weight))23 }24 fn set_public_access_mode() -> Weight {25 (27_000_000 as Weight)26 .saturating_add(DbWeight::get().reads(1 as Weight))27 .saturating_add(DbWeight::get().writes(1 as Weight))28 }29 fn set_mint_permission() -> Weight {30 (27_000_000 as Weight)31 .saturating_add(DbWeight::get().reads(1 as Weight))32 .saturating_add(DbWeight::get().writes(1 as Weight))33 }34 fn change_collection_owner() -> Weight {35 (27_000_000 as Weight)36 .saturating_add(DbWeight::get().reads(1 as Weight))37 .saturating_add(DbWeight::get().writes(1 as Weight))38 }39 fn add_collection_admin() -> Weight {40 (32_000_000 as Weight)41 .saturating_add(DbWeight::get().reads(3 as Weight))42 .saturating_add(DbWeight::get().writes(1 as Weight))43 }44 fn remove_collection_admin() -> Weight {45 (50_000_000 as Weight)46 .saturating_add(DbWeight::get().reads(2 as Weight))47 .saturating_add(DbWeight::get().writes(1 as Weight))48 }49 fn set_collection_sponsor() -> Weight {50 (32_000_000 as Weight)51 .saturating_add(DbWeight::get().reads(2 as Weight))52 .saturating_add(DbWeight::get().writes(1 as Weight))53 } 54 fn confirm_sponsorship() -> Weight {55 (22_000_000 as Weight)56 .saturating_add(DbWeight::get().reads(1 as Weight))57 .saturating_add(DbWeight::get().writes(1 as Weight))58 } 59 fn remove_collection_sponsor() -> Weight {60 (24_000_000 as Weight)61 .saturating_add(DbWeight::get().reads(1 as Weight))62 .saturating_add(DbWeight::get().writes(1 as Weight))63 } 64 fn create_item(s: usize, ) -> Weight {65 (130_000_000 as Weight)66 .saturating_add((2135 as Weight).saturating_mul(s as Weight).saturating_mul(500 as Weight)) // 500 is temporary multiplier, fee for storage67 .saturating_add(DbWeight::get().reads(10 as Weight))68 .saturating_add(DbWeight::get().writes(8 as Weight))69 } 70 fn burn_item() -> Weight {71 (170_000_000 as Weight)72 .saturating_add(DbWeight::get().reads(9 as Weight))73 .saturating_add(DbWeight::get().writes(7 as Weight))74 } 75 fn transfer() -> Weight {76 (125_000_000 as Weight)77 .saturating_add(DbWeight::get().reads(7 as Weight))78 .saturating_add(DbWeight::get().writes(7 as Weight))79 } 80 fn approve() -> Weight {81 (45_000_000 as Weight)82 .saturating_add(DbWeight::get().reads(3 as Weight))83 .saturating_add(DbWeight::get().writes(1 as Weight))84 }85 fn transfer_from() -> Weight {86 (150_000_000 as Weight)87 .saturating_add(DbWeight::get().reads(9 as Weight))88 .saturating_add(DbWeight::get().writes(8 as Weight))89 }90 fn set_offchain_schema() -> Weight {91 (33_000_000 as Weight)92 .saturating_add(DbWeight::get().reads(2 as Weight))93 .saturating_add(DbWeight::get().writes(1 as Weight))94 }95 fn set_const_on_chain_schema() -> Weight {96 (11_100_000 as Weight)97 .saturating_add(DbWeight::get().reads(2 as Weight))98 .saturating_add(DbWeight::get().writes(1 as Weight))99 }100 fn set_variable_on_chain_schema() -> Weight {101 (11_100_000 as Weight)102 .saturating_add(DbWeight::get().reads(2 as Weight))103 .saturating_add(DbWeight::get().writes(1 as Weight))104 }105 fn set_variable_meta_data() -> Weight {106 (17_500_000 as Weight)107 .saturating_add(DbWeight::get().reads(2 as Weight))108 .saturating_add(DbWeight::get().writes(1 as Weight))109 }110 fn enable_contract_sponsoring() -> Weight {111 (13_000_000 as Weight)112 .saturating_add(DbWeight::get().reads(1 as Weight))113 .saturating_add(DbWeight::get().writes(1 as Weight))114 }115 fn set_schema_version() -> Weight {116 (8_500_000 as Weight)117 .saturating_add(DbWeight::get().reads(2 as Weight))118 .saturating_add(DbWeight::get().writes(1 as Weight))119 }120 fn set_chain_limits() -> Weight {121 (1_300_000 as Weight)122 .saturating_add(DbWeight::get().reads(0 as Weight))123 .saturating_add(DbWeight::get().writes(1 as Weight))124 }125 fn set_contract_sponsoring_rate_limit() -> Weight {126 (3_500_000 as Weight)127 .saturating_add(DbWeight::get().reads(0 as Weight))128 .saturating_add(DbWeight::get().writes(2 as Weight))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 }135 fn toggle_contract_white_list() -> Weight {136 (3_000_000 as Weight)137 .saturating_add(DbWeight::get().reads(0 as Weight))138 .saturating_add(DbWeight::get().writes(2 as Weight))139 } 140 fn add_to_contract_white_list() -> Weight {141 (3_000_000 as Weight)142 .saturating_add(DbWeight::get().reads(0 as Weight))143 .saturating_add(DbWeight::get().writes(2 as Weight))144 } 145 fn remove_from_contract_white_list() -> Weight {146 (3_200_000 as Weight)147 .saturating_add(DbWeight::get().reads(0 as Weight))148 .saturating_add(DbWeight::get().writes(2 as Weight))149 }150 fn set_collection_limits() -> Weight {151 (8_900_000 as Weight)152 .saturating_add(DbWeight::get().reads(2 as Weight))153 .saturating_add(DbWeight::get().writes(1 as Weight))154 }155}pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -247,6 +247,7 @@
fn set_schema_version() -> Weight;
fn set_chain_limits() -> Weight;
fn set_contract_sponsoring_rate_limit() -> Weight;
+ fn set_variable_meta_data_sponsoring_rate_limit() -> Weight;
fn toggle_contract_white_list() -> Weight;
fn add_to_contract_white_list() -> Weight;
fn remove_from_contract_white_list() -> Weight;
@@ -442,6 +443,10 @@
pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => T::BlockNumber;
pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;
+ /// Variable metadata sponsoring
+ pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => Option<T::BlockNumber> = None;
+ pub VariableMetaDataSponsoringRateLimit get(fn variable_meta_data_sponsoring_rate_limit): map hasher(identity) CollectionId => T::BlockNumber = 0.into();
+
// Contract Sponsorship and Ownership
pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;
pub ContractSelfSponsoring get(fn contract_self_sponsoring): map hasher(twox_64_concat) T::AccountId => bool;
@@ -640,6 +645,9 @@
<FungibleTransferBasket<T>>::remove_prefix(collection_id);
<ReFungibleTransferBasket<T>>::remove_prefix(collection_id);
+ <VariableMetaDataBasket<T>>::remove_prefix(collection_id);
+ <VariableMetaDataSponsoringRateLimit<T>>::remove(collection_id);
+
if CollectionCount::get() > 0
{
// bound couter
@@ -1424,6 +1432,19 @@
Ok(())
}
+ #[weight = <T as Config>::WeightInfo::set_variable_meta_data_sponsoring_rate_limit()]
+ pub fn set_variable_meta_data_sponsoring_rate_limit(
+ origin,
+ collection_id: CollectionId,
+ rate_limit: T::BlockNumber
+ ) -> DispatchResult {
+ let sender = ensure_signed(origin)?;
+ Self::check_collection_sponsor(collection_id.clone(), sender.clone())?;
+
+ <VariableMetaDataSponsoringRateLimit<T>>::insert(collection_id, rate_limit);
+ Ok(())
+ }
+
/// Enable the white list for a contract. Only addresses added to the white list with addToContractWhiteList will be able to call this smart contract.
///
/// # Permissions
@@ -1866,6 +1887,21 @@
Ok(())
}
+ fn check_collection_sponsor(
+ collection_id: CollectionId,
+ subject: T::AccountId,
+ ) -> DispatchResult {
+ Self::collection_exists(collection_id)?;
+ let collection = <Collection<T>>::get(collection_id);
+
+ ensure!(
+ collection.sponsor_confirmed &&
+ collection.sponsor == subject,
+ Error::<T>::NoPermission,
+ );
+ Ok(())
+ }
+
fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {
let target_collection = <Collection<T>>::get(collection_id);
@@ -2467,6 +2503,39 @@
}
}
+ Some(Call::set_variable_meta_data(collection_id, item_id, data)) => {
+ let mut sponsor_metadata_changes = false;
+
+ let collection = <Collection<T>>::get(collection_id);
+ if
+ collection.sponsor_confirmed &&
+ // Can't sponsor fungible collection, this tx will be rejected
+ // as invalid
+ !matches!(collection.mode, CollectionMode::Fungible(_)) &&
+ data.len() <= collection.limits.sponsored_data_size as usize
+ {
+ let rate_limit = <VariableMetaDataSponsoringRateLimit<T>>::get(collection_id);
+ if rate_limit > 0.into() {
+ // sponsor timeout
+ let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
+
+ if <VariableMetaDataBasket<T>>::get(collection_id, item_id)
+ .map(|last_block| block_number - last_block >= rate_limit)
+ .unwrap_or(true)
+ {
+ sponsor_metadata_changes = true;
+ <VariableMetaDataBasket<T>>::insert(collection_id, item_id, block_number);
+ }
+ }
+ }
+
+ if !sponsor_metadata_changes {
+ T::AccountId::default()
+ } else {
+ <Collection<T>>::get(collection_id).sponsor
+ }
+ }
+
_ => T::AccountId::default(),
};
runtime/src/nft_weights.rsdiffbeforeafterboth--- a/runtime/src/nft_weights.rs
+++ b/runtime/src/nft_weights.rs
@@ -133,6 +133,11 @@
.saturating_add(DbWeight::get().reads(0 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
+ fn set_variable_meta_data_sponsoring_rate_limit() -> Weight {
+ (3_500_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(2 as Weight))
+ }
fn toggle_contract_white_list() -> Weight {
(3_000_000 as Weight)
.saturating_add(DbWeight::get().reads(0 as Weight))