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.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.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.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -615,6 +615,30 @@
amount: u128,
nesting_budget: &dyn Budget,
) -> DispatchResult {
+ let depositor = from;
+ Self::transfer_internal(
+ collection,
+ depositor,
+ from,
+ to,
+ token,
+ amount,
+ nesting_budget,
+ )
+ }
+
+ /// Transfers RFT 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.
+ pub fn transfer_internal(
+ collection: &RefungibleHandle<T>,
+ depositor: &T::CrossAccountId,
+ from: &T::CrossAccountId,
+ to: &T::CrossAccountId,
+ token: TokenId,
+ amount: u128,
+ nesting_budget: &dyn Budget,
+ ) -> DispatchResult {
ensure!(
collection.limits.transfers_enabled(),
<CommonError<T>>::TransferNotAllowed
@@ -683,7 +707,7 @@
// from != to && amount != 0
<PalletStructure<T>>::nest_if_sent_to_token(
- from.clone(),
+ depositor,
to,
collection.id,
token,
@@ -847,7 +871,7 @@
let token_id = TokenId(first_token_id + i as u32 + 1);
for (to, _) in token.users.iter() {
<PalletStructure<T>>::check_nesting(
- sender.clone(),
+ sender,
to,
collection.id,
token_id,
@@ -1146,7 +1170,7 @@
// =========
- Self::transfer(collection, from, to, token, amount, nesting_budget)?;
+ Self::transfer_internal(collection, spender, from, to, token, amount, nesting_budget)?;
if let Some(allowance) = allowance {
Self::set_allowance_unchecked(collection, from, spender, token, allowance);
}
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,