difftreelog
fix forbid non-1 tokenid in native fungibles (#1015)
in: master
* fix: native fungibles collection * refactor: move FungibleItemsHaveNoId to pallet-common
6 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth1use alloc::{vec, vec::Vec};1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;2use core::marker::PhantomData;334use frame_support::{fail, weights::Weight};4use frame_support::{ensure, fail, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{CommonCollectionOperations, CommonWeightInfo};6use pallet_common::{CommonCollectionOperations, CommonWeightInfo, Error as CommonError};7use up_data_structs::TokenId;7use up_data_structs::TokenId;889use crate::{Config, NativeFungibleHandle, Pallet};9use crate::{Config, NativeFungibleHandle, Pallet};77 _data: up_data_structs::CreateItemData,77 _data: up_data_structs::CreateItemData,78 _nesting_budget: &dyn up_data_structs::budget::Budget,78 _nesting_budget: &dyn up_data_structs::budget::Budget,79 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {79 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {80 fail!(<pallet_common::Error<T>>::UnsupportedOperation);80 fail!(<CommonError<T>>::UnsupportedOperation);81 }81 }828283 fn create_multiple_items(83 fn create_multiple_items(87 _data: Vec<up_data_structs::CreateItemData>,87 _data: Vec<up_data_structs::CreateItemData>,88 _nesting_budget: &dyn up_data_structs::budget::Budget,88 _nesting_budget: &dyn up_data_structs::budget::Budget,89 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {89 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {90 fail!(<pallet_common::Error<T>>::UnsupportedOperation);90 fail!(<CommonError<T>>::UnsupportedOperation);91 }91 }929293 fn create_multiple_items_ex(93 fn create_multiple_items_ex(96 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,96 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,97 _nesting_budget: &dyn up_data_structs::budget::Budget,97 _nesting_budget: &dyn up_data_structs::budget::Budget,98 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {98 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {99 fail!(<pallet_common::Error<T>>::UnsupportedOperation);99 fail!(<CommonError<T>>::UnsupportedOperation);100 }100 }101101102 fn burn_item(102 fn burn_item(105 _token: TokenId,105 _token: TokenId,106 _amount: u128,106 _amount: u128,107 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {107 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {108 fail!(<pallet_common::Error<T>>::UnsupportedOperation);108 fail!(<CommonError<T>>::UnsupportedOperation);109 }109 }110110111 fn set_collection_properties(111 fn set_collection_properties(112 &self,112 &self,113 _sender: <T>::CrossAccountId,113 _sender: <T>::CrossAccountId,114 _properties: Vec<up_data_structs::Property>,114 _properties: Vec<up_data_structs::Property>,115 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {115 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {116 fail!(<pallet_common::Error<T>>::UnsupportedOperation);116 fail!(<CommonError<T>>::UnsupportedOperation);117 }117 }118118119 fn delete_collection_properties(119 fn delete_collection_properties(120 &self,120 &self,121 _sender: &<T>::CrossAccountId,121 _sender: &<T>::CrossAccountId,122 _property_keys: Vec<up_data_structs::PropertyKey>,122 _property_keys: Vec<up_data_structs::PropertyKey>,123 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {123 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {124 fail!(<pallet_common::Error<T>>::UnsupportedOperation);124 fail!(<CommonError<T>>::UnsupportedOperation);125 }125 }126126127 fn set_token_properties(127 fn set_token_properties(131 _properties: Vec<up_data_structs::Property>,131 _properties: Vec<up_data_structs::Property>,132 _budget: &dyn up_data_structs::budget::Budget,132 _budget: &dyn up_data_structs::budget::Budget,133 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {133 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {134 fail!(<pallet_common::Error<T>>::UnsupportedOperation);134 fail!(<CommonError<T>>::UnsupportedOperation);135 }135 }136136137 fn delete_token_properties(137 fn delete_token_properties(141 _property_keys: Vec<up_data_structs::PropertyKey>,141 _property_keys: Vec<up_data_structs::PropertyKey>,142 _budget: &dyn up_data_structs::budget::Budget,142 _budget: &dyn up_data_structs::budget::Budget,143 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {143 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {144 fail!(<pallet_common::Error<T>>::UnsupportedOperation);144 fail!(<CommonError<T>>::UnsupportedOperation);145 }145 }146146147 fn get_token_properties_raw(147 fn get_token_properties_raw(161 _sender: &<T>::CrossAccountId,161 _sender: &<T>::CrossAccountId,162 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,162 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,163 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {163 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {164 fail!(<pallet_common::Error<T>>::UnsupportedOperation);164 fail!(<CommonError<T>>::UnsupportedOperation);165 }165 }166166167 fn transfer(167 fn transfer(168 &self,168 &self,169 sender: <T>::CrossAccountId,169 sender: <T>::CrossAccountId,170 to: <T>::CrossAccountId,170 to: <T>::CrossAccountId,171 _token: TokenId,171 token: TokenId,172 amount: u128,172 amount: u128,173 budget: &dyn up_data_structs::budget::Budget,173 _budget: &dyn up_data_structs::budget::Budget,174 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {174 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {175 ensure!(176 token == TokenId::default(),177 <CommonError<T>>::FungibleItemsHaveNoId178 );179175 <Pallet<T>>::transfer(self, &sender, &to, amount, budget)180 <Pallet<T>>::transfer(&sender, &to, amount)176 }181 }177182178 fn approve(183 fn approve(182 _token: TokenId,187 _token: TokenId,183 _amount: u128,188 _amount: u128,184 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {189 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {185 fail!(<pallet_common::Error<T>>::UnsupportedOperation);190 fail!(<CommonError<T>>::UnsupportedOperation);186 }191 }187192188 fn approve_from(193 fn approve_from(193 _token: TokenId,198 _token: TokenId,194 _amount: u128,199 _amount: u128,195 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {200 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {196 fail!(<pallet_common::Error<T>>::UnsupportedOperation);201 fail!(<CommonError<T>>::UnsupportedOperation);197 }202 }198203199 fn transfer_from(204 fn transfer_from(200 &self,205 &self,201 sender: <T>::CrossAccountId,206 sender: <T>::CrossAccountId,202 from: <T>::CrossAccountId,207 from: <T>::CrossAccountId,203 to: <T>::CrossAccountId,208 to: <T>::CrossAccountId,204 _token: TokenId,209 token: TokenId,205 amount: u128,210 amount: u128,206 budget: &dyn up_data_structs::budget::Budget,211 budget: &dyn up_data_structs::budget::Budget,207 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {212 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {213 ensure!(214 token == TokenId::default(),215 <CommonError<T>>::FungibleItemsHaveNoId216 );217208 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, budget)218 <Pallet<T>>::transfer_from(&sender, &from, &to, amount, budget)209 }219 }210220211 fn burn_from(221 fn burn_from(216 _amount: u128,226 _amount: u128,217 _budget: &dyn up_data_structs::budget::Budget,227 _budget: &dyn up_data_structs::budget::Budget,218 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {228 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {219 fail!(<pallet_common::Error<T>>::UnsupportedOperation);229 fail!(<CommonError<T>>::UnsupportedOperation);220 }230 }221231222 fn check_nesting(232 fn check_nesting(226 _under: TokenId,236 _under: TokenId,227 _budget: &dyn up_data_structs::budget::Budget,237 _budget: &dyn up_data_structs::budget::Budget,228 ) -> frame_support::sp_runtime::DispatchResult {238 ) -> frame_support::sp_runtime::DispatchResult {229 fail!(<pallet_common::Error<T>>::UnsupportedOperation);239 fail!(<CommonError<T>>::UnsupportedOperation);230 }240 }231241232 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}242 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}332 _operator: <T>::CrossAccountId,342 _operator: <T>::CrossAccountId,333 _approve: bool,343 _approve: bool,334 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {344 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {335 fail!(<pallet_common::Error<T>>::UnsupportedOperation);345 fail!(<CommonError<T>>::UnsupportedOperation);336 }346 }337347338 fn allowance_for_all(348 fn allowance_for_all(347 &self,357 &self,348 _token: TokenId,358 _token: TokenId,349 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {359 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {350 fail!(<pallet_common::Error<T>>::UnsupportedOperation);360 fail!(<CommonError<T>>::UnsupportedOperation);351 }361 }352}362}353363pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -58,12 +58,8 @@
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
let amount = amount.try_into().map_err(|_| "amount overflow")?;
- let budget = self
- .recorder()
- .weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer(self, &caller, &to, amount, &budget)
- .map_err(|e| dispatch_to_evm::<T>(e.error))?;
+ <Pallet<T>>::transfer(&caller, &to, amount).map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(true)
}
@@ -83,7 +79,7 @@
.recorder()
.weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
+ <Pallet<T>>::transfer_from(&caller, &from, &to, amount, &budget)
.map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(true)
}
@@ -106,12 +102,8 @@
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
let amount = amount.try_into().map_err(|_| "amount overflow")?;
- let budget = self
- .recorder()
- .weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer(self, &caller, &to, amount, &budget)
- .map_err(|e| dispatch_to_evm::<T>(e.error))?;
+ <Pallet<T>>::transfer(&caller, &to, amount).map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(true)
}
@@ -137,7 +129,7 @@
.recorder()
.weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
+ <Pallet<T>>::transfer_from(&caller, &from, &to, amount, &budget)
.map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(true)
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -155,20 +155,15 @@
Ok(Self::balance_of(from))
}
- /// Transfers the specified amount of tokens. Will check that
- /// the transfer is allowed for the token.
+ /// Transfers the specified amount of tokens.
///
- /// - `collection`: Collection that contains the token.
/// - `from`: Owner of tokens to transfer.
/// - `to`: Recepient of transfered tokens.
/// - `amount`: Amount of tokens to transfer.
- /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
pub fn transfer(
- _collection: &NativeFungibleHandle<T>,
from: &T::CrossAccountId,
to: &T::CrossAccountId,
amount: u128,
- _nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
<PalletCommon<T>>::ensure_correct_receiver(to)?;
@@ -185,19 +180,18 @@
})
}
- /// Transfer NFT token from one account to another.
+ /// Transfer tokens from one account to another.
///
- /// Same as the [`Self::transfer`] but spender doesn't needs to be the owner of the token.
- /// The owner should set allowance for the spender to transfer token.
+ /// Same as the [`Self::transfer`] but the spender doesn't needs to be the direct owner of the token.
+ /// The spender must be allowed to transfer token.
+ /// If the tokens are nested in an NFT and the spender owns the NFT, the allowance is considered to be set.
///
- /// - `collection`: Collection that contains the token.
/// - `spender`: Account that spend the money.
/// - `from`: Owner of tokens to transfer.
/// - `to`: Recepient of transfered tokens.
/// - `amount`: Amount of tokens to transfer.
/// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
pub fn transfer_from(
- collection: &NativeFungibleHandle<T>,
spender: &T::CrossAccountId,
from: &T::CrossAccountId,
to: &T::CrossAccountId,
@@ -208,7 +202,7 @@
if allowance < amount {
return Err(<CommonError<T>>::ApprovedValueTooLow.into());
}
- Self::transfer(collection, from, to, amount, nesting_budget)
+ Self::transfer(from, to, amount)
}
}
}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -783,6 +783,9 @@
/// The user is not an administrator.
UserIsNotCollectionAdmin,
+
+ /// Fungible tokens hold no ID, and the default value of TokenId for a fungible collection is 0.
+ FungibleItemsHaveNoId,
}
/// Storage of the count of created collections. Essentially contains the last collection ID.
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -19,7 +19,7 @@
use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};
use pallet_common::{
weights::WeightInfo as _, with_weight, CommonCollectionOperations, CommonWeightInfo,
- RefungibleExtensions, SelfWeightOf as PalletCommonWeightOf,
+ Error as CommonError, RefungibleExtensions, SelfWeightOf as PalletCommonWeightOf,
};
use sp_runtime::{ArithmeticError, DispatchError};
use sp_std::{vec, vec::Vec};
@@ -169,7 +169,7 @@
) -> DispatchResultWithPostInfo {
ensure!(
token == TokenId::default(),
- <Error<T>>::FungibleItemsHaveNoId
+ <CommonError<T>>::FungibleItemsHaveNoId
);
with_weight(
@@ -188,7 +188,7 @@
) -> DispatchResultWithPostInfo {
ensure!(
token == TokenId::default(),
- <Error<T>>::FungibleItemsHaveNoId
+ <CommonError<T>>::FungibleItemsHaveNoId
);
<Pallet<T>>::transfer(self, &from, &to, amount, nesting_budget)
@@ -203,7 +203,7 @@
) -> DispatchResultWithPostInfo {
ensure!(
token == TokenId::default(),
- <Error<T>>::FungibleItemsHaveNoId
+ <CommonError<T>>::FungibleItemsHaveNoId
);
with_weight(
@@ -222,7 +222,7 @@
) -> DispatchResultWithPostInfo {
ensure!(
token == TokenId::default(),
- <Error<T>>::FungibleItemsHaveNoId
+ <CommonError<T>>::FungibleItemsHaveNoId
);
with_weight(
@@ -242,7 +242,7 @@
) -> DispatchResultWithPostInfo {
ensure!(
token == TokenId::default(),
- <Error<T>>::FungibleItemsHaveNoId
+ <CommonError<T>>::FungibleItemsHaveNoId
);
<Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, nesting_budget)
@@ -258,7 +258,7 @@
) -> DispatchResultWithPostInfo {
ensure!(
token == TokenId::default(),
- <Error<T>>::FungibleItemsHaveNoId
+ <CommonError<T>>::FungibleItemsHaveNoId
);
with_weight(
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -123,8 +123,6 @@
pub enum Error<T> {
/// Not Fungible item data used to mint in Fungible collection.
NotFungibleDataUsedToMintFungibleCollectionToken,
- /// Fungible tokens hold no ID, and the default value of TokenId for Fungible collection is 0.
- FungibleItemsHaveNoId,
/// Tried to set data for fungible item.
FungibleItemsDontHaveData,
/// Fungible token does not support nesting.