difftreelog
NFTPAR-288. Limit schema size
in: master
2 files changed
node/src/chain_spec.rsdiffbeforeafterboth210 nft_sponsor_transfer_timeout: 15,210 nft_sponsor_transfer_timeout: 15,211 fungible_sponsor_transfer_timeout: 15,211 fungible_sponsor_transfer_timeout: 15,212 refungible_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,213 },216 },214 }),217 }),215 pallet_contracts: Some(ContractsConfig {218 pallet_contracts: Some(ContractsConfig {pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -74,6 +74,12 @@
ReFungible(DecimalPoints),
}
+impl Default for CollectionMode {
+ fn default() -> Self {
+ Self::Invalid
+ }
+}
+
impl Into<u8> for CollectionMode {
fn into(self) -> u8 {
match self {
@@ -97,12 +103,6 @@
}
}
-impl Default for CollectionMode {
- fn default() -> Self {
- Self::Invalid
- }
-}
-
#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum SchemaVersion {
@@ -208,6 +208,11 @@
pub nft_sponsor_transfer_timeout: u32,
pub fungible_sponsor_transfer_timeout: u32,
pub refungible_sponsor_transfer_timeout: u32,
+
+ // Schema limits
+ pub offchain_schema_limit: u32,
+ pub variable_on_chain_schema_limit: u32,
+ pub const_on_chain_schema_limit: u32,
}
pub trait WeightInfo {
@@ -367,7 +372,9 @@
/// Account token limit exceeded per collection
AccountTokenLimitExceeded,
/// Collection limit bounds per collection exceeded
- CollectionLimitBoundsExceeded
+ CollectionLimitBoundsExceeded,
+ /// Schema data size limit bound exceeded
+ SchemaDataLimitExceeded
}
}
@@ -1281,6 +1288,9 @@
let sender = ensure_signed(origin)?;
Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
+ // check schema limit
+ ensure!(schema.len() as u32 > ChainLimit::get().offchain_schema_limit, "");
+
let mut target_collection = <Collection<T>>::get(collection_id);
target_collection.offchain_schema = schema;
<Collection<T>>::insert(collection_id, target_collection);
@@ -1309,6 +1319,9 @@
let sender = ensure_signed(origin)?;
Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
+ // check schema limit
+ ensure!(schema.len() as u32 > ChainLimit::get().const_on_chain_schema_limit, "");
+
let mut target_collection = <Collection<T>>::get(collection_id);
target_collection.const_on_chain_schema = schema;
<Collection<T>>::insert(collection_id, target_collection);
@@ -1337,6 +1350,9 @@
let sender = ensure_signed(origin)?;
Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
+ // check schema limit
+ ensure!(schema.len() as u32 > ChainLimit::get().variable_on_chain_schema_limit, "");
+
let mut target_collection = <Collection<T>>::get(collection_id);
target_collection.variable_on_chain_schema = schema;
<Collection<T>>::insert(collection_id, target_collection);