git.delta.rocks / unique-network / refs/commits / 944d507c1d0c

difftreelog

NFTPAR-164. Schema version

str-mv2020-12-17parent: #f46510a.patch.diff
in: master

4 files changed

modifiednode/Cargo.tomldiffbeforeafterboth
before · node/Cargo.toml
1[build-dependencies.substrate-build-script-utils]2git = 'https://github.com/usetech-llc/substrate.git'3branch = 'release_flexi'4version = '2.0.0'56[[bin]]7name = 'nft'89[package]10authors = ['UseTech Professional <https://usetech.com/blockchain>']11build = 'build.rs'12description = 'Substrate node nft'13edition = '2018'14homepage = 'https://usetech.com/blockchain'15license = 'Unlicense'16name = 'nft'17repository = 'https://github.com/substrate-developer-hub/nft/'18version = '2.0.0'1920[package.metadata.docs.rs]21targets = ['x86_64-unknown-linux-gnu']2223[dependencies]24futures = '0.3.4'25log = '0.4.8'26parking_lot = '0.10.0'27structopt = '0.3.8'28jsonrpc-core = '15.0.0'2930# Substrate dependencies31nft-runtime = { path = '../runtime', version = '2.0.0' }32frame-benchmarking = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}33frame-benchmarking-cli = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}34pallet-transaction-payment-rpc = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}35sc-basic-authorship = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}36sc-cli = { features = ['wasmtime'], version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }37sc-client-api = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}38sc-consensus = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}39sc-consensus-aura = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}40sc-executor = { features = ['wasmtime'], version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }41sc-finality-grandpa = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}42sc-rpc = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}43sc-rpc-api = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}44sc-service = { features = ['wasmtime'], version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }45sc-transaction-pool = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}46sp-api = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}47sp-block-builder = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}48sp-blockchain = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}49sp-consensus = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}50sp-consensus-aura = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}51sp-core = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}52sp-finality-grandpa = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}53sp-inherents = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}54sp-runtime = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}55sp-transaction-pool = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}56sc-network = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'} 57substrate-frame-rpc-system = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}58pallet-contracts-rpc = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'} 5960[features]61default = []62runtime-benchmarks = ['nft-runtime/runtime-benchmarks']
after · node/Cargo.toml
1[build-dependencies.substrate-build-script-utils]2git = 'https://github.com/usetech-llc/substrate.git'3branch = 'release_flexi'4version = '2.0.0'56[[bin]]7name = 'nft'89[package]10authors = ['UseTech Professional <https://usetech.com/blockchain>']11build = 'build.rs'12description = 'Substrate node nft'13edition = '2018'14homepage = 'https://usetech.com/blockchain'15license = 'Unlicense'16name = 'nft'17repository = 'https://github.com/substrate-developer-hub/nft/'18version = '2.0.0'1920[package.metadata.docs.rs]21targets = ['x86_64-unknown-linux-gnu']2223[dependencies]24futures = '0.3.4'25log = '0.4.8'26flexi_logger = "0.15.7"27parking_lot = '0.10.0'28structopt = '0.3.8'29jsonrpc-core = '15.0.0'3031# Substrate dependencies32nft-runtime = { path = '../runtime', version = '2.0.0' }33frame-benchmarking = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}34frame-benchmarking-cli = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}35pallet-transaction-payment-rpc = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}36sc-basic-authorship = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}37sc-cli = { features = ['wasmtime'], version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }38sc-client-api = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}39sc-consensus = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}40sc-consensus-aura = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}41sc-executor = { features = ['wasmtime'], version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }42sc-finality-grandpa = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}43sc-rpc = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}44sc-rpc-api = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}45sc-service = { features = ['wasmtime'], version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }46sc-transaction-pool = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}47sp-api = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}48sp-block-builder = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}49sp-blockchain = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}50sp-consensus = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}51sp-consensus-aura = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}52sp-core = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}53sp-finality-grandpa = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}54sp-inherents = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}55sp-runtime = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}56sp-transaction-pool = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}57sc-network = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'} 58substrate-frame-rpc-system = {version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'}59pallet-contracts-rpc = {version = '0.8.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi'} 6061[features]62default = []63runtime-benchmarks = ['nft-runtime/runtime-benchmarks']
modifiednode/src/chain_spec.rsdiffbeforeafterboth
--- 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::<sr25519::Public>("Alice"),
                     unconfirmed_sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
                     const_on_chain_schema: vec![],
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- 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<AccountId> {
@@ -116,6 +129,7 @@
     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 
@@ -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 = <Collection<T>>::get(collection_id);
+            target_collection.schema_version = version;
+            <Collection<T>>::insert(collection_id, target_collection);
+
+            Ok(())
+        }
 
         /// Set off-chain data schema.
         /// 
@@ -1458,7 +1500,7 @@
 impl<T: Trait> Module<T> {
 
     fn is_correct_transfer(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, recipient: &T::AccountId) -> DispatchResult {
-        
+
         // check token limit and account token limit
         let account_items: u32 = <AddressTokens<T>>::get(collection_id, recipient).len() as u32;
         ensure!(collection.limits.account_token_ownership_limit > account_items,  Error::<T>::AccountTokenLimitExceeded);
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
--- 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(|| {