From 944d507c1d0ca077c929ceaf807f9168aa17876e Mon Sep 17 00:00:00 2001 From: str-mv Date: Thu, 17 Dec 2020 07:59:52 +0000 Subject: [PATCH] NFTPAR-164. Schema version --- --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -23,6 +23,7 @@ [dependencies] futures = '0.3.4' log = '0.4.8' +flexi_logger = "0.15.7" parking_lot = '0.10.0' structopt = '0.3.8' jsonrpc-core = '15.0.0' --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -167,7 +167,8 @@ description: vec![], token_prefix: vec![], mint_mode: false, - offchain_schema: vec![], + offchain_schema: vec![], + schema_version: SchemaVersion::default(), sponsor: get_account_id_from_seed::("Alice"), unconfirmed_sponsor: get_account_id_from_seed::("Alice"), const_on_chain_schema: vec![], --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -1,3 +1,5 @@ +#![recursion_limit = "1024"] + #![cfg_attr(not(feature = "std"), no_std)] #[cfg(feature = "std")] @@ -54,7 +56,6 @@ pub type CollectionId = u32; pub type TokenId = u32; - pub type DecimalPoints = u8; #[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)] @@ -97,6 +98,18 @@ } } +#[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 { @@ -116,6 +129,7 @@ pub token_prefix: Vec, // 16 include null escape char pub mint_mode: bool, pub offchain_schema: Vec, + 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 @@ -258,7 +272,7 @@ pub enum CreateItemData { NFT(CreateNftData), Fungible(CreateFungibleData), - ReFungible(CreateReFungibleData) + ReFungible(CreateReFungibleData), } impl CreateItemData { @@ -570,6 +584,7 @@ decimal_points: decimal_points, token_prefix: prefix, offchain_schema: Vec::new(), + schema_version: SchemaVersion::ImageURL, sponsor: T::AccountId::default(), unconfirmed_sponsor: T::AccountId::default(), variable_on_chain_schema: Vec::new(), @@ -1200,7 +1215,6 @@ Ok(()) } - /// #[weight = 0] pub fn safe_transfer_from(origin, collection_id: CollectionId, item_id: TokenId, new_owner: T::AccountId) -> DispatchResult { @@ -1259,7 +1273,35 @@ Ok(()) } - + + /// Set schema standard + /// ImageURL + /// Unique + /// + /// # Permissions + /// + /// * Collection Owner + /// * Collection Admin + /// + /// # Arguments + /// + /// * collection_id. + /// + /// * schema: SchemaVersion: enum + #[weight = 0] + pub fn set_schema_version( + origin, + collection_id: CollectionId, + version: SchemaVersion + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + Self::check_owner_or_admin_permissions(collection_id, sender.clone())?; + let mut target_collection = >::get(collection_id); + target_collection.schema_version = version; + >::insert(collection_id, target_collection); + + Ok(()) + } /// Set off-chain data schema. /// @@ -1458,7 +1500,7 @@ impl Module { fn is_correct_transfer(collection_id: CollectionId, collection: &CollectionType, recipient: &T::AccountId) -> DispatchResult { - + // check token limit and account token limit let account_items: u32 = >::get(collection_id, recipient).len() as u32; ensure!(collection.limits.account_token_ownership_limit > account_items, Error::::AccountTokenLimitExceeded); --- a/pallets/nft/src/tests.rs +++ b/pallets/nft/src/tests.rs @@ -77,6 +77,19 @@ // Use cases tests region // #region + +#[test] +fn set_version_schema() { + new_test_ext().execute_with(|| { + default_limits(); + let origin1 = Origin::signed(1); + let collection_id = create_test_collection(&CollectionMode::NFT, 1); + + assert_ok!(TemplateModule::set_schema_version(origin1, collection_id, SchemaVersion::Unique)); + assert_eq!(TemplateModule::collection(collection_id).schema_version, SchemaVersion::Unique); + }); +} + #[test] fn create_fungible_collection_fails_with_large_decimal_numbers() { new_test_ext().execute_with(|| { -- gitstuff