Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add symbol to list_assets rpc #3749

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions code/parachain/frame/assets-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,23 @@ pub mod pallet {
ExistentialDeposit::<T>::iter_keys()
.map(|asset_id| {
let name = AssetName::<T>::get(asset_id).map(Into::into);
let symbol = AssetSymbol::<T>::get(asset_id).map(Into::into);
let foreign_id = LocalToForeign::<T>::get(asset_id);
let decimals =
<Pallet<T> as InspectRegistryMetadata>::decimals(&asset_id).unwrap_or(12);
let ratio = AssetRatio::<T>::get(asset_id);
let existential_deposit =
ExistentialDeposit::<T>::get(asset_id).unwrap_or_default();

Asset { name, id: asset_id, decimals, ratio, foreign_id, existential_deposit }
Asset {
name,
symbol,
id: asset_id,
decimals,
ratio,
foreign_id,
existential_deposit,
}
})
.collect::<Vec<_>>()
}
Expand Down Expand Up @@ -429,6 +438,8 @@ pub mod pallet {
) -> Vec<Asset<Self::AssetId, T::Balance, Self::AssetNativeLocation>> {
ForeignToLocal::<T>::iter()
.map(|(_, asset_id)| {
let name = AssetName::<T>::get(asset_id).map(Into::into);
let symbol = AssetSymbol::<T>::get(asset_id).map(Into::into);
let foreign_id = LocalToForeign::<T>::get(asset_id);
let decimals =
<Pallet<T> as InspectRegistryMetadata>::decimals(&asset_id).unwrap_or(12);
Expand All @@ -437,7 +448,8 @@ pub mod pallet {
ExistentialDeposit::<T>::get(asset_id).unwrap_or_default();

Asset {
name: None,
name,
symbol,
id: asset_id,
decimals,
ratio,
Expand Down
14 changes: 10 additions & 4 deletions code/parachain/frame/assets-registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,11 @@ fn get_foreign_assets_list_should_work() {
let location = ForeignAssetId::Xcm(VersionedMultiLocation::V3(MultiLocation::here()));
let protocol_id = *b"AssTests";
let nonce = 1_u64;
let name = Some(BiBoundedVec::from_vec(b"asset_name".to_vec()).unwrap());
let symbol = Some(BiBoundedVec::from_vec(b"asset_symbol".to_vec()).unwrap());
let asset_info = AssetInfo {
name: None,
symbol: None,
name: name.clone(),
symbol: symbol.clone(),
decimals: Some(4),
existential_deposit: 0,
ratio: Some(rational!(42 / 123)),
Expand All @@ -442,7 +444,8 @@ fn get_foreign_assets_list_should_work() {
assert_eq!(
foreign_assets,
vec![Asset {
name: None,
name: name.clone().map(Into::into),
symbol: symbol.clone().map(Into::into),
id,
decimals: 4,
ratio: Some(rational!(42 / 123)),
Expand All @@ -461,9 +464,10 @@ fn get_all_assets_should_work() {
let nonce = 1_u64;
let nonce2 = 2_u64;
let name = Some(BiBoundedVec::from_vec(b"asset_name".to_vec()).unwrap());
let symbol = Some(BiBoundedVec::from_vec(b"asset_symbol".to_vec()).unwrap());
let asset_info = AssetInfo {
name: name.clone(),
symbol: None,
symbol: symbol.clone(),
decimals: Some(4),
existential_deposit: 0,
ratio: Some(rational!(42 / 123)),
Expand Down Expand Up @@ -498,6 +502,7 @@ fn get_all_assets_should_work() {
vec![
Asset {
name: name.clone().map(Into::into),
symbol: symbol.clone().map(Into::into),
id,
decimals: 4,
ratio: Some(rational!(42 / 123)),
Expand All @@ -506,6 +511,7 @@ fn get_all_assets_should_work() {
},
Asset {
name: name.map(Into::into),
symbol: symbol.map(Into::into),
id: id2,
decimals: 4,
ratio: Some(rational!(42 / 123)),
Expand Down
1 change: 1 addition & 0 deletions code/parachain/frame/composable-traits/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl BasicAssetMetadata {
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct Asset<AssetId, Balance, ForeignId> {
pub name: Option<Vec<u8>>,
pub symbol: Option<Vec<u8>>,
pub id: AssetId,
pub decimals: Exponent,
pub ratio: Option<Rational64>,
Expand Down
1 change: 1 addition & 0 deletions code/parachain/runtime/composable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ impl_runtime_apis! {
id : SafeRpcWrapper(asset.id.into()),
foreign_id : asset.foreign_id.clone(),
name : asset.name.clone(),
symbol : asset.symbol.clone(),
ratio : asset.ratio,
}
).collect::<Vec<Asset<SafeRpcWrapper<u128>, SafeRpcWrapper<Balance>, ForeignAssetId>>>()
Expand Down
1 change: 1 addition & 0 deletions code/parachain/runtime/picasso/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ impl_runtime_apis! {
id : SafeRpcWrapper(asset.id.into()),
foreign_id : asset.foreign_id.clone(),
name : asset.name.clone(),
symbol : asset.symbol.clone(),
ratio : asset.ratio,
}
).collect::<Vec<Asset<SafeRpcWrapper<u128>, SafeRpcWrapper<Balance>, ForeignAssetId>>>()
Expand Down
1 change: 1 addition & 0 deletions code/parachain/runtime/primitives/src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ macro_rules! list_assets {
$(Asset {
id: CurrencyId::$NAME,
name: Some(stringify!($NAME).as_bytes().to_vec()),
symbol: Some(stringify!($NAME).as_bytes().to_vec()),
ratio: None,
decimals: Self::remote_decimals_for_local(CurrencyId::$NAME).unwrap_or(Self::decimals()),
foreign_id: None,
Expand Down
Loading