Skip to content

Commit 5e7817e

Browse files
committed
feat: multilocation getter (given assetid)
1 parent a20b2ef commit 5e7817e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

asset-registry/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ impl<T: Config> Pallet<T> {
249249
Metadata::<T>::get(asset_id)
250250
}
251251

252+
pub fn multilocation(asset_id: &T::AssetId) -> Result<Option<MultiLocation>, DispatchError> {
253+
Metadata::<T>::get(asset_id)
254+
.and_then(|metadata| {
255+
metadata
256+
.location
257+
.map(|location| location.try_into().map_err(|()| Error::<T>::BadVersion.into()))
258+
})
259+
.transpose()
260+
}
261+
252262
pub fn do_insert_location(asset_id: T::AssetId, location: VersionedMultiLocation) -> DispatchResult {
253263
// if the metadata contains a location, set the LocationToAssetId
254264
let location: MultiLocation = location.try_into().map_err(|()| Error::<T>::BadVersion)?;

asset-registry/src/mock/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
4747
CurrencyId::B1 => Some((Parent, Parachain(2), GeneralKey("B1".into())).into()),
4848
CurrencyId::B2 => Some((Parent, Parachain(2), GeneralKey("B2".into())).into()),
4949
CurrencyId::D => Some((Parent, Parachain(4), GeneralKey("D".into())).into()),
50-
CurrencyId::RegisteredAsset(id) => {
51-
AssetRegistry::metadata(id).and_then(|x| x.location.and_then(|x| x.try_into().ok()))
52-
}
50+
CurrencyId::RegisteredAsset(id) => AssetRegistry::multilocation(&id).unwrap_or_default(),
5351
}
5452
}
5553
}

0 commit comments

Comments
 (0)