difftreelog
refactor remove id from collection info
in: master
3 files changed
node/src/chain_spec.rsdiffbeforeafterboth183 collection_id: vec![(183 collection_id: vec![(184 1,184 1,185 Collection {185 Collection {186 id: 1,187 owner: get_account_id_from_seed::<sr25519::Public>("Alice"),186 owner: get_account_id_from_seed::<sr25519::Public>("Alice"),188 mode: CollectionMode::NFT,187 mode: CollectionMode::NFT,189 access: AccessMode::Normal,188 access: AccessMode::Normal,pallets/nft/src/lib.rsdiffbeforeafterboth13#[cfg(feature = "std")]13#[cfg(feature = "std")]14pub use serde::*;14pub use serde::*;151516use core::ops::{Deref, DerefMut};16use codec::{Decode, Encode};17use codec::{Decode, Encode};17pub use frame_support::{18pub use frame_support::{18 construct_runtime, decl_event, decl_module, decl_storage, decl_error,19 construct_runtime, decl_event, decl_module, decl_storage, decl_error,126#[derive(Encode, Decode, Clone, PartialEq)]127#[derive(Encode, Decode, Clone, PartialEq)]127#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]128#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]128pub struct Collection<T: Config> {129pub struct Collection<T: Config> {129 pub id: CollectionId,130 pub owner: T::AccountId,130 pub owner: T::AccountId,131 pub mode: CollectionMode,131 pub mode: CollectionMode,132 pub access: AccessMode,132 pub access: AccessMode,144 pub const_on_chain_schema: Vec<u8>, //144 pub const_on_chain_schema: Vec<u8>, //145}145}146147pub struct CollectionHandle<T: Config> {148 pub id: CollectionId,149 collection: Collection<T>,150}151152impl<T: Config> Deref for CollectionHandle<T> {153 type Target = Collection<T>;154155 fn deref(&self) -> &Self::Target {156 &self.collection157 }158}159160impl<T: Config> DerefMut for CollectionHandle<T> {161 fn deref_mut(&mut self) -> &mut Self::Target {162 &mut self.collection163 }164}146165147#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]166#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]148#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]167#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]617636618 // Create new collection637 // Create new collection619 let new_collection = Collection {638 let new_collection = Collection {620 id: next_id,621 owner: who.clone(),639 owner: who.clone(),622 name: collection_name,640 name: collection_name,623 mode: mode.clone(),641 mode: mode.clone(),1579 let sender = ensure_signed(origin)?;1597 let sender = ensure_signed(origin)?;1580 let mut target_collection = Self::get_collection(collection_id)?;1598 let mut target_collection = Self::get_collection(collection_id)?;1581 Self::check_owner_permissions(&target_collection, sender.clone())?;1599 Self::check_owner_permissions(&target_collection, sender.clone())?;1582 let old_limits = target_collection.limits;1600 let old_limits = &target_collection.limits;1583 let chain_limits = ChainLimit::get();1601 let chain_limits = ChainLimit::get();158416021585 // collection bounds1603 // collection bounds160816261609impl<T: Config> Module<T> {1627impl<T: Config> Module<T> {161016281611 pub fn transfer_internal(sender: T::AccountId, recipient: T::AccountId, target_collection: &Collection<T>, item_id: TokenId, value: u128) -> DispatchResult {1629 pub fn transfer_internal(sender: T::AccountId, recipient: T::AccountId, target_collection: &CollectionHandle<T>, item_id: TokenId, value: u128) -> DispatchResult {1612 // Limits check1630 // Limits check1613 Self::is_correct_transfer(target_collection, &recipient)?;1631 Self::is_correct_transfer(target_collection, &recipient)?;161416321636 }1654 }16371655163816561639 fn is_correct_transfer(collection: &Collection<T>, recipient: &T::AccountId) -> DispatchResult {1657 fn is_correct_transfer(collection: &CollectionHandle<T>, recipient: &T::AccountId) -> DispatchResult {1640 let collection_id = collection.id;1658 let collection_id = collection.id;164116591642 // check token limit and account token limit1660 // check token limit and account token limit1646 Ok(())1664 Ok(())1647 }1665 }164816661649 fn can_create_items_in_collection(collection: &Collection<T>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {1667 fn can_create_items_in_collection(collection: &CollectionHandle<T>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {1650 let collection_id = collection.id;1668 let collection_id = collection.id;165116691652 // check token limit and account token limit1670 // check token limit and account token limit1664 Ok(())1682 Ok(())1665 }1683 }166616841667 fn validate_create_item_args(target_collection: &Collection<T>, data: &CreateItemData) -> DispatchResult {1685 fn validate_create_item_args(target_collection: &CollectionHandle<T>, data: &CreateItemData) -> DispatchResult {1668 match target_collection.mode1686 match target_collection.mode1669 {1687 {1670 CollectionMode::NFT => {1688 CollectionMode::NFT => {1702 Ok(())1720 Ok(())1703 }1721 }170417221705 fn create_item_no_validation(collection: &Collection<T>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1723 fn create_item_no_validation(collection: &CollectionHandle<T>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1706 let collection_id = collection.id;1724 let collection_id = collection.id;170717251708 match data1726 match data1739 Ok(())1757 Ok(())1740 }1758 }174117591742 fn add_fungible_item(collection: &Collection<T>, owner: &T::AccountId, value: u128) -> DispatchResult {1760 fn add_fungible_item(collection: &CollectionHandle<T>, owner: &T::AccountId, value: u128) -> DispatchResult {1743 let collection_id = collection.id;1761 let collection_id = collection.id;174417621745 // Does new owner already have an account?1763 // Does new owner already have an account?1763 Ok(())1781 Ok(())1764 }1782 }176517831766 fn add_refungible_item(collection: &Collection<T>, item: ReFungibleItemType<T::AccountId>) -> DispatchResult {1784 fn add_refungible_item(collection: &CollectionHandle<T>, item: ReFungibleItemType<T::AccountId>) -> DispatchResult {1767 let collection_id = collection.id;1785 let collection_id = collection.id;176817861769 let current_index = <ItemListIndex>::get(collection_id)1787 let current_index = <ItemListIndex>::get(collection_id)1788 Ok(())1806 Ok(())1789 }1807 }179018081791 fn add_nft_item(collection: &Collection<T>, item: NftItemType<T::AccountId>) -> DispatchResult {1809 fn add_nft_item(collection: &CollectionHandle<T>, item: NftItemType<T::AccountId>) -> DispatchResult {1792 let collection_id = collection.id;1810 let collection_id = collection.id;179318111794 let current_index = <ItemListIndex>::get(collection_id)1812 let current_index = <ItemListIndex>::get(collection_id)1811 }1829 }181218301813 fn burn_refungible_item(1831 fn burn_refungible_item(1814 collection: &Collection<T>,1832 collection: &CollectionHandle<T>,1815 item_id: TokenId,1833 item_id: TokenId,1816 owner: &T::AccountId,1834 owner: &T::AccountId,1817 ) -> DispatchResult {1835 ) -> DispatchResult {1857 Ok(())1875 Ok(())1858 }1876 }185918771860 fn burn_nft_item(collection: &Collection<T>, item_id: TokenId) -> DispatchResult {1878 fn burn_nft_item(collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {1861 let collection_id = collection.id;1879 let collection_id = collection.id;186218801863 ensure!(1881 ensure!(1878 Ok(())1896 Ok(())1879 }1897 }188018981881 fn burn_fungible_item(owner: &T::AccountId, collection: &Collection<T>, value: u128) -> DispatchResult {1899 fn burn_fungible_item(owner: &T::AccountId, collection: &CollectionHandle<T>, value: u128) -> DispatchResult {1882 let collection_id = collection.id;1900 let collection_id = collection.id;188319011884 ensure!(1902 ensure!(1905 Ok(())1923 Ok(())1906 }1924 }190719251908 pub fn get_collection(collection_id: CollectionId) -> Result<Collection<T>, sp_runtime::DispatchError> {1926 pub fn get_collection(collection_id: CollectionId) -> Result<CollectionHandle<T>, sp_runtime::DispatchError> {1909 Ok(<CollectionById<T>>::get(collection_id)1927 Ok(<CollectionById<T>>::get(collection_id)1928 .map(|collection| CollectionHandle {1929 id: collection_id,1930 collection1931 })1910 .ok_or(Error::<T>::CollectionNotFound)?)1932 .ok_or(Error::<T>::CollectionNotFound)?)1911 }1933 }191219341913 fn save_collection(collection: Collection<T>) {1935 fn save_collection(collection: CollectionHandle<T>) {1914 <CollectionById<T>>::insert(collection.id, collection);1936 <CollectionById<T>>::insert(collection.id, collection.collection);1915 }1937 }191619381917 fn check_owner_permissions(target_collection: &Collection<T>, subject: T::AccountId) -> DispatchResult {1939 fn check_owner_permissions(target_collection: &CollectionHandle<T>, subject: T::AccountId) -> DispatchResult {1918 ensure!(1940 ensure!(1919 subject == target_collection.owner,1941 subject == target_collection.owner,1920 Error::<T>::NoPermission1942 Error::<T>::NoPermission1923 Ok(())1945 Ok(())1924 }1946 }192519471926 fn is_owner_or_admin_permissions(collection: &Collection<T>, subject: T::AccountId) -> bool {1948 fn is_owner_or_admin_permissions(collection: &CollectionHandle<T>, subject: T::AccountId) -> bool {1927 let mut result: bool = subject == collection.owner;1949 let mut result: bool = subject == collection.owner;1928 let exists = <AdminList<T>>::contains_key(collection.id);1950 let exists = <AdminList<T>>::contains_key(collection.id);192919511937 }1959 }193819601939 fn check_owner_or_admin_permissions(1961 fn check_owner_or_admin_permissions(1940 collection: &Collection<T>,1962 collection: &CollectionHandle<T>,1941 subject: T::AccountId,1963 subject: T::AccountId,1942 ) -> DispatchResult {1964 ) -> DispatchResult {1943 let result = Self::is_owner_or_admin_permissions(collection, subject.clone());1965 let result = Self::is_owner_or_admin_permissions(collection, subject.clone());195119731952 fn owned_amount(1974 fn owned_amount(1953 subject: T::AccountId,1975 subject: T::AccountId,1954 target_collection: &Collection<T>,1976 target_collection: &CollectionHandle<T>,1955 item_id: TokenId,1977 item_id: TokenId,1956 ) -> Option<u128> {1978 ) -> Option<u128> {1957 let collection_id = target_collection.id;1979 let collection_id = target_collection.id;1979 }2001 }1980 }2002 }198120031982 fn is_item_owner(subject: T::AccountId, target_collection: &Collection<T>, item_id: TokenId) -> bool {2004 fn is_item_owner(subject: T::AccountId, target_collection: &CollectionHandle<T>, item_id: TokenId) -> bool {1983 let collection_id = target_collection.id;2005 let collection_id = target_collection.id;198420061985 match target_collection.mode {2007 match target_collection.mode {1999 }2021 }2000 }2022 }200120232002 fn check_white_list(collection: &Collection<T>, address: &T::AccountId) -> DispatchResult {2024 fn check_white_list(collection: &CollectionHandle<T>, address: &T::AccountId) -> DispatchResult {2003 let collection_id = collection.id;2025 let collection_id = collection.id;200420262005 let mes = Error::<T>::AddresNotInWhiteList;2027 let mes = Error::<T>::AddresNotInWhiteList;2011 /// Check if token exists. In case of Fungible, check if there is an entry for 2033 /// Check if token exists. In case of Fungible, check if there is an entry for 2012 /// the owner in fungible balances double map2034 /// the owner in fungible balances double map2013 fn token_exists(2035 fn token_exists(2014 target_collection: &Collection<T>,2036 target_collection: &CollectionHandle<T>,2015 item_id: TokenId,2037 item_id: TokenId,2016 owner: &T::AccountId2038 owner: &T::AccountId2017 ) -> DispatchResult {2039 ) -> DispatchResult {2029 }2051 }203020522031 fn transfer_fungible(2053 fn transfer_fungible(2032 collection: &Collection<T>,2054 collection: &CollectionHandle<T>,2033 value: u128,2055 value: u128,2034 owner: &T::AccountId,2056 owner: &T::AccountId,2035 recipient: &T::AccountId,2057 recipient: &T::AccountId,2059 }2081 }206020822061 fn transfer_refungible(2083 fn transfer_refungible(2062 collection: &Collection<T>,2084 collection: &CollectionHandle<T>,2063 item_id: TokenId,2085 item_id: TokenId,2064 value: u128,2086 value: u128,2065 owner: T::AccountId,2087 owner: T::AccountId,2142 }2164 }214321652144 fn transfer_nft(2166 fn transfer_nft(2145 collection: &Collection<T>,2167 collection: &CollectionHandle<T>,2146 item_id: TokenId,2168 item_id: TokenId,2147 sender: T::AccountId,2169 sender: T::AccountId,2148 new_owner: T::AccountId,2170 new_owner: T::AccountId,2180 }2202 }2181 2203 2182 fn set_re_fungible_variable_data(2204 fn set_re_fungible_variable_data(2183 collection: &Collection<T>,2205 collection: &CollectionHandle<T>,2184 item_id: TokenId,2206 item_id: TokenId,2185 data: Vec<u8>2207 data: Vec<u8>2186 ) -> DispatchResult {2208 ) -> DispatchResult {2195 }2217 }219622182197 fn set_nft_variable_data(2219 fn set_nft_variable_data(2198 collection: &Collection<T>,2220 collection: &CollectionHandle<T>,2199 item_id: TokenId,2221 item_id: TokenId,2200 data: Vec<u8>2222 data: Vec<u8>2201 ) -> DispatchResult {2223 ) -> DispatchResult {runtime_types.jsondiffbeforeafterboth32 "VariableData": "Vec<u8>"32 "VariableData": "Vec<u8>"33 },33 },34 "Collection": {34 "Collection": {35 "Id": "CollectionId",36 "Owner": "AccountId",35 "Owner": "AccountId",37 "Mode": "CollectionMode",36 "Mode": "CollectionMode",38 "Access": "AccessMode",37 "Access": "AccessMode",