difftreelog
refactor remove redundant foreign flag, use foreign-assets pallet instead
in: master
8 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -368,10 +368,6 @@
}
impl<T: Config> pallet_common::XcmExtensions<T> for NativeFungibleHandle<T> {
- fn is_foreign(&self) -> bool {
- false
- }
-
fn create_item_internal(
&self,
_depositor: &<T>::CrossAccountId,
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1088,7 +1088,6 @@
read_only: flags.external,
flags: RpcCollectionFlags {
- foreign: flags.foreign,
erc721metadata: flags.erc721metadata,
},
})
@@ -1128,17 +1127,17 @@
/// Create new collection.
///
/// * `owner` - The owner of the collection.
+ /// * `payer` - If set, the user that will pay a deposit for the collection creation.
/// * `data` - Description of the created collection.
- /// * `flags` - Extra flags to store.
pub fn init_collection(
owner: T::CrossAccountId,
- payer: T::CrossAccountId,
+ payer: Option<T::CrossAccountId>,
data: CreateCollectionData<T::CrossAccountId>,
) -> Result<CollectionId, DispatchError> {
ensure!(data.flags.is_allowed_for_user(), <Error<T>>::NoPermission);
// Take a (non-refundable) deposit of collection creation
- {
+ if let Some(payer) = payer {
let mut imbalance = <Debt<T::AccountId, <T as Config>::Currency>>::zero();
imbalance.subsume(<T as Config>::Currency::deposit(
&T::TreasuryAccountId::get(),
@@ -1153,16 +1152,6 @@
}
Self::init_collection_internal(owner, data)
- }
-
- /// Initializes the collection with ForeignCollection flag. Returns [CollectionId] on success, [DispatchError] otherwise.
- pub fn init_foreign_collection(
- owner: T::CrossAccountId,
- mut data: CreateCollectionData<T::CrossAccountId>,
- ) -> Result<CollectionId, DispatchError> {
- data.flags.foreign = true;
- let id = Self::init_collection_internal(owner, data)?;
- Ok(id)
}
fn init_collection_internal(
@@ -2348,9 +2337,6 @@
where
T: Config,
{
- /// Is the collection a foreign one?
- fn is_foreign(&self) -> bool;
-
/// Does the token have children?
fn token_has_children(&self, _token: TokenId) -> bool {
false
pallets/foreign-assets/src/lib.rsdiffbeforeafterboth304 /// If the `asset_instance` is a part of a local collection,304 /// If the `asset_instance` is a part of a local collection,305 /// the function will return either `Ok(Some(<token ID>))` or an error if the token is not found.305 /// the function will return either `Ok(Some(<token ID>))` or an error if the token is not found.306 fn asset_instance_to_token_id(306 fn asset_instance_to_token_id(307 xcm_ext: &dyn XcmExtensions<T>,308 collection_id: CollectionId,307 collection_id: CollectionId,309 asset_instance: &AssetInstance,308 asset_instance: &AssetInstance,310 ) -> Result<Option<TokenId>, XcmError> {309 ) -> Result<Option<TokenId>, XcmError> {311 if xcm_ext.is_foreign() {310 if <CollectionToForeignReserveLocation<T>>::contains_key(collection_id) {312 Ok(Self::foreign_reserve_asset_instance_to_token_id(311 Ok(Self::foreign_reserve_asset_instance_to_token_id(313 collection_id,312 collection_id,314 asset_instance,313 asset_instance,363 to: T::CrossAccountId,362 to: T::CrossAccountId,364 ) -> XcmResult {363 ) -> XcmResult {365 let deposit_result = if let Some(token_id) =364 let deposit_result = if let Some(token_id) =366 Self::asset_instance_to_token_id(xcm_ext, collection_id, asset_instance)?365 Self::asset_instance_to_token_id(collection_id, asset_instance)?367 {366 {368 let depositor = &Self::pallet_account();367 let depositor = &Self::pallet_account();369 let from = depositor;368 let from = depositor;389 asset_instance: &AssetInstance,388 asset_instance: &AssetInstance,390 from: T::CrossAccountId,389 from: T::CrossAccountId,391 ) -> XcmResult {390 ) -> XcmResult {392 let token_id = Self::asset_instance_to_token_id(xcm_ext, collection_id, &asset_instance)?391 let token_id = Self::asset_instance_to_token_id(collection_id, &asset_instance)?393 .ok_or(XcmError::AssetNotFound)?;392 .ok_or(XcmError::AssetNotFound)?;394393395 if xcm_ext.token_has_children(token_id) {394 if xcm_ext.token_has_children(token_id) {518517519 Fungibility::NonFungible(asset_instance) => {518 Fungibility::NonFungible(asset_instance) => {520 token_id =519 token_id = Self::asset_instance_to_token_id(collection_id, &asset_instance)?521 Self::asset_instance_to_token_id(xcm_ext, collection_id, &asset_instance)?522 .ok_or(XcmError::AssetNotFound)?;520 .ok_or(XcmError::AssetNotFound)?;523521524 amount = 1;522 amount = 1;542 if collection_id == NATIVE_FUNGIBLE_COLLECTION_ID {540 if collection_id == NATIVE_FUNGIBLE_COLLECTION_ID {543 Some(Here.into())541 Some(Here.into())544 } else {542 } else {545 let dispatch = T::CollectionDispatch::dispatch(collection_id).ok()?;546 let collection = dispatch.as_dyn();547 let xcm_ext = collection.xcm_extensions()?;548549 if xcm_ext.is_foreign() {550 <Pallet<T>>::collection_to_foreign_reserve_location(collection_id)543 <Pallet<T>>::collection_to_foreign_reserve_location(collection_id).or_else(|| {551 } else {552 T::SelfLocation::get()544 T::SelfLocation::get()553 .pushed_with_interior(GeneralIndex(collection_id.0.into()))545 .pushed_with_interior(GeneralIndex(collection_id.0.into()))554 .ok()546 .ok()555 }547 })556 }548 }557 }549 }558}550}pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -459,10 +459,6 @@
}
impl<T: Config> XcmExtensions<T> for FungibleHandle<T> {
- fn is_foreign(&self) -> bool {
- self.flags.foreign
- }
-
fn create_item_internal(
&self,
depositor: &<T>::CrossAccountId,
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -572,10 +572,6 @@
}
impl<T: Config> XcmExtensions<T> for NonfungibleHandle<T> {
- fn is_foreign(&self) -> bool {
- self.flags.foreign
- }
-
fn token_has_children(&self, token: TokenId) -> bool {
<Pallet<T>>::token_has_children(self.id, token)
}
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -306,7 +306,7 @@
payer: T::CrossAccountId,
data: CreateCollectionData<T::CrossAccountId>,
) -> Result<CollectionId, DispatchError> {
- <PalletCommon<T>>::init_collection(owner, payer, data)
+ <PalletCommon<T>>::init_collection(owner, Some(payer), data)
}
/// Destroy RFT collection
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -378,9 +378,9 @@
#[derive(AbiCoderFlags, Bitfields, Clone, Copy, PartialEq, Eq, Debug, Default)]
#[bondrewd(enforce_bytes = 1)]
pub struct CollectionFlags {
- /// Tokens in foreign collections can be transferred, but not burnt
+ /// Reserved flag
#[bondrewd(bits = "0..1")]
- pub foreign: bool,
+ pub reserved_0: bool,
/// Supports ERC721Metadata
#[bondrewd(bits = "1..2")]
pub erc721metadata: bool,
@@ -395,7 +395,7 @@
impl CollectionFlags {
pub fn is_allowed_for_user(self) -> bool {
- !self.foreign && !self.external && self.reserved == 0
+ !self.reserved_0 && !self.external && self.reserved == 0
}
}
@@ -461,8 +461,6 @@
#[derive(Debug, Encode, Decode, Clone, PartialEq, TypeInfo, Serialize, Deserialize)]
pub struct RpcCollectionFlags {
- /// Is collection is foreign.
- pub foreign: bool,
/// Collection supports ERC721Metadata.
pub erc721metadata: bool,
}
@@ -505,7 +503,7 @@
pub read_only: bool,
/// Extra collection flags
- #[version(2.., upper(RpcCollectionFlags {foreign: false, erc721metadata: false}))]
+ #[version(2.., upper(RpcCollectionFlags {erc721metadata: false}))]
pub flags: RpcCollectionFlags,
}
@@ -542,7 +540,6 @@
read_only: true,
flags: RpcCollectionFlags {
- foreign: false,
erc721metadata: false,
},
}
runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -86,7 +86,7 @@
_ => {}
};
- <PalletCommon<T>>::init_collection(sender, payer, data)
+ <PalletCommon<T>>::init_collection(sender, Some(payer), data)
}
fn create_foreign(
@@ -106,7 +106,8 @@
_ => {}
};
- <PalletCommon<T>>::init_foreign_collection(sender, data)
+ let payer = None;
+ <PalletCommon<T>>::init_collection(sender, payer, data)
}
fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {