Skip to content

Commit

Permalink
Add skeleton for ActionDutchAuctionWithdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Apr 15, 2024
1 parent 7e90c07 commit c441d2f
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 0 deletions.
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pub use schedule::ActionDutchAuctionSchedule;

pub mod end;
pub use end::ActionDutchAuctionEnd;

pub mod withdraw;
pub use withdraw::ActionDutchAuctionWithdraw;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::auction::dutch::DutchAuctionauction_id;
use anyhow::anyhow;
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(
try_from = "pb::ActionDutchAuctionWithdraw",
into = "pb::ActionDutchAuctionWithdraw"
)]
pub struct ActionDutchAuctionWithdraw {
pub auction_id: AuctionId,
}

/* Protobuf impls */
impl DomainType for ActionDutchAuctionWithdraw {
type Proto = pb::ActionDutchAuctionWithdraw;
}

impl From<ActionDutchAuctionWithdraw> for pb::ActionDutchAuctionWithdraw {
fn from(domain: ActionDutchAuctionWithdraw) -> Self {
pb::ActionDutchAuctionWithdraw {
auction_id: Some(domain.auction_id.into()),
}
}
}

impl TryFrom<pb::ActionDutchAuctionWithdraw> for ActionDutchAuctionWithdraw {
type Error = anyhow::Error;

fn try_from(msg: pb::ActionDutchAuctionWithdraw) -> Result<Self, Self::Error> {
Ok(ActionDutchAuctionWithdraw {
auction_id: msg
.auction_id
.ok_or_else(|| {
anyhow!("ActionDutchAuctionWithdraw message is missing an auction_id")
})?
.try_into()?,
})
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod end;
mod schedule;
mod withdraw;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anyhow::Result;
use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::ActionHandler;

use crate::auction::dutch::actions::ActionDutchAuctionWithdraw;

#[async_trait]
impl ActionHandler for ActionDutchAuctionWithdraw {
type CheckStatelessContext = ();
async fn check_stateless(&self, _context: ()) -> Result<()> {
Ok(())
}

async fn check_and_execute<S: StateWrite>(&self, mut _state: S) -> Result<()> {
Ok(())
}
}
17 changes: 17 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.auction.v1alpha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,23 @@ impl ::prost::Name for ActionDutchAuctionEnd {
)
}
}
/// Withdraw funds from the ended auction associated with the specified `auction_id`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ActionDutchAuctionWithdraw {
/// The auction to withdraw.
#[prost(message, optional, tag = "1")]
pub auction_id: ::core::option::Option<AuctionId>,
}
impl ::prost::Name for ActionDutchAuctionWithdraw {
const NAME: &'static str = "ActionDutchAuctionWithdraw";
const PACKAGE: &'static str = "penumbra.core.component.auction.v1alpha1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!(
"penumbra.core.component.auction.v1alpha1.{}", Self::NAME
)
}
}
/// Generated client implementations.
#[cfg(feature = "rpc")]
pub mod query_service_client {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,102 @@ impl<'de> serde::Deserialize<'de> for ActionDutchAuctionSchedule {
deserializer.deserialize_struct("penumbra.core.component.auction.v1alpha1.ActionDutchAuctionSchedule", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for ActionDutchAuctionWithdraw {
#[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.auction_id.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.auction.v1alpha1.ActionDutchAuctionWithdraw", len)?;
if let Some(v) = self.auction_id.as_ref() {
struct_ser.serialize_field("auctionId", v)?;
}
struct_ser.end()
}
}
impl<'de> serde::Deserialize<'de> for ActionDutchAuctionWithdraw {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"auction_id",
"auctionId",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
AuctionId,
__SkipField__,
}
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 {
"auctionId" | "auction_id" => Ok(GeneratedField::AuctionId),
_ => Ok(GeneratedField::__SkipField__),
}
}
}
deserializer.deserialize_identifier(GeneratedVisitor)
}
}
struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = ActionDutchAuctionWithdraw;

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

fn visit_map<V>(self, mut map_: V) -> std::result::Result<ActionDutchAuctionWithdraw, V::Error>
where
V: serde::de::MapAccess<'de>,
{
let mut auction_id__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::AuctionId => {
if auction_id__.is_some() {
return Err(serde::de::Error::duplicate_field("auctionId"));
}
auction_id__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
}
}
Ok(ActionDutchAuctionWithdraw {
auction_id: auction_id__,
})
}
}
deserializer.deserialize_struct("penumbra.core.component.auction.v1alpha1.ActionDutchAuctionWithdraw", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for AuctionId {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,9 @@ message ActionDutchAuctionEnd {
// The auction to end.
AuctionId auction_id = 1;
}

// Withdraw funds from the ended auction associated with the specified `auction_id`
message ActionDutchAuctionWithdraw {
// The auction to withdraw.
AuctionId auction_id = 1;
}

0 comments on commit c441d2f

Please sign in to comment.