Skip to content

Commit

Permalink
Add badges field to Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 committed Oct 22, 2024
1 parent 112bb24 commit 71a1b7d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
6 changes: 6 additions & 0 deletions crates/core/asset/src/asset/denom_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(super) struct Inner {
// For now, don't bother with a domain type here,
// since we don't render images from Rust code.
images: Vec<pb::AssetImage>,
badges: Vec<pb::AssetImage>,
priority_score: u64,

/// Sorted by priority order.
Expand All @@ -65,6 +66,7 @@ impl From<&Inner> for pb::Metadata {
penumbra_asset_id: Some(inner.id.into()),
denom_units: inner.units.clone().into_iter().map(|x| x.into()).collect(),
images: inner.images.clone(),
badges: inner.badges.clone(),
priority_score: inner.priority_score,
}
}
Expand Down Expand Up @@ -131,6 +133,7 @@ impl TryFrom<pb::Metadata> for Inner {
name: value.name,
symbol: value.symbol,
images: value.images,
badges: value.badges,
priority_score: value.priority_score,
})
}
Expand Down Expand Up @@ -253,6 +256,7 @@ impl Inner {
name: String::new(),
symbol: String::new(),
images: Vec::new(),
badges: Vec::new(),
priority_score: 0,
}
}
Expand Down Expand Up @@ -429,13 +433,15 @@ impl Debug for Metadata {
name,
symbol,
priority_score,
badges,
} = inner.as_ref();
f.debug_struct("Metadata")
.field("id", id)
.field("base_denom", base_denom)
.field("description", description)
.field("images", images)
.field("badges", badges)
.field("priority_score", priority_score)
.field("units", units)
.field("display_index", display_index)
Expand Down
4 changes: 4 additions & 0 deletions crates/proto/src/gen/penumbra.core.asset.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ pub struct Metadata {
/// This is solely for use in client-side registries.
#[prost(uint64, tag = "1986")]
pub priority_score: u64,
/// Associated icons for asset.
/// For ibc assets, usually an image of the source chain.
#[prost(message, repeated, tag = "1987")]
pub badges: ::prost::alloc::vec::Vec<AssetImage>,
}
impl ::prost::Name for Metadata {
const NAME: &'static str = "Metadata";
Expand Down
17 changes: 17 additions & 0 deletions crates/proto/src/gen/penumbra.core.asset.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ impl serde::Serialize for Metadata {
if self.priority_score != 0 {
len += 1;
}
if !self.badges.is_empty() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.asset.v1.Metadata", len)?;
if !self.description.is_empty() {
struct_ser.serialize_field("description", &self.description)?;
Expand Down Expand Up @@ -1068,6 +1071,9 @@ impl serde::Serialize for Metadata {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("priorityScore", ToString::to_string(&self.priority_score).as_str())?;
}
if !self.badges.is_empty() {
struct_ser.serialize_field("badges", &self.badges)?;
}
struct_ser.end()
}
}
Expand All @@ -1090,6 +1096,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
"images",
"priority_score",
"priorityScore",
"badges",
];

#[allow(clippy::enum_variant_names)]
Expand All @@ -1103,6 +1110,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
PenumbraAssetId,
Images,
PriorityScore,
Badges,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand Down Expand Up @@ -1134,6 +1142,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
"penumbraAssetId" | "penumbra_asset_id" => Ok(GeneratedField::PenumbraAssetId),
"images" => Ok(GeneratedField::Images),
"priorityScore" | "priority_score" => Ok(GeneratedField::PriorityScore),
"badges" => Ok(GeneratedField::Badges),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand Down Expand Up @@ -1162,6 +1171,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
let mut penumbra_asset_id__ = None;
let mut images__ = None;
let mut priority_score__ = None;
let mut badges__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::Description => {
Expand Down Expand Up @@ -1220,6 +1230,12 @@ impl<'de> serde::Deserialize<'de> for Metadata {
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::Badges => {
if badges__.is_some() {
return Err(serde::de::Error::duplicate_field("badges"));
}
badges__ = Some(map_.next_value()?);
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -1235,6 +1251,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
penumbra_asset_id: penumbra_asset_id__,
images: images__.unwrap_or_default(),
priority_score: priority_score__.unwrap_or_default(),
badges: badges__.unwrap_or_default(),
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
4 changes: 4 additions & 0 deletions proto/penumbra/penumbra/core/asset/v1/asset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ message Metadata {
//
// This is solely for use in client-side registries.
uint64 priority_score = 1986;

// Associated icons for asset.
// For ibc assets, usually an image of the source chain.
repeated AssetImage badges = 1987;
}

// DenomUnit represents a struct that describes a given denomination unit of the basic token.
Expand Down

0 comments on commit 71a1b7d

Please sign in to comment.