difftreelog
Merge pull request #22 from usetech-llc/feature/NFTPAR-142
in: master
NFTPAR-142 Off-chain and on-chain data schema.
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth264decl_error! {264decl_error! {265 /// Error for non-fungible-token module.265 /// Error for non-fungible-token module.266 pub enum Error for Module<T: Trait> {266 pub enum Error for Module<T: Trait> {267 /// Total collections bound exceeded267 /// Total collections bound exceeded.268 TotalCollectionsLimitExceeded,268 TotalCollectionsLimitExceeded,269 /// Decimal_points parameter must be lower than 4269 /// Decimal_points parameter must be lower than 4.270 CollectionDecimalPointLimitExceeded, 270 CollectionDecimalPointLimitExceeded, 271 /// Collection name can not be longer than 63 char271 /// Collection name can not be longer than 63 char.272 CollectionNameLimitExceeded, 272 CollectionNameLimitExceeded, 273 /// Collection description can not be longer than 255 char273 /// Collection description can not be longer than 255 char.274 CollectionDescriptionLimitExceeded, 274 CollectionDescriptionLimitExceeded, 275 /// Token prefix can not be longer than 15 char275 /// Token prefix can not be longer than 15 char.276 CollectionTokenPrefixLimitExceeded,276 CollectionTokenPrefixLimitExceeded,277 /// This collection does not exist277 /// This collection does not exist.278 CollectionNotFound,278 CollectionNotFound,279 /// Item not exists279 /// Item not exists.280 TokenNotFound,280 TokenNotFound,281 /// Arithmetic calculation overflow281 /// Arithmetic calculation overflow.282 NumOverflow, 282 NumOverflow, 283 /// Account already has admin role283 /// Account already has admin role.284 AlreadyAdmin, 284 AlreadyAdmin, 285 /// You do not own this collection285 /// You do not own this collection.286 NoPermission,286 NoPermission,287 /// This address is not set as sponsor, use setCollectionSponsor first287 /// This address is not set as sponsor, use setCollectionSponsor first.288 ConfirmUnsetSponsorFail,288 ConfirmUnsetSponsorFail,289 /// Collection is not in mint mode289 /// Collection is not in mint mode.290 PublicMintingNotAllowed,290 PublicMintingNotAllowed,291 /// Sender parameter and item owner must be equal291 /// Sender parameter and item owner must be equal.292 MustBeTokenOwner,292 MustBeTokenOwner,293 /// Item balance not enouth293 /// Item balance not enough.294 TokenValueTooLow,294 TokenValueTooLow,295 /// Size of item is too large295 /// Size of item is too large.296 NftSizeLimitExceeded,296 NftSizeLimitExceeded,297 /// Size of item must be 0 with fungible type298 FungibleUnexpectedParam,299 /// No approve found297 /// No approve found300 ApproveNotFound,298 ApproveNotFound,301 /// Requested value more than approved299 /// Requested value more than approved.302 TokenValueNotEnough,300 TokenValueNotEnough,303 /// Only approved addresses can call this method301 /// Only approved addresses can call this method.304 ApproveRequired,302 ApproveRequired,305 /// Address is not in white list303 /// Address is not in white list.306 AddresNotInWhiteList,304 AddresNotInWhiteList,307 /// Number of collection admins bound exceeded305 /// Number of collection admins bound exceeded.308 CollectionAdminsLimitExceeded,306 CollectionAdminsLimitExceeded,309 /// Owned tokens by a single address bound exceeded307 /// Owned tokens by a single address bound exceeded.310 AddressOwnershipLimitExceeded,308 AddressOwnershipLimitExceeded,311 /// Length of items properties must be greater than 0309 /// Length of items properties must be greater than 0.312 EmptyArgument,310 EmptyArgument,311 /// const_data exceeded data limit.312 TokenConstDataLimitExceeded,313 /// variable_data exceeded data limit.314 TokenVariableDataLimitExceeded,315 /// Not NFT item data used to mint in NFT collection.316 NotNftDataUsedToMintNftCollectionToken,317 /// Not Fungible item data used to mint in Fungible collection.318 NotFungibleDataUsedToMintFungibleCollectionToken,319 /// Not Re Fungible item data used to mint in Re Fungible collection.320 NotReFungibleDataUsedToMintReFungibleCollectionToken,321 /// Unexpected collection type.322 UnexpectedCollectionType,323 /// Can't store metadata in fungible tokens.324 CantStoreMetadataInFungibleTokens313 }325 }314}326}3153271182 1194 1183 Self::collection_exists(collection_id)?;1195 Self::collection_exists(collection_id)?;1196 1197 ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);118411981185 // Modify permissions check1199 // Modify permissions check1186 let target_collection = <Collection<T>>::get(collection_id);1200 let target_collection = <Collection<T>>::get(collection_id);1194 {1208 {1195 CollectionMode::NFT => Self::set_nft_variable_data(collection_id, item_id, data)?,1209 CollectionMode::NFT => Self::set_nft_variable_data(collection_id, item_id, data)?,1196 CollectionMode::ReFungible(_) => Self::set_re_fungible_variable_data(collection_id, item_id, data)?,1210 CollectionMode::ReFungible(_) => Self::set_re_fungible_variable_data(collection_id, item_id, data)?,1211 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1197 _ => ()1212 _ => fail!(Error::<T>::UnexpectedCollectionType)1198 };1213 };119912141200 Ok(())1215 Ok(())1382 CollectionMode::NFT => {1397 CollectionMode::NFT => {1383 if let CreateItemData::NFT(data) = data {1398 if let CreateItemData::NFT(data) = data {1384 // check sizes1399 // check sizes1385 ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");1400 ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, Error::<T>::TokenConstDataLimitExceeded);1386 ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");1401 ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);1387 } else {1402 } else {1388 fail!("Not NFT item data used to mint in NFT collection.");1403 fail!(Error::<T>::NotNftDataUsedToMintNftCollectionToken);1389 }1404 }1390 },1405 },1391 CollectionMode::Fungible(_) => {1406 CollectionMode::Fungible(_) => {1392 if let CreateItemData::Fungible(_) = data {1407 if let CreateItemData::Fungible(_) = data {1393 } else {1408 } else {1394 fail!("Not Fungible item data used to mint in Fungible collection.");1409 fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);1395 }1410 }1396 },1411 },1397 CollectionMode::ReFungible(_) => {1412 CollectionMode::ReFungible(_) => {1398 if let CreateItemData::ReFungible(data) = data {1413 if let CreateItemData::ReFungible(data) = data {139914141400 // check sizes1415 // check sizes1401 ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");1416 ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, Error::<T>::TokenConstDataLimitExceeded);1402 ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");1417 ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);1403 } else {1418 } else {1404 fail!("Not Re Fungible item data used to mint in Re Fungible collection.");1419 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1405 }1420 }1406 },1421 },1407 _ => { fail!("Unexpected collection type."); }1422 _ => { fail!(Error::<T>::UnexpectedCollectionType); }1408 };1423 };140914241410 Ok(())1425 Ok(())pallets/nft/src/tests.rsdiffbeforeafterboth1725 collection_id,1725 collection_id,1726 1,1726 1,1727 too_big_const_data1727 too_big_const_data1728 ), "const_data exceeded data limit.");1728 ), Error::<Test>::TokenConstDataLimitExceeded);1729 });1729 });1730}1730}173117311756 collection_id,1756 collection_id,1757 1,1757 1,1758 too_big_const_data1758 too_big_const_data1759 ), "variable_data exceeded data limit.");1759 ), Error::<Test>::TokenVariableDataLimitExceeded);1760 });1760 });1761}1761}176217621787 collection_id,1787 collection_id,1788 1,1788 1,1789 too_big_const_data1789 too_big_const_data1790 ), "const_data exceeded data limit.");1790 ), Error::<Test>::TokenConstDataLimitExceeded);1791 });1791 });1792}1792}179317931818 collection_id,1818 collection_id,1819 1,1819 1,1820 too_big_const_data1820 too_big_const_data1821 ), "variable_data exceeded data limit.");1821 ), Error::<Test>::TokenVariableDataLimitExceeded);1822 });1822 });1823}1823}1824// #endregion1824// #endregion1853 });1853 });1854}1854}18551856#[test]1857fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1858 new_test_ext().execute_with(|| {1859 default_limits();18601861 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18621863 let origin1 = Origin::signed(1);1864 1865 let data = default_nft_data();1866 create_test_item(1, &data.into());1867 1868 let variable_data = b"test set_variable_meta_data method.".to_vec();1869 assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));18701871 assert_eq!(TemplateModule::nft_item_id(collection_id, 1).variable_data, variable_data);1872 });1873}18741875#[test]1876fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1877 new_test_ext().execute_with(|| {1878 default_limits();18791880 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);18811882 let origin1 = Origin::signed(1);18831884 let data = default_re_fungible_data();1885 create_test_item(1, &data.into());18861887 let variable_data = b"test set_variable_meta_data method.".to_vec();1888 assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));18891890 assert_eq!(TemplateModule::refungible_item_id(collection_id, 1).variable_data, variable_data);1891 });1892}189318941895#[test]1896fn set_variable_meta_data_on_fungible_token_fails() {1897 new_test_ext().execute_with(|| {1898 default_limits();18991900 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);19011902 let origin1 = Origin::signed(1);19031904 let data = default_fungible_data();1905 create_test_item(1, &data.into());19061907 let variable_data = b"test set_variable_meta_data method.".to_vec();1908 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), Error::<Test>::CantStoreMetadataInFungibleTokens);1909 });1910}19111912#[test]1913fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1914 new_test_ext().execute_with(|| {1915 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1916 collection_numbers_limit: default_collection_numbers_limit(),1917 account_token_ownership_limit: 10,1918 collections_admins_limit: 5,1919 custom_data_limit: 10,1920 nft_sponsor_transfer_timeout: 15,1921 fungible_sponsor_transfer_timeout: 15,1922 refungible_sponsor_transfer_timeout: 15, 1923 }));19241925 let collection_id = create_test_collection(&CollectionMode::NFT, 1);19261927 let origin1 = Origin::signed(1);19281929 let data = default_nft_data();1930 create_test_item(1, &data.into());19311932 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1933 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1934 });1935}19361937#[test]1938fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1939 new_test_ext().execute_with(|| {1940 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1941 collection_numbers_limit: default_collection_numbers_limit(),1942 account_token_ownership_limit: 10,1943 collections_admins_limit: 5,1944 custom_data_limit: 10,1945 nft_sponsor_transfer_timeout: 15,1946 fungible_sponsor_transfer_timeout: 15,1947 refungible_sponsor_transfer_timeout: 15, 1948 }));194919501951 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);19521953 let origin1 = Origin::signed(1);19541955 let data = default_re_fungible_data();1956 create_test_item(1, &data.into());19571958 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1959 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1960 });1961}1962