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
23[dependencies]23[dependencies]
24futures = '0.3.4'24futures = '0.3.4'
25log = '0.4.8'25log = '0.4.8'
26flexi_logger = "0.15.7"
26parking_lot = '0.10.0'27parking_lot = '0.10.0'
27structopt = '0.3.8'28structopt = '0.3.8'
28jsonrpc-core = '15.0.0'29jsonrpc-core = '15.0.0'
modifiednode/src/chain_spec.rsdiffbeforeafterboth
168 token_prefix: vec![],168 token_prefix: vec![],
169 mint_mode: false,169 mint_mode: false,
170 offchain_schema: vec![],170 offchain_schema: vec![],
171 schema_version: SchemaVersion::default(),
171 sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),172 sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
172 unconfirmed_sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),173 unconfirmed_sponsor: get_account_id_from_seed::<sr25519::Public>("Alice"),
173 const_on_chain_schema: vec![],174 const_on_chain_schema: vec![],
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
1#![recursion_limit = "1024"]
2
1#![cfg_attr(not(feature = "std"), no_std)]3#![cfg_attr(not(feature = "std"), no_std)]
24
97 }98 }
98}99}
100
101#[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::ImageURL
110 }
111}
99112
100#[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 char
117 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 sender
120 pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship134 pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship
121 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}
263277
264impl 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 }
12021217
1203 ///
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 {
12061220
1260 Ok(())1274 Ok(())
1261 }1275 }
1262 1276
1277 /// Set schema standard
1278 /// ImageURL
1279 /// Unique
1280 ///
1281 /// # Permissions
1282 ///
1283 /// * Collection Owner
1284 /// * Collection Admin
1285 ///
1286 /// # Arguments
1287 ///
1288 /// * collection_id.
1289 ///
1290 /// * schema: SchemaVersion: enum
1291 #[weight = 0]
1292 pub fn set_schema_version(
1293 origin,
1294 collection_id: CollectionId,
1295 version: SchemaVersion
1296 ) -> 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);
1302
1303 Ok(())
1304 }
12631305
1264 /// Set off-chain data schema.1306 /// Set off-chain data schema.
1265 /// 1307 ///
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
78// Use cases tests region78// Use cases tests region
79// #region79// #region
80
81#[test]
82fn set_version_schema() {
83 new_test_ext().execute_with(|| {
84 default_limits();
85 let origin1 = Origin::signed(1);
86 let collection_id = create_test_collection(&CollectionMode::NFT, 1);
87
88 assert_ok!(TemplateModule::set_schema_version(origin1, collection_id, SchemaVersion::Unique));
89 assert_eq!(TemplateModule::collection(collection_id).schema_version, SchemaVersion::Unique);
90 });
91}
92
80#[test]93#[test]
81fn create_fungible_collection_fails_with_large_decimal_numbers() {94fn create_fungible_collection_fails_with_large_decimal_numbers() {