Skip to content

Commit

Permalink
Re-enable sweeping of unclaimed swaps (#2965)
Browse files Browse the repository at this point in the history
Re-enable sweeping of unclaimed swaps (#2965)

---------

Co-authored-by: aubrey <aubrey@penumbra.zone>
  • Loading branch information
zbuc and aubrika authored Sep 7, 2023
1 parent b4cb9aa commit ab79917
Show file tree
Hide file tree
Showing 11 changed files with 1,164 additions and 683 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1alpha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,21 @@ pub struct SwapByCommitmentResponse {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnclaimedSwapsRequest {
/// Identifies the account group to query.
#[prost(message, optional, tag = "1")]
pub account_group_id: ::core::option::Option<
super::super::core::crypto::v1alpha1::AccountGroupId,
>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnclaimedSwapsResponse {
#[prost(message, optional, tag = "1")]
pub swap: ::core::option::Option<SwapRecord>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NullifierStatusRequest {
#[prost(message, optional, tag = "2")]
pub nullifier: ::core::option::Option<
Expand Down Expand Up @@ -1123,6 +1138,29 @@ pub mod view_protocol_service_client {
);
self.inner.unary(request.into_request(), path, codec).await
}
/// Query for all unclaimed swaps.
pub async fn unclaimed_swaps(
&mut self,
request: impl tonic::IntoRequest<super::UnclaimedSwapsRequest>,
) -> Result<
tonic::Response<tonic::codec::Streaming<super::UnclaimedSwapsResponse>>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/penumbra.view.v1alpha1.ViewProtocolService/UnclaimedSwaps",
);
self.inner.server_streaming(request.into_request(), path, codec).await
}
/// Query for whether a nullifier has been spent, optionally waiting until it is spent.
pub async fn nullifier_status(
&mut self,
Expand Down Expand Up @@ -1490,6 +1528,17 @@ pub mod view_protocol_service_server {
&self,
request: tonic::Request<super::SwapByCommitmentRequest>,
) -> Result<tonic::Response<super::SwapByCommitmentResponse>, tonic::Status>;
/// Server streaming response type for the UnclaimedSwaps method.
type UnclaimedSwapsStream: futures_core::Stream<
Item = Result<super::UnclaimedSwapsResponse, tonic::Status>,
>
+ Send
+ 'static;
/// Query for all unclaimed swaps.
async fn unclaimed_swaps(
&self,
request: tonic::Request<super::UnclaimedSwapsRequest>,
) -> Result<tonic::Response<Self::UnclaimedSwapsStream>, tonic::Status>;
/// Query for whether a nullifier has been spent, optionally waiting until it is spent.
async fn nullifier_status(
&self,
Expand Down Expand Up @@ -2203,6 +2252,47 @@ pub mod view_protocol_service_server {
};
Box::pin(fut)
}
"/penumbra.view.v1alpha1.ViewProtocolService/UnclaimedSwaps" => {
#[allow(non_camel_case_types)]
struct UnclaimedSwapsSvc<T: ViewProtocolService>(pub Arc<T>);
impl<
T: ViewProtocolService,
> tonic::server::ServerStreamingService<super::UnclaimedSwapsRequest>
for UnclaimedSwapsSvc<T> {
type Response = super::UnclaimedSwapsResponse;
type ResponseStream = T::UnclaimedSwapsStream;
type Future = BoxFuture<
tonic::Response<Self::ResponseStream>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::UnclaimedSwapsRequest>,
) -> Self::Future {
let inner = self.0.clone();
let fut = async move {
(*inner).unclaimed_swaps(request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = UnclaimedSwapsSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
);
let res = grpc.server_streaming(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/penumbra.view.v1alpha1.ViewProtocolService/NullifierStatus" => {
#[allow(non_camel_case_types)]
struct NullifierStatusSvc<T: ViewProtocolService>(pub Arc<T>);
Expand Down
183 changes: 183 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1alpha1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5839,6 +5839,189 @@ impl<'de> serde::Deserialize<'de> for TransactionPlannerResponse {
deserializer.deserialize_struct("penumbra.view.v1alpha1.TransactionPlannerResponse", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for UnclaimedSwapsRequest {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let mut len = 0;
if self.account_group_id.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1alpha1.UnclaimedSwapsRequest", len)?;
if let Some(v) = self.account_group_id.as_ref() {
struct_ser.serialize_field("accountGroupId", v)?;
}
struct_ser.end()
}
}
impl<'de> serde::Deserialize<'de> for UnclaimedSwapsRequest {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"account_group_id",
"accountGroupId",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
AccountGroupId,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
struct GeneratedVisitor;

impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = GeneratedField;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
match value {
"accountGroupId" | "account_group_id" => Ok(GeneratedField::AccountGroupId),
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
}
}
}
deserializer.deserialize_identifier(GeneratedVisitor)
}
}
struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = UnclaimedSwapsRequest;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("struct penumbra.view.v1alpha1.UnclaimedSwapsRequest")
}

fn visit_map<V>(self, mut map: V) -> std::result::Result<UnclaimedSwapsRequest, V::Error>
where
V: serde::de::MapAccess<'de>,
{
let mut account_group_id__ = None;
while let Some(k) = map.next_key()? {
match k {
GeneratedField::AccountGroupId => {
if account_group_id__.is_some() {
return Err(serde::de::Error::duplicate_field("accountGroupId"));
}
account_group_id__ = map.next_value()?;
}
}
}
Ok(UnclaimedSwapsRequest {
account_group_id: account_group_id__,
})
}
}
deserializer.deserialize_struct("penumbra.view.v1alpha1.UnclaimedSwapsRequest", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for UnclaimedSwapsResponse {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let mut len = 0;
if self.swap.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1alpha1.UnclaimedSwapsResponse", len)?;
if let Some(v) = self.swap.as_ref() {
struct_ser.serialize_field("swap", v)?;
}
struct_ser.end()
}
}
impl<'de> serde::Deserialize<'de> for UnclaimedSwapsResponse {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"swap",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
Swap,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
struct GeneratedVisitor;

impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = GeneratedField;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
match value {
"swap" => Ok(GeneratedField::Swap),
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
}
}
}
deserializer.deserialize_identifier(GeneratedVisitor)
}
}
struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = UnclaimedSwapsResponse;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("struct penumbra.view.v1alpha1.UnclaimedSwapsResponse")
}

fn visit_map<V>(self, mut map: V) -> std::result::Result<UnclaimedSwapsResponse, V::Error>
where
V: serde::de::MapAccess<'de>,
{
let mut swap__ = None;
while let Some(k) = map.next_key()? {
match k {
GeneratedField::Swap => {
if swap__.is_some() {
return Err(serde::de::Error::duplicate_field("swap"));
}
swap__ = map.next_value()?;
}
}
}
Ok(UnclaimedSwapsResponse {
swap: swap__,
})
}
}
deserializer.deserialize_struct("penumbra.view.v1alpha1.UnclaimedSwapsResponse", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for ViewAuthRequest {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down
4 changes: 2 additions & 2 deletions crates/proto/src/gen/proto_descriptor.bin
Git LFS file not shown
35 changes: 35 additions & 0 deletions crates/view/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ pub trait ViewClient {
&mut self,
address_index: AddressIndex,
) -> Pin<Box<dyn Future<Output = Result<Address>> + Send + 'static>>;

/// Queries for unclaimed Swaps.
fn unclaimed_swaps(
&mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<SwapRecord>>> + Send + 'static>>;
}

// We need to tell `async_trait` not to add a `Send` bound to the boxed
Expand Down Expand Up @@ -872,4 +877,34 @@ where
}
.boxed()
}

fn unclaimed_swaps(
&mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<SwapRecord>>> + Send + 'static>> {
let mut self2 = self.clone();
async move {
let swaps_response = ViewProtocolServiceClient::unclaimed_swaps(
&mut self2,
tonic::Request::new(pb::UnclaimedSwapsRequest {
..Default::default()
}),
);
let pb_swaps: Vec<_> = swaps_response.await?.into_inner().try_collect().await?;

pb_swaps
.into_iter()
.map(|swap_rsp| {
let swap_record = swap_rsp
.swap
.ok_or_else(|| anyhow::anyhow!("empty UnclaimedSwapsResponse message"));

match swap_record {
Ok(swap) => swap.try_into(),
Err(e) => Err(e),
}
})
.collect()
}
.boxed()
}
}
Loading

0 comments on commit ab79917

Please sign in to comment.