Skip to content

Commit

Permalink
Fix InspectRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
vgantchev committed Nov 7, 2023
1 parent 9215cb7 commit 62f3b07
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
12 changes: 7 additions & 5 deletions pallets/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ impl<T: Config> CreateRegistry<T::AssetId, T::Balance> for Pallet<T> {
}
}

impl<T: Config> InspectRegistry<T::AssetId, BoundedVec<u8, <T as Config>::StringLimit>> for Pallet<T> {
impl<T: Config> InspectRegistry<T::AssetId> for Pallet<T> {
fn exists(asset_id: T::AssetId) -> bool {
Assets::<T>::contains_key(asset_id)
}
Expand All @@ -639,11 +639,13 @@ impl<T: Config> InspectRegistry<T::AssetId, BoundedVec<u8, <T as Config>::String
Some(AssetMetadataMap::<T>::get(asset_id)?.decimals)
}

fn asset_name(asset_id: T::AssetId) -> Option<BoundedVec<u8, <T as Config>::StringLimit>> {
Some(Assets::<T>::get(asset_id)?.name)
fn asset_name(asset_id: T::AssetId) -> Option<Vec<u8>> {
let asset = Assets::<T>::get(asset_id)?;
Some(asset.name.into_inner())
}

fn asset_symbol(asset_id: T::AssetId) -> Option<BoundedVec<u8, <T as Config>::StringLimit>> {
Some(AssetMetadataMap::<T>::get(asset_id)?.symbol)
fn asset_symbol(asset_id: T::AssetId) -> Option<Vec<u8>> {
let asset_metadata = AssetMetadataMap::<T>::get(asset_id)?;
Some(asset_metadata.symbol.into_inner())
}
}
3 changes: 1 addition & 2 deletions pallets/stableswap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use hydradx_traits::pools::DustRemovalAccountWhitelist;
use orml_traits::MultiCurrency;
use sp_std::collections::btree_map::BTreeMap;
use weights::WeightInfo;
use pallet_asset_registry::Config as PalletAssetRegistryConfig;

#[cfg(test)]
pub(crate) mod tests;
Expand Down Expand Up @@ -127,7 +126,7 @@ pub mod pallet {
type ShareAccountId: AccountIdFor<Self::AssetId, AccountId = Self::AccountId>;

/// Asset registry mechanism
type AssetInspection: InspectRegistry<Self::AssetId, BoundedVec<u8, <T as PalletAssetRegistryConfig>::StringLimit>>;
type AssetInspection: InspectRegistry<Self::AssetId>;

/// The origin which can create a new pool
type AuthorityOrigin: EnsureOrigin<Self::RuntimeOrigin>;
Expand Down
8 changes: 8 additions & 0 deletions pallets/stableswap/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ impl InspectRegistry<AssetId> for DummyRegistry {
let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&asset_id).copied())?;
Some(asset.1)
}

fn asset_name(_asset_id: AssetId) -> Option<Vec<u8>> {
unimplemented!()
}

fn asset_symbol(_asset_id: AssetId) -> Option<Vec<u8>> {
unimplemented!()
}
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/evm/precompiles/multicurrency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ use crate::{
};
use codec::EncodeLike;
use frame_support::traits::OriginTrait;
use hydradx_traits::InspectRegistry;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use orml_traits::{MultiCurrency as MultiCurrencyT, MultiCurrency};
use pallet_evm::{AddressMapping, ExitRevert, Precompile, PrecompileFailure, PrecompileHandle, PrecompileResult};
use primitive_types::H160;
use primitives::{AssetId, Balance};
use sp_runtime::{traits::Dispatchable, RuntimeDebug};
use sp_std::{marker::PhantomData, prelude::*};
use hydradx_traits::InspectRegistry;

#[module_evm_utility_macro::generate_function_selector]
#[derive(RuntimeDebug, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)]
Expand Down
6 changes: 3 additions & 3 deletions traits/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub trait ShareTokenRegistry<AssetId, AssetName, Balance, Error>: Registry<Asset
}
}

pub trait InspectRegistry<AssetId, BoundedString> {
pub trait InspectRegistry<AssetId> {
fn exists(asset_id: AssetId) -> bool;
fn decimals(asset_id: AssetId) -> Option<u8>;
fn asset_name(asset_id: AssetId) -> Option<BoundedString>;
fn asset_symbol(asset_id: AssetId) -> Option<BoundedString>;
fn asset_name(asset_id: AssetId) -> Option<Vec<u8>>;
fn asset_symbol(asset_id: AssetId) -> Option<Vec<u8>>;
}

#[derive(Eq, PartialEq, Copy, Clone)]
Expand Down

0 comments on commit 62f3b07

Please sign in to comment.