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

protos(view): add a subaccount filter to the OwnedPositionIds rpc #4992

Merged
merged 3 commits into from
Jan 17, 2025
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
6 changes: 6 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,9 @@ pub struct OwnedPositionIdsRequest {
pub trading_pair: ::core::option::Option<
super::super::core::component::dex::v1::TradingPair,
>,
/// If present, return only positions for this subaccount index.
#[prost(message, optional, tag = "3")]
pub subaccount: ::core::option::Option<super::super::core::keys::v1::AddressIndex>,
}
impl ::prost::Name for OwnedPositionIdsRequest {
const NAME: &'static str = "OwnedPositionIdsRequest";
Expand All @@ -1558,6 +1561,9 @@ pub struct OwnedPositionIdsResponse {
pub position_id: ::core::option::Option<
super::super::core::component::dex::v1::PositionId,
>,
/// The subaccount this position belongs to.
#[prost(message, optional, tag = "2")]
pub subaccount: ::core::option::Option<super::super::core::keys::v1::AddressIndex>,
}
impl ::prost::Name for OwnedPositionIdsResponse {
const NAME: &'static str = "OwnedPositionIdsResponse";
Expand Down
34 changes: 34 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4196,13 +4196,19 @@ impl serde::Serialize for OwnedPositionIdsRequest {
if self.trading_pair.is_some() {
len += 1;
}
if self.subaccount.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1.OwnedPositionIdsRequest", len)?;
if let Some(v) = self.position_state.as_ref() {
struct_ser.serialize_field("positionState", v)?;
}
if let Some(v) = self.trading_pair.as_ref() {
struct_ser.serialize_field("tradingPair", v)?;
}
if let Some(v) = self.subaccount.as_ref() {
struct_ser.serialize_field("subaccount", v)?;
}
struct_ser.end()
}
}
Expand All @@ -4217,12 +4223,14 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsRequest {
"positionState",
"trading_pair",
"tradingPair",
"subaccount",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
PositionState,
TradingPair,
Subaccount,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -4247,6 +4255,7 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsRequest {
match value {
"positionState" | "position_state" => Ok(GeneratedField::PositionState),
"tradingPair" | "trading_pair" => Ok(GeneratedField::TradingPair),
"subaccount" => Ok(GeneratedField::Subaccount),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -4268,6 +4277,7 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsRequest {
{
let mut position_state__ = None;
let mut trading_pair__ = None;
let mut subaccount__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::PositionState => {
Expand All @@ -4282,6 +4292,12 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsRequest {
}
trading_pair__ = map_.next_value()?;
}
GeneratedField::Subaccount => {
if subaccount__.is_some() {
return Err(serde::de::Error::duplicate_field("subaccount"));
}
subaccount__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -4290,6 +4306,7 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsRequest {
Ok(OwnedPositionIdsRequest {
position_state: position_state__,
trading_pair: trading_pair__,
subaccount: subaccount__,
})
}
}
Expand All @@ -4307,10 +4324,16 @@ impl serde::Serialize for OwnedPositionIdsResponse {
if self.position_id.is_some() {
len += 1;
}
if self.subaccount.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1.OwnedPositionIdsResponse", len)?;
if let Some(v) = self.position_id.as_ref() {
struct_ser.serialize_field("positionId", v)?;
}
if let Some(v) = self.subaccount.as_ref() {
struct_ser.serialize_field("subaccount", v)?;
}
struct_ser.end()
}
}
Expand All @@ -4323,11 +4346,13 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsResponse {
const FIELDS: &[&str] = &[
"position_id",
"positionId",
"subaccount",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
PositionId,
Subaccount,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -4351,6 +4376,7 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsResponse {
{
match value {
"positionId" | "position_id" => Ok(GeneratedField::PositionId),
"subaccount" => Ok(GeneratedField::Subaccount),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -4371,6 +4397,7 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsResponse {
V: serde::de::MapAccess<'de>,
{
let mut position_id__ = None;
let mut subaccount__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::PositionId => {
Expand All @@ -4379,13 +4406,20 @@ impl<'de> serde::Deserialize<'de> for OwnedPositionIdsResponse {
}
position_id__ = map_.next_value()?;
}
GeneratedField::Subaccount => {
if subaccount__.is_some() {
return Err(serde::de::Error::duplicate_field("subaccount"));
}
subaccount__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
}
}
Ok(OwnedPositionIdsResponse {
position_id: position_id__,
subaccount: subaccount__,
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
1 change: 1 addition & 0 deletions crates/view/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ where
tonic::Request::new(pb::OwnedPositionIdsRequest {
trading_pair: trading_pair.map(TryInto::try_into).transpose()?,
position_state: position_state.map(TryInto::try_into).transpose()?,
subaccount: None,
}),
);

Expand Down
4 changes: 4 additions & 0 deletions crates/view/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ impl ViewService for ViewServer {
let pb::OwnedPositionIdsRequest {
position_state,
trading_pair,
subaccount: _,
} = request.into_inner();

let position_state: Option<position::State> = position_state
Expand All @@ -1741,6 +1742,9 @@ impl ViewService for ViewServer {
for id in ids {
yield pb::OwnedPositionIdsResponse{
position_id: Some(id.into()),
// The rust view server does not index positions by subaccount,
// so this information is invisible to it.
subaccount: None,
}
}
};
Expand Down
9 changes: 6 additions & 3 deletions proto/penumbra/penumbra/view/v1/view.proto
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ service ViewService {

// There's only one transparent address per wallet, so this request has no parameters;
// the message exists to satisfy forward-compatibility properties.
message TransparentAddressRequest {
}
message TransparentAddressRequest {}

message TransparentAddressResponse {
// The raw (binary) transparent address
Expand Down Expand Up @@ -700,10 +699,14 @@ message OwnedPositionIdsRequest {
core.component.dex.v1.PositionState position_state = 1;
// If present, return only positions for this trading pair.
core.component.dex.v1.TradingPair trading_pair = 2;
// If present, return only positions for this subaccount index.
core.keys.v1.AddressIndex subaccount = 3;
}

message OwnedPositionIdsResponse {
core.component.dex.v1.PositionId position_id = 1;
// The subaccount this position belongs to.
core.keys.v1.AddressIndex subaccount = 2;
}

// Requests information on an asset by asset id
Expand Down Expand Up @@ -786,4 +789,4 @@ message UnbondingTokensByAddressIndexResponse {
// `true` if the `unbonding_delay` (from `StakeParameters`) has passed or the
// validator has unbonded.
bool claimable = 2;
}
}
Loading