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.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.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.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,