Skip to content

Commit

Permalink
finish implementation, no need to insert into AssetIdMetadata
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Reif <[email protected]>
  • Loading branch information
Adam Reif authored and Adam Reif committed Apr 11, 2023
1 parent a41e44b commit b9f1eb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
13 changes: 8 additions & 5 deletions pallets/asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ pub mod pallet {
pub fn update_asset_metadata(
origin: OriginFor<T>,
asset_id: T::AssetId,
metadata: <T::AssetConfig as AssetConfig<T>>::AssetRegistryMetadata,
metadata: <<T as Config>::AssetConfig as AssetConfig<T>>::StorageMetadata,
) -> DispatchResult {
T::ModifierOrigin::ensure_origin(origin)?;
ensure!(
Expand All @@ -476,11 +476,14 @@ pub mod pallet {
Error::<T>::UpdateNonExistentAsset
);
<T::AssetConfig as AssetConfig<T>>::AssetRegistry::update_asset_metadata(
&asset_id,
metadata.clone().into(),
&asset_id, metadata,
)?;
AssetIdMetadata::<T>::insert(asset_id, &metadata);
Self::deposit_event(Event::<T>::AssetMetadataUpdated { asset_id, metadata });
let updated_registry_metadata = Self::asset_id_metadata(asset_id)
.expect("we just successfully updated the asset, so it exists. qed");
Self::deposit_event(Event::<T>::AssetMetadataUpdated {
asset_id,
metadata: updated_registry_metadata,
});
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/asset-manager/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn wrong_modifier_origin_should_not_work() {
AssetManager::update_asset_metadata(
Origin::signed([3u8; 32].into()),
0,
asset_metadata
asset_metadata.into()
),
BadOrigin
);
Expand Down Expand Up @@ -166,14 +166,14 @@ fn update_asset() {
AssetManager::update_asset_metadata(
Origin::root(),
native_asset_id,
new_metadata.clone(),
new_metadata.clone().into(),
),
Error::<Runtime>::CannotUpdateNativeAssetMetadata
);
assert_ok!(AssetManager::update_asset_metadata(
Origin::root(),
asset_id,
new_metadata.clone(),
new_metadata.clone().into(),
),);
assert_eq!(Assets::name(&asset_id), new_name);
assert_eq!(Assets::symbol(&asset_id), new_symbol);
Expand Down Expand Up @@ -205,7 +205,7 @@ fn update_asset() {
AssetManager::update_asset_metadata(
Origin::root(),
next_asset_id,
new_metadata.clone()
new_metadata.clone().into()
),
Error::<Runtime>::UpdateNonExistentAsset
);
Expand Down
4 changes: 2 additions & 2 deletions primitives/manta/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub trait AssetRegistry: AssetIdType + BalanceType {

/// Update asset metadata by `AssetId`.
///
/// * `asset_id`: the asset id to be created.
/// * `asset_id`: the asset id to be updated.
/// * `metadata`: the metadata that the implementation layer stores.
fn update_asset_metadata(
asset_id: &Self::AssetId,
Expand All @@ -120,7 +120,7 @@ where
C: Config,
{
/// Metadata type that required in token storage: e.g. AssetMetadata in Pallet-Assets.
type StorageMetadata: From<Self::AssetRegistryMetadata>;
type StorageMetadata: From<Self::AssetRegistryMetadata> + Parameter;

/// The Asset Metadata type stored in this pallet.
type AssetRegistryMetadata: AssetMetadata<Balance = Self::Balance> + Parameter + TestingDefault;
Expand Down

0 comments on commit b9f1eb0

Please sign in to comment.