difftreelog
feat add/remove from white list chain extension
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth843 let sender = ensure_signed(origin)?;843 let sender = ensure_signed(origin)?;844 let collection = Self::get_collection(collection_id)?;844 let collection = Self::get_collection(collection_id)?;845845 Self::check_owner_or_admin_permissions(&collection, sender)?;846 Self::toggle_white_list_internal(846847 &sender,848 &collection,847 <WhiteList<T>>::insert(collection_id, address, true);849 &address,848 850 true,851 )?;852849 Ok(())853 Ok(())850 }854 }868 let sender = ensure_signed(origin)?;872 let sender = ensure_signed(origin)?;869 let collection = Self::get_collection(collection_id)?;873 let collection = Self::get_collection(collection_id)?;874870 Self::check_owner_or_admin_permissions(&collection, sender)?;875 Self::toggle_white_list_internal(871876 &sender,872 <WhiteList<T>>::remove(collection_id, address);877 &collection,878 &address,879 false,880 )?;873881874 Ok(())882 Ok(())1851 Ok(())1859 Ok(())1852 }1860 }18611862 pub fn toggle_white_list_internal(1863 sender: &T::AccountId,1864 collection: &CollectionHandle<T>,1865 address: &T::AccountId,1866 whitelisted: bool,1867 ) -> DispatchResult {1868 Self::check_owner_or_admin_permissions(&collection, sender.clone())?;18691870 if whitelisted {1871 <WhiteList<T>>::insert(collection.id, address, true);1872 } else {1873 <WhiteList<T>>::remove(collection.id, address);1874 }18751876 Ok(())1877 }185318781854 fn is_correct_transfer(collection: &CollectionHandle<T>, recipient: &T::AccountId) -> DispatchResult {1879 fn is_correct_transfer(collection: &CollectionHandle<T>, recipient: &T::AccountId) -> DispatchResult {1855 let collection_id = collection.id;1880 let collection_id = collection.id;runtime/src/chain_extension.rsdiffbeforeafterboth67 pub data: Vec<u8>, 67 pub data: Vec<u8>, 68}68}6970#[derive(Debug, PartialEq, Encode, Decode)]71pub struct NFTExtToggleWhiteList<E: Ext> {72 pub collection_id: u32,73 pub address: <E::T as SysConfig>::AccountId,74 pub whitelisted: bool,75}697670/// The chain Extension of NFT pallet77/// The chain Extension of NFT pallet71pub struct NFTExtension;78pub struct NFTExtension;175 )?;182 )?;176 Ok(RetVal::Converging(func_id))183 Ok(RetVal::Converging(func_id))177 },184 },185 6 => {186 // Toggle whitelist187 let mut env = env.buf_in_buf_out();188 let input: NFTExtToggleWhiteList<E> = env.read_as()?;189190 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;191192 pallet_nft::Module::<C>::toggle_white_list_internal(193 &env.ext().address().clone(),194 &collection,195 &input.address,196 input.whitelisted,197 )?;198 Ok(RetVal::Converging(func_id))199 }178 _ => {200 _ => {179 panic!("Passed unknown func_id to test chain extension: {}", func_id);201 panic!("Passed unknown func_id to test chain extension: {}", func_id);180 }202 }