From a7714b67820e45c7cde3ff82af8cdc768c96c55e Mon Sep 17 00:00:00 2001 From: Erwan Or Date: Tue, 30 Apr 2024 08:31:22 -0400 Subject: [PATCH] auction: fuse both views in `dutch:actions::view` --- .../auction/src/auction/dutch/actions/mod.rs | 2 + .../actions/{schedule_view.rs => view.rs} | 56 ++++++++++++++++++- .../auction/dutch/actions/withdraw_view.rs | 55 ------------------ 3 files changed, 57 insertions(+), 56 deletions(-) rename crates/core/component/auction/src/auction/dutch/actions/{schedule_view.rs => view.rs} (56%) delete mode 100644 crates/core/component/auction/src/auction/dutch/actions/withdraw_view.rs diff --git a/crates/core/component/auction/src/auction/dutch/actions/mod.rs b/crates/core/component/auction/src/auction/dutch/actions/mod.rs index 90d3c2a813..4b42da3352 100644 --- a/crates/core/component/auction/src/auction/dutch/actions/mod.rs +++ b/crates/core/component/auction/src/auction/dutch/actions/mod.rs @@ -9,3 +9,5 @@ pub use withdraw::ActionDutchAuctionWithdraw; pub mod plan; pub use plan::ActionDutchAuctionWithdrawPlan; + +pub mod view; diff --git a/crates/core/component/auction/src/auction/dutch/actions/schedule_view.rs b/crates/core/component/auction/src/auction/dutch/actions/view.rs similarity index 56% rename from crates/core/component/auction/src/auction/dutch/actions/schedule_view.rs rename to crates/core/component/auction/src/auction/dutch/actions/view.rs index 26099e60af..28b340276e 100644 --- a/crates/core/component/auction/src/auction/dutch/actions/schedule_view.rs +++ b/crates/core/component/auction/src/auction/dutch/actions/view.rs @@ -1,11 +1,16 @@ use crate::auction::{ - dutch::{actions::ActionDutchAuctionSchedule, asset::Metadata}, + dutch::{ + actions::{ActionDutchAuctionSchedule, ActionDutchAuctionWithdraw}, + asset::Metadata, + }, id::AuctionId, }; use anyhow::anyhow; +use penumbra_asset::ValueView; use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType}; use serde::{Deserialize, Serialize}; +/* Domain type definitions */ #[derive(Debug, Clone, Serialize, Deserialize)] #[serde( try_from = "pb::ActionDutchAuctionScheduleView", @@ -18,6 +23,18 @@ pub struct ActionDutchAuctionScheduleView { pub output_metadata: Metadata, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde( + try_from = "pb::ActionDutchAuctionWithdrawView", + into = "pb::ActionDutchAuctionWithdrawView" +)] +pub struct ActionDutchAuctionWithdrawView { + pub action: ActionDutchAuctionWithdraw, + // A sequence of values that sum together to the provided + // reserves commitment. + pub reserves: Vec, +} + /* Protobuf impls */ impl DomainType for ActionDutchAuctionScheduleView { type Proto = pb::ActionDutchAuctionScheduleView; @@ -66,3 +83,40 @@ impl TryFrom for ActionDutchAuctionScheduleV }) } } +/* Protobuf impls */ +impl DomainType for ActionDutchAuctionWithdrawView { + type Proto = pb::ActionDutchAuctionWithdrawView; +} + +impl From for pb::ActionDutchAuctionWithdrawView { + fn from(domain: ActionDutchAuctionWithdrawView) -> Self { + pb::ActionDutchAuctionWithdrawView { + action: Some(domain.action.into()), + reserves: domain + .reserves + .into_iter() + .map(Into::into) + .collect::>(), + } + } +} + +impl TryFrom for ActionDutchAuctionWithdrawView { + type Error = anyhow::Error; + + fn try_from(msg: pb::ActionDutchAuctionWithdrawView) -> Result { + Ok(ActionDutchAuctionWithdrawView { + action: msg + .action + .ok_or_else(|| { + anyhow!("ActionDutchAuctionWithdrawView message is missing an action") + })? + .try_into()?, + reserves: msg + .reserves + .into_iter() + .map(TryInto::try_into) + .collect::>()?, + }) + } +} diff --git a/crates/core/component/auction/src/auction/dutch/actions/withdraw_view.rs b/crates/core/component/auction/src/auction/dutch/actions/withdraw_view.rs deleted file mode 100644 index f53c3e9adf..0000000000 --- a/crates/core/component/auction/src/auction/dutch/actions/withdraw_view.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::auction::dutch::actions::ActionDutchAuctionWithdraw; -use anyhow::anyhow; -use penumbra_asset::ValueView; -use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType}; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde( - try_from = "pb::ActionDutchAuctionWithdrawView", - into = "pb::ActionDutchAuctionWithdrawView" -)] -pub struct ActionDutchAuctionWithdrawView { - pub action: ActionDutchAuctionWithdraw, - // A sequence of values that sum together to the provided - // reserves commitment. - pub reserves: Vec, -} - -/* Protobuf impls */ -impl DomainType for ActionDutchAuctionWithdrawView { - type Proto = pb::ActionDutchAuctionWithdrawView; -} - -impl From for pb::ActionDutchAuctionWithdrawView { - fn from(domain: ActionDutchAuctionWithdrawView) -> Self { - pb::ActionDutchAuctionWithdrawView { - action: Some(domain.action.into()), - reserves: domain - .reserves - .into_iter() - .map(Into::into) - .collect::>(), - } - } -} - -impl TryFrom for ActionDutchAuctionWithdrawView { - type Error = anyhow::Error; - - fn try_from(msg: pb::ActionDutchAuctionWithdrawView) -> Result { - Ok(ActionDutchAuctionWithdrawView { - action: msg - .action - .ok_or_else(|| { - anyhow!("ActionDutchAuctionWithdrawView message is missing an action") - })? - .try_into()?, - reserves: msg - .reserves - .into_iter() - .map(TryInto::try_into) - .collect::>()?, - }) - } -}