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.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -221,7 +221,7 @@
fn check_nesting(
&self,
- _sender: <T>::CrossAccountId,
+ _sender: &<T>::CrossAccountId,
_from: (up_data_structs::CollectionId, TokenId),
_under: TokenId,
_budget: &dyn up_data_structs::budget::Budget,
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -2194,7 +2194,7 @@
/// * `budget` - The maximum budget that can be spent on the check.
fn check_nesting(
&self,
- sender: T::CrossAccountId,
+ sender: &T::CrossAccountId,
from: (CollectionId, TokenId),
under: TokenId,
budget: &dyn Budget,
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -335,7 +335,7 @@
fn check_nesting(
&self,
- _sender: <T>::CrossAccountId,
+ _sender: &<T>::CrossAccountId,
_from: (CollectionId, TokenId),
_under: TokenId,
_nesting_budget: &dyn Budget,
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -384,6 +384,21 @@
amount: u128,
nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
+ let depositor = from;
+ Self::transfer_internal(collection, depositor, from, to, amount, nesting_budget)
+ }
+
+ /// Transfers tokens from the `from` account to the `to` account.
+ /// The `depositor` is the account who deposits the tokens.
+ /// For instance, the nesting rules will be checked against the `depositor`'s permissions.
+ fn transfer_internal(
+ collection: &FungibleHandle<T>,
+ depositor: &T::CrossAccountId,
+ from: &T::CrossAccountId,
+ to: &T::CrossAccountId,
+ amount: u128,
+ nesting_budget: &dyn Budget,
+ ) -> DispatchResultWithPostInfo {
ensure!(
collection.limits.transfers_enabled(),
<CommonError<T>>::TransferNotAllowed,
@@ -416,7 +431,7 @@
// from != to && amount != 0
<PalletStructure<T>>::nest_if_sent_to_token(
- from.clone(),
+ depositor,
to,
collection.id,
TokenId::default(),
@@ -473,7 +488,7 @@
for (to, _) in data.iter() {
<PalletStructure<T>>::check_nesting(
- sender.clone(),
+ sender,
to,
collection.id,
TokenId::default(),
@@ -730,7 +745,8 @@
// =========
- let mut result = Self::transfer(collection, from, to, amount, nesting_budget);
+ let mut result =
+ Self::transfer_internal(collection, spender, from, to, amount, nesting_budget);
add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());
result?;
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -407,7 +407,7 @@
fn check_nesting(
&self,
- sender: T::CrossAccountId,
+ sender: &T::CrossAccountId,
from: (CollectionId, TokenId),
under: TokenId,
nesting_budget: &dyn Budget,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -718,6 +718,21 @@
token: TokenId,
nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
+ let depositor = from;
+ Self::transfer_internal(collection, depositor, from, to, token, nesting_budget)
+ }
+
+ /// Transfers an NFT from the `from` account to the `to` account.
+ /// The `depositor` is the account who deposits the NFT.
+ /// For instance, the nesting rules will be checked against the `depositor`'s permissions.
+ pub fn transfer_internal(
+ collection: &NonfungibleHandle<T>,
+ depositor: &T::CrossAccountId,
+ from: &T::CrossAccountId,
+ to: &T::CrossAccountId,
+ token: TokenId,
+ nesting_budget: &dyn Budget,
+ ) -> DispatchResultWithPostInfo {
ensure!(
collection.limits.transfers_enabled(),
<CommonError<T>>::TransferNotAllowed
@@ -754,7 +769,7 @@
};
<PalletStructure<T>>::nest_if_sent_to_token(
- from.clone(),
+ depositor,
to,
collection.id,
token,
@@ -860,7 +875,7 @@
let token = TokenId(first_token + i as u32 + 1);
<PalletStructure<T>>::check_nesting(
- sender.clone(),
+ sender,
&data.owner,
collection.id,
token,
@@ -1154,7 +1169,8 @@
// =========
// Allowance is reset in [`transfer`]
- let mut result = Self::transfer(collection, from, to, token, nesting_budget);
+ let mut result =
+ Self::transfer_internal(collection, spender, from, to, token, nesting_budget);
add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());
result
}
@@ -1183,7 +1199,7 @@
///
pub fn check_nesting(
handle: &NonfungibleHandle<T>,
- sender: T::CrossAccountId,
+ sender: &T::CrossAccountId,
from: (CollectionId, TokenId),
under: TokenId,
nesting_budget: &dyn Budget,
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -416,7 +416,7 @@
fn check_nesting(
&self,
- _sender: <T>::CrossAccountId,
+ _sender: &<T>::CrossAccountId,
_from: (CollectionId, TokenId),
_under: TokenId,
_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.rsdiffbeforeafterboth--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -300,7 +300,7 @@
///
/// - `nesting_budget`: Limit for searching parents in depth.
pub fn check_nesting(
- from: T::CrossAccountId,
+ from: &T::CrossAccountId,
under: &T::CrossAccountId,
collection_id: CollectionId,
token_id: TokenId,
@@ -317,7 +317,7 @@
///
/// - `nesting_budget`: Limit for searching parents in depth.
pub fn nest_if_sent_to_token(
- from: T::CrossAccountId,
+ from: &T::CrossAccountId,
under: &T::CrossAccountId,
collection_id: CollectionId,
token_id: TokenId,