Skip to content

Commit

Permalink
fix: rfts are unsupported in XCM
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Oct 24, 2023
1 parent 18163db commit e8a0ca9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
11 changes: 6 additions & 5 deletions pallets/foreign-assets/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use pallet_common::benchmarking::create_u16_data;
use pallet_common::benchmarking::{create_data, create_u16_data};
use sp_std::vec;
use staging_xcm::prelude::*;
use up_data_structs::{CollectionMode, MAX_COLLECTION_NAME_LENGTH};
use up_data_structs::{MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH};

use super::{Call, Config, Pallet};
use super::{Call, Config, ForeignCollectionMode, Pallet};

#[benchmarks]
mod benchmarks {
Expand All @@ -35,10 +35,11 @@ mod benchmarks {
let location =
MultiLocation::from(X3(Parachain(1000), PalletInstance(42), GeneralIndex(1)));
let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
let mode = CollectionMode::NFT;
let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
let mode = ForeignCollectionMode::NFT;

#[extrinsic_call]
_(RawOrigin::Root, location, name, mode);
_(RawOrigin::Root, location, name, token_prefix, mode);

Ok(())
}
Expand Down
28 changes: 23 additions & 5 deletions pallets/foreign-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ use staging_xcm_executor::{
Assets,
};
use up_data_structs::{
budget::ZeroBudget, CollectionId, CollectionMode, CollectionName, CreateCollectionData,
CreateFungibleData, CreateItemData, CreateNftData, Property, PropertyKey, TokenId,
budget::ZeroBudget, CollectionId, CollectionMode, CollectionName, CollectionTokenPrefix,
CreateCollectionData, CreateFungibleData, CreateItemData, CreateNftData, Property, PropertyKey,
TokenId,
};

pub mod weights;
Expand Down Expand Up @@ -87,7 +88,7 @@ pub mod module {

#[pallet::error]
pub enum Error<T> {
/// The foreign asset is already registered
/// The foreign asset is already registered.
ForeignAssetAlreadyRegistered,
}

Expand Down Expand Up @@ -136,7 +137,8 @@ pub mod module {
origin: OriginFor<T>,
reserve_location: MultiLocation,
name: CollectionName,
mode: CollectionMode,
token_prefix: CollectionTokenPrefix,
mode: ForeignCollectionMode,
) -> DispatchResult {
T::ForceRegisterOrigin::ensure_origin(origin.clone())?;

Expand All @@ -160,8 +162,9 @@ pub mod module {
is_special_collection,
CreateCollectionData {
name,
token_prefix,
description,
mode,
mode: mode.into(),

properties: vec![Property {
key: Self::reserve_location_property_key(),
Expand Down Expand Up @@ -560,6 +563,21 @@ pub use frame_support::{
weights::{WeightToFee, WeightToFeePolynomial},
};

#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
pub enum ForeignCollectionMode {
NFT,
Fungible(u8),
}

impl Into<CollectionMode> for ForeignCollectionMode {
fn into(self) -> CollectionMode {
match self {
Self::NFT => CollectionMode::NFT,
Self::Fungible(decimals) => CollectionMode::Fungible(decimals),
}
}
}

pub struct FreeForAll;

impl WeightTrader for FreeForAll {
Expand Down

0 comments on commit e8a0ca9

Please sign in to comment.