git.delta.rocks / unique-network / refs/commits / 7e808da4a3d9

difftreelog

fix revert set_allowance

Daniel Shiposha2022-06-05parent: #e099d8f.patch.diff
in: master

8 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1298 spender: T::CrossAccountId,1298 spender: T::CrossAccountId,
1299 token: TokenId,1299 token: TokenId,
1300 amount: u128,1300 amount: u128,
1301 nesting_budget: &dyn Budget,
1302 ) -> DispatchResultWithPostInfo;1301 ) -> DispatchResultWithPostInfo;
1303 fn transfer_from(1302 fn transfer_from(
1304 &self,1303 &self,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
226 spender: T::CrossAccountId,226 spender: T::CrossAccountId,
227 token: TokenId,227 token: TokenId,
228 amount: u128,228 amount: u128,
229 _nesting_budget: &dyn Budget,
230 ) -> DispatchResultWithPostInfo {229 ) -> DispatchResultWithPostInfo {
231 ensure!(230 ensure!(
232 token == TokenId::default(),231 token == TokenId::default(),
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
308 spender: T::CrossAccountId,308 spender: T::CrossAccountId,
309 token: TokenId,309 token: TokenId,
310 amount: u128,310 amount: u128,
311 nesting_budget: &dyn Budget,
312 ) -> DispatchResultWithPostInfo {311 ) -> DispatchResultWithPostInfo {
313 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);312 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
314313
315 with_weight(314 with_weight(
316 if amount == 1 {315 if amount == 1 {
317 <Pallet<T>>::set_allowance(self, &sender, token, Some(&spender), nesting_budget)316 <Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))
318 } else {317 } else {
319 <Pallet<T>>::set_allowance(self, &sender, token, None, nesting_budget)318 <Pallet<T>>::set_allowance(self, &sender, token, None)
320 },319 },
321 <CommonWeights<T>>::approve(),320 <CommonWeights<T>>::approve(),
322 )321 )
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
269 let caller = T::CrossAccountId::from_eth(caller);269 let caller = T::CrossAccountId::from_eth(caller);
270 let approved = T::CrossAccountId::from_eth(approved);270 let approved = T::CrossAccountId::from_eth(approved);
271 let token = token_id.try_into()?;271 let token = token_id.try_into()?;
272 let budget = self
273 .recorder
274 .weight_calls_budget(<StructureWeight<T>>::find_parent());
275272
276 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved), &budget)273 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))
277 .map_err(dispatch_to_evm::<T>)?;274 .map_err(dispatch_to_evm::<T>)?;
278 Ok(())275 Ok(())
279 }276 }
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
878 sender: &T::CrossAccountId,878 sender: &T::CrossAccountId,
879 token: TokenId,879 token: TokenId,
880 spender: Option<&T::CrossAccountId>,880 spender: Option<&T::CrossAccountId>,
881 nesting_budget: &dyn Budget,
882 ) -> DispatchResult {881 ) -> DispatchResult {
883 if collection.permissions.access() == AccessMode::AllowList {882 if collection.permissions.access() == AccessMode::AllowList {
884 collection.check_allowlist(sender)?;883 collection.check_allowlist(sender)?;
891 <PalletCommon<T>>::ensure_correct_receiver(spender)?;890 <PalletCommon<T>>::ensure_correct_receiver(spender)?;
892 }891 }
893892
894 let is_owned = <PalletStructure<T>>::check_indirectly_owned(893 let token_data =
895 sender.clone(),
896 collection.id,
897 token,
898 None,
899 nesting_budget
900 )?;894 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
901
902 if !is_owned {895 if &token_data.owner != sender {
903 ensure!(896 ensure!(
904 collection.ignores_owned_amount(sender),897 collection.ignores_owned_amount(sender),
905 <CommonError<T>>::CantApproveMoreThanOwned898 <CommonError<T>>::CantApproveMoreThanOwned
926 // `from`, `to` checked in [`transfer`]919 // `from`, `to` checked in [`transfer`]
927 collection.check_allowlist(spender)?;920 collection.check_allowlist(spender)?;
928 }921 }
929 if <Allowance<T>>::get((collection.id, token)).as_ref() == Some(spender) {
930 return Ok(());
931 }
932 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {922 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {
933 // TODO: should collection owner be allowed to perform this transfer?923 // TODO: should collection owner be allowed to perform this transfer?
934 ensure!(924 ensure!(
943 );933 );
944 return Ok(());934 return Ok(());
945 }935 }
936 if <Allowance<T>>::get((collection.id, token)).as_ref() == Some(spender) {
937 return Ok(());
938 }
946 ensure!(939 ensure!(
947 collection.ignores_allowance(spender),940 collection.ignores_allowance(spender),
948 <CommonError<T>>::ApprovedValueTooLow941 <CommonError<T>>::ApprovedValueTooLow
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
414 let is_approval_required = cross_sender != spender;414 let is_approval_required = cross_sender != spender;
415415
416 if is_approval_required {416 if is_approval_required {
417 <PalletNft<T>>::set_allowance(417 // FIXME
418 &collection,418 // <PalletNft<T>>::set_allowance(
419 &cross_sender,419 // &collection,
420 nft_id,420 // &cross_sender,
421 Some(&spender),421 // nft_id,
422 &budget422 // Some(&spender),
423 ).map_err(Self::map_common_err_to_proxy)?;423 // &budget
424 // ).map_err(Self::map_common_err_to_proxy)?;
424425
425 return Ok(());426 return Ok(());
426 }427 }
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
254 spender: T::CrossAccountId,254 spender: T::CrossAccountId,
255 token: TokenId,255 token: TokenId,
256 amount: u128,256 amount: u128,
257 _nesting_budget: &dyn Budget,
258 ) -> DispatchResultWithPostInfo {257 ) -> DispatchResultWithPostInfo {
259 with_weight(258 with_weight(
260 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),259 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
815 #[transactional]815 #[transactional]
816 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {816 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {
817 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);817 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
818 let budget = budget::Value::new(NESTING_BUDGET);
819818
820 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount, &budget))819 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))
821 }820 }
822821
823 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.822 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.