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

proto: add fields for crossreferencing swaps/swap claims #3809

Merged
merged 1 commit into from
Feb 15, 2024
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
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
2 changes: 2 additions & 0 deletions crates/core/component/dex/src/swap/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ impl From<SwapView> for pb::SwapView {
swap_view: Some(sv::SwapView::Visible(sv::Visible {
swap: Some(swap.into()),
swap_plaintext: Some(swap_plaintext.into()),
// Swap claim crossreferencing is not yet supported in the Rust stack.
claim_tx: None,
})),
},
SwapView::Opaque { swap } => Self {
Expand Down
2 changes: 2 additions & 0 deletions crates/core/component/dex/src/swap_claim/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ impl From<SwapClaimView> for pbd::SwapClaimView {
swap_claim: Some(swap_claim.into()),
output_1: Some(output_1.into()),
output_2: Some(output_2.into()),
// Swap claim crossreferencing is not yet supported in the Rust stack.
swap_tx: None,
})),
},
SwapClaimView::Opaque { swap_claim } => Self {
Expand Down
24 changes: 24 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.dex.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,25 @@ pub mod swap_view {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Visible {
/// The underlying Swap action being viewed.
#[prost(message, optional, tag = "1")]
pub swap: ::core::option::Option<super::Swap>,
/// The plaintext of the encrypted swap.
#[prost(message, optional, tag = "3")]
pub swap_plaintext: ::core::option::Option<super::SwapPlaintext>,
/// Optionally, a transaction hash for the transaction that claimed this
/// swap.
///
/// Presence of this field signals that the swap outputs have been claimed
/// and that the claim transaction is known to the view server. Absence of
/// this field does not indicate anything about the state of the swap.
///
/// This field allows frontends to more easily crossreference the sequence of
/// Swap/SwapClaim actions.
#[prost(message, optional, tag = "4")]
pub claim_tx: ::core::option::Option<
super::super::super::super::txhash::v1::TransactionId,
>,
}
impl ::prost::Name for Visible {
const NAME: &'static str = "Visible";
Expand Down Expand Up @@ -306,6 +321,15 @@ pub mod swap_claim_view {
pub output_2: ::core::option::Option<
super::super::super::shielded_pool::v1::NoteView,
>,
/// Optionally, a transaction hash for the transaction that created the swap
/// this action claims.
///
/// This field allows frontends to more easily crossreference the sequence of
/// Swap/SwapClaim actions.
#[prost(message, optional, tag = "4")]
pub swap_tx: ::core::option::Option<
super::super::super::super::txhash::v1::TransactionId,
>,
}
impl ::prost::Name for Visible {
const NAME: &'static str = "Visible";
Expand Down
36 changes: 36 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.dex.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6106,6 +6106,9 @@ impl serde::Serialize for swap_claim_view::Visible {
if self.output_2.is_some() {
len += 1;
}
if self.swap_tx.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.dex.v1.SwapClaimView.Visible", len)?;
if let Some(v) = self.swap_claim.as_ref() {
struct_ser.serialize_field("swapClaim", v)?;
Expand All @@ -6116,6 +6119,9 @@ impl serde::Serialize for swap_claim_view::Visible {
if let Some(v) = self.output_2.as_ref() {
struct_ser.serialize_field("output2", v)?;
}
if let Some(v) = self.swap_tx.as_ref() {
struct_ser.serialize_field("swapTx", v)?;
}
struct_ser.end()
}
}
Expand All @@ -6132,13 +6138,16 @@ impl<'de> serde::Deserialize<'de> for swap_claim_view::Visible {
"output1",
"output_2",
"output2",
"swap_tx",
"swapTx",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
SwapClaim,
Output1,
Output2,
SwapTx,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -6164,6 +6173,7 @@ impl<'de> serde::Deserialize<'de> for swap_claim_view::Visible {
"swapClaim" | "swap_claim" => Ok(GeneratedField::SwapClaim),
"output1" | "output_1" => Ok(GeneratedField::Output1),
"output2" | "output_2" => Ok(GeneratedField::Output2),
"swapTx" | "swap_tx" => Ok(GeneratedField::SwapTx),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -6186,6 +6196,7 @@ impl<'de> serde::Deserialize<'de> for swap_claim_view::Visible {
let mut swap_claim__ = None;
let mut output_1__ = None;
let mut output_2__ = None;
let mut swap_tx__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::SwapClaim => {
Expand All @@ -6206,6 +6217,12 @@ impl<'de> serde::Deserialize<'de> for swap_claim_view::Visible {
}
output_2__ = map_.next_value()?;
}
GeneratedField::SwapTx => {
if swap_tx__.is_some() {
return Err(serde::de::Error::duplicate_field("swapTx"));
}
swap_tx__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -6215,6 +6232,7 @@ impl<'de> serde::Deserialize<'de> for swap_claim_view::Visible {
swap_claim: swap_claim__,
output_1: output_1__,
output_2: output_2__,
swap_tx: swap_tx__,
})
}
}
Expand Down Expand Up @@ -7614,13 +7632,19 @@ impl serde::Serialize for swap_view::Visible {
if self.swap_plaintext.is_some() {
len += 1;
}
if self.claim_tx.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.dex.v1.SwapView.Visible", len)?;
if let Some(v) = self.swap.as_ref() {
struct_ser.serialize_field("swap", v)?;
}
if let Some(v) = self.swap_plaintext.as_ref() {
struct_ser.serialize_field("swapPlaintext", v)?;
}
if let Some(v) = self.claim_tx.as_ref() {
struct_ser.serialize_field("claimTx", v)?;
}
struct_ser.end()
}
}
Expand All @@ -7634,12 +7658,15 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
"swap",
"swap_plaintext",
"swapPlaintext",
"claim_tx",
"claimTx",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
Swap,
SwapPlaintext,
ClaimTx,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -7664,6 +7691,7 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
match value {
"swap" => Ok(GeneratedField::Swap),
"swapPlaintext" | "swap_plaintext" => Ok(GeneratedField::SwapPlaintext),
"claimTx" | "claim_tx" => Ok(GeneratedField::ClaimTx),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -7685,6 +7713,7 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
{
let mut swap__ = None;
let mut swap_plaintext__ = None;
let mut claim_tx__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::Swap => {
Expand All @@ -7699,6 +7728,12 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
}
swap_plaintext__ = map_.next_value()?;
}
GeneratedField::ClaimTx => {
if claim_tx__.is_some() {
return Err(serde::de::Error::duplicate_field("claimTx"));
}
claim_tx__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -7707,6 +7742,7 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
Ok(swap_view::Visible {
swap: swap__,
swap_plaintext: swap_plaintext__,
claim_tx: claim_tx__,
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
19 changes: 19 additions & 0 deletions proto/penumbra/penumbra/core/component/dex/v1/dex.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "penumbra/core/component/sct/v1/sct.proto";
import "penumbra/core/component/shielded_pool/v1/shielded_pool.proto";
import "penumbra/core/keys/v1/keys.proto";
import "penumbra/core/num/v1/num.proto";
import "penumbra/core/txhash/v1/txhash.proto";
import "penumbra/crypto/tct/v1/tct.proto";

// A Penumbra ZK swap proof.
Expand Down Expand Up @@ -119,8 +120,20 @@ message SwapClaimPlan {

message SwapView {
message Visible {
// The underlying Swap action being viewed.
dex.v1.Swap swap = 1;
// The plaintext of the encrypted swap.
dex.v1.SwapPlaintext swap_plaintext = 3;
// Optionally, a transaction hash for the transaction that claimed this
// swap.
//
// Presence of this field signals that the swap outputs have been claimed
// and that the claim transaction is known to the view server. Absence of
// this field does not indicate anything about the state of the swap.
//
// This field allows frontends to more easily crossreference the sequence of
// Swap/SwapClaim actions.
txhash.v1.TransactionId claim_tx = 4;
}

message Opaque {
Expand All @@ -138,6 +151,12 @@ message SwapClaimView {
dex.v1.SwapClaim swap_claim = 1;
shielded_pool.v1.NoteView output_1 = 2;
shielded_pool.v1.NoteView output_2 = 3;
// Optionally, a transaction hash for the transaction that created the swap
// this action claims.
//
// This field allows frontends to more easily crossreference the sequence of
// Swap/SwapClaim actions.
txhash.v1.TransactionId swap_tx = 4;
}
message Opaque {
dex.v1.SwapClaim swap_claim = 1;
Expand Down
Loading