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