difftreelog
NFTPAR-164. Schema version
in: master
4 files changed
node/Cargo.tomldiffbeforeafterboth--- 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'
node/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![],
pallets/nft/src/lib.rsdiffbeforeafterboth1#![recursion_limit = "1024"]21#![cfg_attr(not(feature = "std"), no_std)]3#![cfg_attr(not(feature = "std"), no_std)]2497 }98 }98}99}100101#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]102#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]103pub enum SchemaVersion {104 ImageURL,105 Unique,106}107impl Default for SchemaVersion {108 fn default() -> Self {109 Self::ImageURL110 }111}99112100#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]113#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]101#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]114#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]116 pub token_prefix: Vec<u8>, // 16 include null escape char129 pub token_prefix: Vec<u8>, // 16 include null escape char117 pub mint_mode: bool,130 pub mint_mode: bool,118 pub offchain_schema: Vec<u8>,131 pub offchain_schema: Vec<u8>,132 pub schema_version: SchemaVersion,119 pub sponsor: AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender133 pub sponsor: AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender120 pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship134 pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship121 pub limits: CollectionLimits, // Collection private restrictions 135 pub limits: CollectionLimits, // Collection private restrictions 258pub enum CreateItemData {272pub enum CreateItemData {259 NFT(CreateNftData),273 NFT(CreateNftData),260 Fungible(CreateFungibleData),274 Fungible(CreateFungibleData),261 ReFungible(CreateReFungibleData)275 ReFungible(CreateReFungibleData),262}276}263277264impl CreateItemData {278impl CreateItemData {570 decimal_points: decimal_points,584 decimal_points: decimal_points,571 token_prefix: prefix,585 token_prefix: prefix,572 offchain_schema: Vec::new(),586 offchain_schema: Vec::new(),587 schema_version: SchemaVersion::ImageURL,573 sponsor: T::AccountId::default(),588 sponsor: T::AccountId::default(),574 unconfirmed_sponsor: T::AccountId::default(),589 unconfirmed_sponsor: T::AccountId::default(),575 variable_on_chain_schema: Vec::new(),590 variable_on_chain_schema: Vec::new(),1200 Ok(())1215 Ok(())1201 }1216 }120212171203 ///1204 #[weight = 0]1218 #[weight = 0]1205 pub fn safe_transfer_from(origin, collection_id: CollectionId, item_id: TokenId, new_owner: T::AccountId) -> DispatchResult {1219 pub fn safe_transfer_from(origin, collection_id: CollectionId, item_id: TokenId, new_owner: T::AccountId) -> DispatchResult {120612201260 Ok(())1274 Ok(())1261 }1275 }1262 1276 1277 /// Set schema standard1278 /// ImageURL1279 /// Unique1280 /// 1281 /// # Permissions1282 /// 1283 /// * Collection Owner1284 /// * Collection Admin1285 /// 1286 /// # Arguments1287 /// 1288 /// * collection_id.1289 /// 1290 /// * schema: SchemaVersion: enum1291 #[weight = 0]1292 pub fn set_schema_version(1293 origin,1294 collection_id: CollectionId,1295 version: SchemaVersion1296 ) -> DispatchResult {1297 let sender = ensure_signed(origin)?;1298 Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;1299 let mut target_collection = <Collection<T>>::get(collection_id);1300 target_collection.schema_version = version;1301 <Collection<T>>::insert(collection_id, target_collection);13021303 Ok(())1304 }126313051264 /// Set off-chain data schema.1306 /// Set off-chain data schema.1265 /// 1307 /// pallets/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(|| {