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

difftreelog

Merge pull request #65 from usetech-llc/feature/NFTPAR-288

Greg Zaitsev2021-01-18parents: #add913f #4e9eae9.patch.diff
in: master
Feature/nftpar 288

3 files changed

modifiednode/src/chain_spec.rsdiffbeforeafterboth
--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -209,7 +209,10 @@
                 custom_data_limit: 2048,
                 nft_sponsor_transfer_timeout: 15,
                 fungible_sponsor_transfer_timeout: 15,
-                refungible_sponsor_transfer_timeout: 15,
+				refungible_sponsor_transfer_timeout: 15,
+				offchain_schema_limit: 1024,
+				variable_on_chain_schema_limit: 1024,
+				const_on_chain_schema_limit: 1024,
             },
         }),
         pallet_contracts: Some(ContractsConfig {
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
74 ReFungible(DecimalPoints),74 ReFungible(DecimalPoints),
75}75}
76
77impl Default for CollectionMode {
78 fn default() -> Self {
79 Self::Invalid
80 }
81}
7682
77impl Into<u8> for CollectionMode {83impl Into<u8> for CollectionMode {
78 fn into(self) -> u8 {84 fn into(self) -> u8 {
97 }103 }
98}104}
99
100impl Default for CollectionMode {
101 fn default() -> Self {
102 Self::Invalid
103 }
104}
105105
106#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]106#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
107#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]107#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
209 pub fungible_sponsor_transfer_timeout: u32,209 pub fungible_sponsor_transfer_timeout: u32,
210 pub refungible_sponsor_transfer_timeout: u32,210 pub refungible_sponsor_transfer_timeout: u32,
211
212 // Schema limits
213 pub offchain_schema_limit: u32,
214 pub variable_on_chain_schema_limit: u32,
215 pub const_on_chain_schema_limit: u32,
211}216}
212217
213pub trait WeightInfo {218pub trait WeightInfo {
367 /// Account token limit exceeded per collection372 /// Account token limit exceeded per collection
368 AccountTokenLimitExceeded,373 AccountTokenLimitExceeded,
369 /// Collection limit bounds per collection exceeded374 /// Collection limit bounds per collection exceeded
370 CollectionLimitBoundsExceeded375 CollectionLimitBoundsExceeded,
376 /// Schema data size limit bound exceeded
377 SchemaDataLimitExceeded
371 }378 }
372}379}
373380
1281 let sender = ensure_signed(origin)?;1288 let sender = ensure_signed(origin)?;
1282 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;1289 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
1290
1291 // check schema limit
1292 ensure!(schema.len() as u32 > ChainLimit::get().offchain_schema_limit, "");
12831293
1284 let mut target_collection = <Collection<T>>::get(collection_id);1294 let mut target_collection = <Collection<T>>::get(collection_id);
1285 target_collection.offchain_schema = schema;1295 target_collection.offchain_schema = schema;
1309 let sender = ensure_signed(origin)?;1319 let sender = ensure_signed(origin)?;
1310 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;1320 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
1321
1322 // check schema limit
1323 ensure!(schema.len() as u32 > ChainLimit::get().const_on_chain_schema_limit, "");
13111324
1312 let mut target_collection = <Collection<T>>::get(collection_id);1325 let mut target_collection = <Collection<T>>::get(collection_id);
1313 target_collection.const_on_chain_schema = schema;1326 target_collection.const_on_chain_schema = schema;
1337 let sender = ensure_signed(origin)?;1350 let sender = ensure_signed(origin)?;
1338 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;1351 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
1352
1353 // check schema limit
1354 ensure!(schema.len() as u32 > ChainLimit::get().variable_on_chain_schema_limit, "");
13391355
1340 let mut target_collection = <Collection<T>>::get(collection_id);1356 let mut target_collection = <Collection<T>>::get(collection_id);
1341 target_collection.variable_on_chain_schema = schema;1357 target_collection.variable_on_chain_schema = schema;
addedpallets/nft/src/types.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/nft/src/types.rs
@@ -0,0 +1,234 @@
+#[cfg(feature = "std")]
+pub use std::*;
+
+#[cfg(feature = "std")]
+pub use serde::*;
+
+use codec::{Decode, Encode};
+
+pub type CollectionId = u32;
+pub type TokenId = u32;
+pub type DecimalPoints = u8;
+
+#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub enum CollectionMode {
+    Invalid,
+    NFT,
+    // decimal points
+    Fungible(DecimalPoints),
+    // decimal points
+    ReFungible(DecimalPoints),
+}
+
+impl Into<u8> for CollectionMode {
+    fn into(self) -> u8 {
+        match self {
+            CollectionMode::Invalid => 0,
+            CollectionMode::NFT => 1,
+            CollectionMode::Fungible(_) => 2,
+            CollectionMode::ReFungible(_) => 3,
+        }
+    }
+}
+
+#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub enum AccessMode {
+    Normal,
+    WhiteList,
+}
+impl Default for AccessMode {
+    fn default() -> Self {
+        Self::Normal
+    }
+}
+
+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 {
+    ImageURL,
+    Unique,
+}
+impl Default for SchemaVersion {
+    fn default() -> Self {
+        Self::ImageURL
+    }
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct Ownership<AccountId> {
+    pub owner: AccountId,
+    pub fraction: u128,
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct CollectionType<AccountId> {
+    pub owner: AccountId,
+    pub mode: CollectionMode,
+    pub access: AccessMode,
+    pub decimal_points: DecimalPoints,
+    pub name: Vec<u16>,        // 64 include null escape char
+    pub description: Vec<u16>, // 256 include null escape char
+    pub token_prefix: Vec<u8>, // 16 include null escape char
+    pub mint_mode: bool,
+    pub offchain_schema: Vec<u8>,
+    pub schema_version: SchemaVersion,
+    pub sponsor: AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender
+    pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship
+    pub limits: CollectionLimits, // Collection private restrictions 
+    pub variable_on_chain_schema: Vec<u8>, //
+    pub const_on_chain_schema: Vec<u8>, //
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct NftItemType<AccountId> {
+    pub collection: CollectionId,
+    pub owner: AccountId,
+    pub const_data: Vec<u8>,
+    pub variable_data: Vec<u8>,
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct FungibleItemType<AccountId> {
+    pub collection: CollectionId,
+    pub owner: AccountId,
+    pub value: u128,
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct ReFungibleItemType<AccountId> {
+    pub collection: CollectionId,
+    pub owner: Vec<Ownership<AccountId>>,
+    pub const_data: Vec<u8>,
+    pub variable_data: Vec<u8>,
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct ApprovePermissions<AccountId> {
+    pub approved: AccountId,
+    pub amount: u128,
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct VestingItem<AccountId, Moment> {
+    pub sender: AccountId,
+    pub recipient: AccountId,
+    pub collection_id: CollectionId,
+    pub item_id: TokenId,
+    pub amount: u64,
+    pub vesting_date: Moment,
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct BasketItem<AccountId, BlockNumber> {
+    pub address: AccountId,
+    pub start_block: BlockNumber,
+}
+
+#[derive(Encode, Decode, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct CollectionLimits {
+    pub account_token_ownership_limit: u32,
+    pub sponsored_data_size: u32,
+    pub token_limit: u32,
+
+    // Timeouts for item types in passed blocks
+    pub sponsor_transfer_timeout: u32,
+}
+
+impl Default for CollectionLimits {
+    fn default() -> CollectionLimits {
+        CollectionLimits { 
+            account_token_ownership_limit: 10_000_000, 
+            token_limit: u32::max_value(),
+            sponsored_data_size: u32::max_value(), 
+            sponsor_transfer_timeout: 14400 }
+    }
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct ChainLimits {
+    pub collection_numbers_limit: u32,
+    pub account_token_ownership_limit: u32,
+    pub collections_admins_limit: u64,
+    pub custom_data_limit: u32,
+
+    // Timeouts for item types in passed blocks
+    pub nft_sponsor_transfer_timeout: u32,
+    pub fungible_sponsor_transfer_timeout: u32,
+    pub refungible_sponsor_transfer_timeout: u32,
+}
+
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct CreateNftData {
+    pub const_data: Vec<u8>,
+    pub variable_data: Vec<u8>,
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct CreateFungibleData {
+}
+
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub struct CreateReFungibleData {
+    pub const_data: Vec<u8>,
+    pub variable_data: Vec<u8>,
+}
+
+#[derive(Encode, Decode, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+pub enum CreateItemData {
+    NFT(CreateNftData),
+    Fungible(CreateFungibleData),
+    ReFungible(CreateReFungibleData),
+}
+
+impl CreateItemData {
+    pub fn len(&self) -> usize {
+        let len = match self {
+            CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),
+            CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),
+            _ => 0
+        };
+        
+        return len;
+    }
+}
+
+impl From<CreateNftData> for CreateItemData {
+    fn from(item: CreateNftData) -> Self {
+        CreateItemData::NFT(item)
+    }
+}
+
+impl From<CreateReFungibleData> for CreateItemData {
+    fn from(item: CreateReFungibleData) -> Self {
+        CreateItemData::ReFungible(item)
+    }
+}
+
+impl From<CreateFungibleData> for CreateItemData {
+    fn from(item: CreateFungibleData) -> Self {
+        CreateItemData::Fungible(item)
+    }
+}