git.delta.rocks / unique-network / refs/commits / b3fda41c65ef

difftreelog

feat add/remove from white list chain extension

Yaroslav Bolyukin2021-05-06parent: #13a0a85.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
843 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)?;
845
845 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 )?;
852
849 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)?;
874
870 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 )?;
873881
874 Ok(())882 Ok(())
1851 Ok(())1859 Ok(())
1852 }1860 }
1861
1862 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())?;
1869
1870 if whitelisted {
1871 <WhiteList<T>>::insert(collection.id, address, true);
1872 } else {
1873 <WhiteList<T>>::remove(collection.id, address);
1874 }
1875
1876 Ok(())
1877 }
18531878
1854 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;
modifiedruntime/src/chain_extension.rsdiffbeforeafterboth
67 pub data: Vec<u8>, 67 pub data: Vec<u8>,
68}68}
69
70#[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}
6976
70/// The chain Extension of NFT pallet77/// The chain Extension of NFT pallet
71pub 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 whitelist
187 let mut env = env.buf_in_buf_out();
188 let input: NFTExtToggleWhiteList<E> = env.read_as()?;
189
190 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
191
192 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 }