From 974dd5d11294d362cd164132eddc28935ec6c70a Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Wed, 22 May 2024 22:30:53 -0700 Subject: [PATCH] asset: add asset.v1.Metadata.priority_score This is intended to help support clients that need to display lists of assets. An asset registry can assign rankings to tokens, and frontend software can consume them without needing to have its own opinions about what the ranking should be. For instance, a registry could have hardcoded "tiers" or priorities, or priorities assigned by market cap, or the user's balances, etc. --- crates/core/asset/src/asset/denom_metadata.rs | 6 +++++ .../proto/src/gen/penumbra.core.asset.v1.rs | 5 +++++ .../src/gen/penumbra.core.asset.v1.serde.rs | 21 ++++++++++++++++++ .../proto/src/gen/proto_descriptor.bin.no_lfs | Bin 529831 -> 530043 bytes .../penumbra/core/asset/v1/asset.proto | 5 +++++ 5 files changed, 37 insertions(+) diff --git a/crates/core/asset/src/asset/denom_metadata.rs b/crates/core/asset/src/asset/denom_metadata.rs index a43a1c7b9e..7b64780f62 100644 --- a/crates/core/asset/src/asset/denom_metadata.rs +++ b/crates/core/asset/src/asset/denom_metadata.rs @@ -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, + priority_score: u64, /// Sorted by priority order. pub(super) units: Vec, @@ -64,6 +65,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(), + priority_score: inner.priority_score, } } } @@ -129,6 +131,7 @@ impl TryFrom for Inner { name: value.name, symbol: value.symbol, images: value.images, + priority_score: value.priority_score, }) } } @@ -250,6 +253,7 @@ impl Inner { name: String::new(), symbol: String::new(), images: Vec::new(), + priority_score: 0, } } } @@ -416,6 +420,7 @@ impl Debug for Metadata { display_index, name, symbol, + priority_score, } = inner.as_ref(); f.debug_struct("Metadata") @@ -423,6 +428,7 @@ impl Debug for Metadata { .field("base_denom", base_denom) .field("description", description) .field("images", images) + .field("priority_score", priority_score) .field("units", units) .field("display_index", display_index) .field("name", name) diff --git a/crates/proto/src/gen/penumbra.core.asset.v1.rs b/crates/proto/src/gen/penumbra.core.asset.v1.rs index 01187b7973..13edd5ca93 100644 --- a/crates/proto/src/gen/penumbra.core.asset.v1.rs +++ b/crates/proto/src/gen/penumbra.core.asset.v1.rs @@ -84,6 +84,11 @@ pub struct Metadata { pub penumbra_asset_id: ::core::option::Option, #[prost(message, repeated, tag = "1985")] pub images: ::prost::alloc::vec::Vec, + /// An optional "score" used to prioritize token lists. + /// + /// This is solely for use in client-side registries. + #[prost(uint64, tag = "1986")] + pub priority_score: u64, } impl ::prost::Name for Metadata { const NAME: &'static str = "Metadata"; diff --git a/crates/proto/src/gen/penumbra.core.asset.v1.serde.rs b/crates/proto/src/gen/penumbra.core.asset.v1.serde.rs index 9992e2e4f7..0eff480e20 100644 --- a/crates/proto/src/gen/penumbra.core.asset.v1.serde.rs +++ b/crates/proto/src/gen/penumbra.core.asset.v1.serde.rs @@ -1036,6 +1036,9 @@ impl serde::Serialize for Metadata { if !self.images.is_empty() { len += 1; } + if self.priority_score != 0 { + 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)?; @@ -1061,6 +1064,10 @@ impl serde::Serialize for Metadata { if !self.images.is_empty() { struct_ser.serialize_field("images", &self.images)?; } + if self.priority_score != 0 { + #[allow(clippy::needless_borrow)] + struct_ser.serialize_field("priorityScore", ToString::to_string(&self.priority_score).as_str())?; + } struct_ser.end() } } @@ -1081,6 +1088,8 @@ impl<'de> serde::Deserialize<'de> for Metadata { "penumbra_asset_id", "penumbraAssetId", "images", + "priority_score", + "priorityScore", ]; #[allow(clippy::enum_variant_names)] @@ -1093,6 +1102,7 @@ impl<'de> serde::Deserialize<'de> for Metadata { Symbol, PenumbraAssetId, Images, + PriorityScore, __SkipField__, } impl<'de> serde::Deserialize<'de> for GeneratedField { @@ -1123,6 +1133,7 @@ impl<'de> serde::Deserialize<'de> for Metadata { "symbol" => Ok(GeneratedField::Symbol), "penumbraAssetId" | "penumbra_asset_id" => Ok(GeneratedField::PenumbraAssetId), "images" => Ok(GeneratedField::Images), + "priorityScore" | "priority_score" => Ok(GeneratedField::PriorityScore), _ => Ok(GeneratedField::__SkipField__), } } @@ -1150,6 +1161,7 @@ impl<'de> serde::Deserialize<'de> for Metadata { let mut symbol__ = None; let mut penumbra_asset_id__ = None; let mut images__ = None; + let mut priority_score__ = None; while let Some(k) = map_.next_key()? { match k { GeneratedField::Description => { @@ -1200,6 +1212,14 @@ impl<'de> serde::Deserialize<'de> for Metadata { } images__ = Some(map_.next_value()?); } + GeneratedField::PriorityScore => { + if priority_score__.is_some() { + return Err(serde::de::Error::duplicate_field("priorityScore")); + } + priority_score__ = + Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0) + ; + } GeneratedField::__SkipField__ => { let _ = map_.next_value::()?; } @@ -1214,6 +1234,7 @@ impl<'de> serde::Deserialize<'de> for Metadata { symbol: symbol__.unwrap_or_default(), penumbra_asset_id: penumbra_asset_id__, images: images__.unwrap_or_default(), + priority_score: priority_score__.unwrap_or_default(), }) } } diff --git a/crates/proto/src/gen/proto_descriptor.bin.no_lfs b/crates/proto/src/gen/proto_descriptor.bin.no_lfs index 9eb18cdb73f4d4e5b435fd0ee81c2b9b0cde43f2..ea87649cbd5f9b87d224451df216830ff050c145 100644 GIT binary patch delta 2102 zcmYjST}&KR6y9^^?(EEk1$Ow`-9niHp-`c0X={t!#9(OMkf;P&Fu{hDc9f0CBD=Iu zO}Ek7Dkg?93DieIS{n7iWYxYJqmMSenlvUp`qW2beDOQ;vuna6eCM3+yWctYXAi!% z|NX}P_J@@A{DN}#vOSe&DV@Y4ZTH;I`cNftsGs_+KGm?YnlG&8OB?gWtA$l3`BS4! z{cZmn>gbQfk7mv~kgu&f8{;HpLdj~TOIU}Ji!o3s`OPkm|^;Dlcf&U>m5eNc7aKdcx1c4wpk+9T(@My?Q zKKcHs-a{EF2)xNEk2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`0m2l#**w^hF13yW6 zxqa-!pHeL=A*CZP#V+fo)#dahE32+4DW!-x#!>5) z)+0CD{;oDmBeNlaIA~{m0)a5wol~#4^};b4pPiX$HH7l>B92fps21QhoMMmzw^8a> z3U=d;yb`-g_-)8Is;*cmm4s%TJhupl#`#Az{ zUf2QRoN@vL-h8e{O~Hog$c5Ou+N@7?Eud?Ya9|oSM_w0i8@zUVSigUG=D8 zWpa-FE$S!rQ}spJqtYtj1+l_nzCXfPW3h4!ZSqJ+FKKghroJRQ!XobMQYsf=kd_KX z)$mE^Zc~3S`r2gkeLL$LvuB30x&dJ(S(4G^qMS& zbe_?gOh%aV9o-QIeXW%*U~KSYVJdgTJBB+%AQa!R9QVwaY;0W)c`4V{y37O!h3naJ zfS|cPFzC~e+K?yx6x-R5-XSps&t{`*P!;&r0D`x1{Di9F%-{mvjeVpapRK0v!oe8a zCD_5H{^RV(IM)N>8f^Mk2nb@Ec89wV5VSTsGd>ZiEj@j1IbETIaO4i*thtM};02EYMZI%=;AkoT&Hx%C+U2m7Cgpq1C!imM3j- zU-n20xnv+n19~d~LVAz7%0U*=dxYb{t}HhFfCQiCI3rL211d%Z*i{O$pg!QfenUzo zP>wC_>*V>zwSB^PJqcFaC%Z3z;OrA#v>A6fAgzBt|LPeXG5BU`vU5Je;2Oe{@l0Uv zwqrgd{58D(;v3ZYkgUA>FJSYQ5A@G3EsPxyo>E>KF$f({?sxzpbU?!+?xD2V*CP_e z-XZ&<^F9yt(S?QbVc;4uFb)IPfM6W%lqNnd WO%OhT&%h_~#qpUxmL?K!{`McLQ@hIm diff --git a/proto/penumbra/penumbra/core/asset/v1/asset.proto b/proto/penumbra/penumbra/core/asset/v1/asset.proto index 04abdcc6af..433e1c1a33 100644 --- a/proto/penumbra/penumbra/core/asset/v1/asset.proto +++ b/proto/penumbra/penumbra/core/asset/v1/asset.proto @@ -62,6 +62,11 @@ message Metadata { AssetId penumbra_asset_id = 1984; repeated AssetImage images = 1985; + + // An optional "score" used to prioritize token lists. + // + // This is solely for use in client-side registries. + uint64 priority_score = 1986; } // DenomUnit represents a struct that describes a given denomination unit of the basic token.