difftreelog
fix separate depositor from sender in transfer_internal (#1013)
in: master
* fix: transfer-from * fix: remove Option from nester type * fix: check_nesting comment * fix: rename nester to depositor, add docs
9 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth221221222 fn check_nesting(222 fn check_nesting(223 &self,223 &self,224 _sender: <T>::CrossAccountId,224 _sender: &<T>::CrossAccountId,225 _from: (up_data_structs::CollectionId, TokenId),225 _from: (up_data_structs::CollectionId, TokenId),226 _under: TokenId,226 _under: TokenId,227 _budget: &dyn up_data_structs::budget::Budget,227 _budget: &dyn up_data_structs::budget::Budget,pallets/common/src/lib.rsdiffbeforeafterboth2194 /// * `budget` - The maximum budget that can be spent on the check.2194 /// * `budget` - The maximum budget that can be spent on the check.2195 fn check_nesting(2195 fn check_nesting(2196 &self,2196 &self,2197 sender: T::CrossAccountId,2197 sender: &T::CrossAccountId,2198 from: (CollectionId, TokenId),2198 from: (CollectionId, TokenId),2199 under: TokenId,2199 under: TokenId,2200 budget: &dyn Budget,2200 budget: &dyn Budget,pallets/fungible/src/common.rsdiffbeforeafterboth335335336 fn check_nesting(336 fn check_nesting(337 &self,337 &self,338 _sender: <T>::CrossAccountId,338 _sender: &<T>::CrossAccountId,339 _from: (CollectionId, TokenId),339 _from: (CollectionId, TokenId),340 _under: TokenId,340 _under: TokenId,341 _nesting_budget: &dyn Budget,341 _nesting_budget: &dyn Budget,pallets/fungible/src/lib.rsdiffbeforeafterboth383 to: &T::CrossAccountId,383 to: &T::CrossAccountId,384 amount: u128,384 amount: u128,385 nesting_budget: &dyn Budget,385 nesting_budget: &dyn Budget,386 ) -> DispatchResultWithPostInfo {386 ) -> DispatchResultWithPostInfo {387 let depositor = from;388 Self::transfer_internal(collection, depositor, from, to, amount, nesting_budget)389 }390391 /// Transfers tokens from the `from` account to the `to` account.392 /// The `depositor` is the account who deposits the tokens.393 /// For instance, the nesting rules will be checked against the `depositor`'s permissions.394 fn transfer_internal(395 collection: &FungibleHandle<T>,396 depositor: &T::CrossAccountId,397 from: &T::CrossAccountId,398 to: &T::CrossAccountId,399 amount: u128,400 nesting_budget: &dyn Budget,401 ) -> DispatchResultWithPostInfo {387 ensure!(402 ensure!(388 collection.limits.transfers_enabled(),403 collection.limits.transfers_enabled(),389 <CommonError<T>>::TransferNotAllowed,404 <CommonError<T>>::TransferNotAllowed,416 // from != to && amount != 0431 // from != to && amount != 0417432418 <PalletStructure<T>>::nest_if_sent_to_token(433 <PalletStructure<T>>::nest_if_sent_to_token(419 from.clone(),434 depositor,420 to,435 to,421 collection.id,436 collection.id,422 TokenId::default(),437 TokenId::default(),473488474 for (to, _) in data.iter() {489 for (to, _) in data.iter() {475 <PalletStructure<T>>::check_nesting(490 <PalletStructure<T>>::check_nesting(476 sender.clone(),491 sender,477 to,492 to,478 collection.id,493 collection.id,479 TokenId::default(),494 TokenId::default(),730745731 // =========746 // =========732747733 let mut result = Self::transfer(collection, from, to, amount, nesting_budget);748 let mut result =749 Self::transfer_internal(collection, spender, from, to, amount, nesting_budget);734 add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());750 add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());735 result?;751 result?;736752pallets/nonfungible/src/common.rsdiffbeforeafterboth407407408 fn check_nesting(408 fn check_nesting(409 &self,409 &self,410 sender: T::CrossAccountId,410 sender: &T::CrossAccountId,411 from: (CollectionId, TokenId),411 from: (CollectionId, TokenId),412 under: TokenId,412 under: TokenId,413 nesting_budget: &dyn Budget,413 nesting_budget: &dyn Budget,pallets/nonfungible/src/lib.rsdiffbeforeafterboth717 to: &T::CrossAccountId,717 to: &T::CrossAccountId,718 token: TokenId,718 token: TokenId,719 nesting_budget: &dyn Budget,719 nesting_budget: &dyn Budget,720 ) -> DispatchResultWithPostInfo {720 ) -> DispatchResultWithPostInfo {721 let depositor = from;722 Self::transfer_internal(collection, depositor, from, to, token, nesting_budget)723 }724725 /// Transfers an NFT from the `from` account to the `to` account.726 /// The `depositor` is the account who deposits the NFT.727 /// For instance, the nesting rules will be checked against the `depositor`'s permissions.728 pub fn transfer_internal(729 collection: &NonfungibleHandle<T>,730 depositor: &T::CrossAccountId,731 from: &T::CrossAccountId,732 to: &T::CrossAccountId,733 token: TokenId,734 nesting_budget: &dyn Budget,735 ) -> DispatchResultWithPostInfo {721 ensure!(736 ensure!(722 collection.limits.transfers_enabled(),737 collection.limits.transfers_enabled(),723 <CommonError<T>>::TransferNotAllowed738 <CommonError<T>>::TransferNotAllowed754 };769 };755770756 <PalletStructure<T>>::nest_if_sent_to_token(771 <PalletStructure<T>>::nest_if_sent_to_token(757 from.clone(),772 depositor,758 to,773 to,759 collection.id,774 collection.id,760 token,775 token,860 let token = TokenId(first_token + i as u32 + 1);875 let token = TokenId(first_token + i as u32 + 1);861876862 <PalletStructure<T>>::check_nesting(877 <PalletStructure<T>>::check_nesting(863 sender.clone(),878 sender,864 &data.owner,879 &data.owner,865 collection.id,880 collection.id,866 token,881 token,1154 // =========1169 // =========115511701156 // Allowance is reset in [`transfer`]1171 // Allowance is reset in [`transfer`]1157 let mut result = Self::transfer(collection, from, to, token, nesting_budget);1172 let mut result =1173 Self::transfer_internal(collection, spender, from, to, token, nesting_budget);1158 add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());1174 add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());1159 result1175 result1160 }1176 }1183 ///1199 ///1184 pub fn check_nesting(1200 pub fn check_nesting(1185 handle: &NonfungibleHandle<T>,1201 handle: &NonfungibleHandle<T>,1186 sender: T::CrossAccountId,1202 sender: &T::CrossAccountId,1187 from: (CollectionId, TokenId),1203 from: (CollectionId, TokenId),1188 under: TokenId,1204 under: TokenId,1189 nesting_budget: &dyn Budget,1205 nesting_budget: &dyn Budget,pallets/refungible/src/common.rsdiffbeforeafterboth416416417 fn check_nesting(417 fn check_nesting(418 &self,418 &self,419 _sender: <T>::CrossAccountId,419 _sender: &<T>::CrossAccountId,420 _from: (CollectionId, TokenId),420 _from: (CollectionId, TokenId),421 _under: TokenId,421 _under: TokenId,422 _nesting_budget: &dyn Budget,422 _nesting_budget: &dyn Budget,pallets/refungible/src/lib.rsdiffbeforeafterboth614 token: TokenId,614 token: TokenId,615 amount: u128,615 amount: u128,616 nesting_budget: &dyn Budget,616 nesting_budget: &dyn Budget,617 ) -> DispatchResult {617 ) -> DispatchResult {618 let depositor = from;619 Self::transfer_internal(620 collection,621 depositor,622 from,623 to,624 token,625 amount,626 nesting_budget,627 )628 }629630 /// Transfers RFT tokens from the `from` account to the `to` account.631 /// The `depositor` is the account who deposits the tokens.632 /// For instance, the nesting rules will be checked against the `depositor`'s permissions.633 pub fn transfer_internal(634 collection: &RefungibleHandle<T>,635 depositor: &T::CrossAccountId,636 from: &T::CrossAccountId,637 to: &T::CrossAccountId,638 token: TokenId,639 amount: u128,640 nesting_budget: &dyn Budget,641 ) -> DispatchResult {618 ensure!(642 ensure!(619 collection.limits.transfers_enabled(),643 collection.limits.transfers_enabled(),620 <CommonError<T>>::TransferNotAllowed644 <CommonError<T>>::TransferNotAllowed683 // from != to && amount != 0707 // from != to && amount != 0684708685 <PalletStructure<T>>::nest_if_sent_to_token(709 <PalletStructure<T>>::nest_if_sent_to_token(686 from.clone(),710 depositor,687 to,711 to,688 collection.id,712 collection.id,689 token,713 token,847 let token_id = TokenId(first_token_id + i as u32 + 1);871 let token_id = TokenId(first_token_id + i as u32 + 1);848 for (to, _) in token.users.iter() {872 for (to, _) in token.users.iter() {849 <PalletStructure<T>>::check_nesting(873 <PalletStructure<T>>::check_nesting(850 sender.clone(),874 sender,851 to,875 to,852 collection.id,876 collection.id,853 token_id,877 token_id,114611701147 // =========1171 // =========114811721149 Self::transfer(collection, from, to, token, amount, nesting_budget)?;1173 Self::transfer_internal(collection, spender, from, to, token, amount, nesting_budget)?;1150 if let Some(allowance) = allowance {1174 if let Some(allowance) = allowance {1151 Self::set_allowance_unchecked(collection, from, spender, token, allowance);1175 Self::set_allowance_unchecked(collection, from, spender, token, allowance);1152 }1176 }pallets/structure/src/lib.rsdiffbeforeafterboth300 ///300 ///301 /// - `nesting_budget`: Limit for searching parents in depth.301 /// - `nesting_budget`: Limit for searching parents in depth.302 pub fn check_nesting(302 pub fn check_nesting(303 from: T::CrossAccountId,303 from: &T::CrossAccountId,304 under: &T::CrossAccountId,304 under: &T::CrossAccountId,305 collection_id: CollectionId,305 collection_id: CollectionId,306 token_id: TokenId,306 token_id: TokenId,317 ///317 ///318 /// - `nesting_budget`: Limit for searching parents in depth.318 /// - `nesting_budget`: Limit for searching parents in depth.319 pub fn nest_if_sent_to_token(319 pub fn nest_if_sent_to_token(320 from: T::CrossAccountId,320 from: &T::CrossAccountId,321 under: &T::CrossAccountId,321 under: &T::CrossAccountId,322 collection_id: CollectionId,322 collection_id: CollectionId,323 token_id: TokenId,323 token_id: TokenId,