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.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -264,52 +264,64 @@
decl_error! {
/// Error for non-fungible-token module.
pub enum Error for Module<T: Trait> {
- /// Total collections bound exceeded
+ /// Total collections bound exceeded.
TotalCollectionsLimitExceeded,
- /// Decimal_points parameter must be lower than 4
+ /// Decimal_points parameter must be lower than 4.
CollectionDecimalPointLimitExceeded,
- /// Collection name can not be longer than 63 char
+ /// Collection name can not be longer than 63 char.
CollectionNameLimitExceeded,
- /// Collection description can not be longer than 255 char
+ /// Collection description can not be longer than 255 char.
CollectionDescriptionLimitExceeded,
- /// Token prefix can not be longer than 15 char
+ /// Token prefix can not be longer than 15 char.
CollectionTokenPrefixLimitExceeded,
- /// This collection does not exist
+ /// This collection does not exist.
CollectionNotFound,
- /// Item not exists
+ /// Item not exists.
TokenNotFound,
- /// Arithmetic calculation overflow
+ /// Arithmetic calculation overflow.
NumOverflow,
- /// Account already has admin role
+ /// Account already has admin role.
AlreadyAdmin,
- /// You do not own this collection
+ /// You do not own this collection.
NoPermission,
- /// This address is not set as sponsor, use setCollectionSponsor first
+ /// This address is not set as sponsor, use setCollectionSponsor first.
ConfirmUnsetSponsorFail,
- /// Collection is not in mint mode
+ /// Collection is not in mint mode.
PublicMintingNotAllowed,
- /// Sender parameter and item owner must be equal
+ /// Sender parameter and item owner must be equal.
MustBeTokenOwner,
- /// Item balance not enouth
+ /// Item balance not enough.
TokenValueTooLow,
- /// Size of item is too large
+ /// Size of item is too large.
NftSizeLimitExceeded,
- /// Size of item must be 0 with fungible type
- FungibleUnexpectedParam,
/// No approve found
ApproveNotFound,
- /// Requested value more than approved
+ /// Requested value more than approved.
TokenValueNotEnough,
- /// Only approved addresses can call this method
+ /// Only approved addresses can call this method.
ApproveRequired,
- /// Address is not in white list
+ /// Address is not in white list.
AddresNotInWhiteList,
- /// Number of collection admins bound exceeded
+ /// Number of collection admins bound exceeded.
CollectionAdminsLimitExceeded,
- /// Owned tokens by a single address bound exceeded
+ /// Owned tokens by a single address bound exceeded.
AddressOwnershipLimitExceeded,
- /// Length of items properties must be greater than 0
+ /// Length of items properties must be greater than 0.
EmptyArgument,
+ /// const_data exceeded data limit.
+ TokenConstDataLimitExceeded,
+ /// variable_data exceeded data limit.
+ TokenVariableDataLimitExceeded,
+ /// Not NFT item data used to mint in NFT collection.
+ NotNftDataUsedToMintNftCollectionToken,
+ /// Not Fungible item data used to mint in Fungible collection.
+ NotFungibleDataUsedToMintFungibleCollectionToken,
+ /// Not Re Fungible item data used to mint in Re Fungible collection.
+ NotReFungibleDataUsedToMintReFungibleCollectionToken,
+ /// Unexpected collection type.
+ UnexpectedCollectionType,
+ /// Can't store metadata in fungible tokens.
+ CantStoreMetadataInFungibleTokens
}
}
@@ -1181,6 +1193,8 @@
let sender = ensure_signed(origin)?;
Self::collection_exists(collection_id)?;
+
+ ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);
// Modify permissions check
let target_collection = <Collection<T>>::get(collection_id);
@@ -1194,7 +1208,8 @@
{
CollectionMode::NFT => Self::set_nft_variable_data(collection_id, item_id, data)?,
CollectionMode::ReFungible(_) => Self::set_re_fungible_variable_data(collection_id, item_id, data)?,
- _ => ()
+ CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),
+ _ => fail!(Error::<T>::UnexpectedCollectionType)
};
Ok(())
@@ -1382,29 +1397,29 @@
CollectionMode::NFT => {
if let CreateItemData::NFT(data) = data {
// check sizes
- ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");
- ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");
+ ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, Error::<T>::TokenConstDataLimitExceeded);
+ ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);
} else {
- fail!("Not NFT item data used to mint in NFT collection.");
+ fail!(Error::<T>::NotNftDataUsedToMintNftCollectionToken);
}
},
CollectionMode::Fungible(_) => {
if let CreateItemData::Fungible(_) = data {
} else {
- fail!("Not Fungible item data used to mint in Fungible collection.");
+ fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);
}
},
CollectionMode::ReFungible(_) => {
if let CreateItemData::ReFungible(data) = data {
// check sizes
- ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");
- ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");
+ ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, Error::<T>::TokenConstDataLimitExceeded);
+ ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);
} else {
- fail!("Not Re Fungible item data used to mint in Re Fungible collection.");
+ fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);
}
},
- _ => { fail!("Unexpected collection type."); }
+ _ => { fail!(Error::<T>::UnexpectedCollectionType); }
};
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