Skip to content

Commit

Permalink
remove getter in asset-registry (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
MJLNSN authored Aug 5, 2024
1 parent 64ce328 commit 3ed7c0b
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions pallets/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,50 +129,43 @@ pub mod pallet {
///
/// NextForeignAssetId: ForeignAssetId
#[pallet::storage]
#[pallet::getter(fn next_foreign_asset_id)]
pub type NextForeignAssetId<T: Config> = StorageValue<_, ForeignAssetId, ValueQuery>;

/// Next available TokenId ID.
///
/// NextTokenId: TokenId
#[pallet::storage]
#[pallet::getter(fn next_token_id)]
pub type NextTokenId<T: Config> = StorageValue<_, TokenId, ValueQuery>;

/// The storages for Locations.
///
/// CurrencyIdToLocations: map CurrencyId => Option<Location>
#[pallet::storage]
#[pallet::getter(fn currency_id_to_locations)]
pub type CurrencyIdToLocations<T: Config> =
StorageMap<_, Twox64Concat, CurrencyId, xcm::v3::Location, OptionQuery>;

/// The storages for CurrencyIds.
///
/// LocationToCurrencyIds: map Location => Option<CurrencyId>
#[pallet::storage]
#[pallet::getter(fn location_to_currency_ids)]
pub type LocationToCurrencyIds<T: Config> =
StorageMap<_, Twox64Concat, xcm::v3::Location, CurrencyId, OptionQuery>;

#[pallet::storage]
#[pallet::getter(fn currency_id_to_weight)]
pub type CurrencyIdToWeights<T: Config> =
StorageMap<_, Twox64Concat, CurrencyId, Weight, OptionQuery>;

/// The storages for AssetMetadatas.
///
/// AssetMetadatas: map AssetIds => Option<AssetMetadata>
#[pallet::storage]
#[pallet::getter(fn asset_metadatas)]
pub type AssetMetadatas<T: Config> =
StorageMap<_, Twox64Concat, AssetIds, AssetMetadata<BalanceOf<T>>, OptionQuery>;

/// The storages for AssetMetadata.
///
/// CurrencyMetadatas: map CurrencyId => Option<AssetMetadata>
#[pallet::storage]
#[pallet::getter(fn currency_metadatas)]
pub type CurrencyMetadatas<T: Config> =
StorageMap<_, Twox64Concat, CurrencyId, AssetMetadata<BalanceOf<T>>, OptionQuery>;

Expand Down Expand Up @@ -639,25 +632,24 @@ impl<T: Config> CurrencyIdMapping<CurrencyId, MultiLocation, AssetMetadata<Balan
for AssetIdMaps<T>
{
fn get_asset_metadata(asset_ids: AssetIds) -> Option<AssetMetadata<BalanceOf<T>>> {
Pallet::<T>::asset_metadatas(asset_ids)
AssetMetadatas::<T>::get(asset_ids)
}

fn get_currency_metadata(currency_id: CurrencyId) -> Option<AssetMetadata<BalanceOf<T>>> {
Pallet::<T>::currency_metadatas(currency_id)
CurrencyMetadatas::<T>::get(currency_id)
}

fn get_all_currency() -> Vec<CurrencyId> {
CurrencyMetadatas::<T>::iter_keys().collect()
}

fn get_location(currency_id: CurrencyId) -> Option<Location> {
Pallet::<T>::currency_id_to_locations(currency_id)
.map(|location| location.try_into().ok())?
CurrencyIdToLocations::<T>::get(currency_id).map(|location| location.try_into().ok())?
}

fn get_currency_id(multi_location: Location) -> Option<CurrencyId> {
let v3_location = xcm::v3::Location::try_from(multi_location).ok()?;
Pallet::<T>::location_to_currency_ids(v3_location)
LocationToCurrencyIds::<T>::get(v3_location)
}
}

Expand Down Expand Up @@ -942,8 +934,8 @@ where
let v3_location =
xcm::v3::Location::try_from(location.clone()).map_err(|_| XcmError::InvalidLocation)?;

if let Some(currency_id) = Pallet::<T>::location_to_currency_ids(v3_location) {
if let Some(currency_metadatas) = Pallet::<T>::currency_metadatas(currency_id) {
if let Some(currency_id) = LocationToCurrencyIds::<T>::get(v3_location) {
if let Some(currency_metadatas) = CurrencyMetadatas::<T>::get(currency_id) {
// The integration tests can ensure the ed is non-zero.
let ed_ratio = FixedU128::saturating_from_rational(
currency_metadatas.minimal_balance.into(),
Expand Down

0 comments on commit 3ed7c0b

Please sign in to comment.