Skip to content

Commit

Permalink
auction: fuse both views in dutch:actions::view
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed May 1, 2024
1 parent b80a970 commit a7714b6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ pub use withdraw::ActionDutchAuctionWithdraw;

pub mod plan;
pub use plan::ActionDutchAuctionWithdrawPlan;

pub mod view;
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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<ValueView>,
}

/* Protobuf impls */
impl DomainType for ActionDutchAuctionScheduleView {
type Proto = pb::ActionDutchAuctionScheduleView;
Expand Down Expand Up @@ -66,3 +83,40 @@ impl TryFrom<pb::ActionDutchAuctionScheduleView> for ActionDutchAuctionScheduleV
})
}
}
/* Protobuf impls */
impl DomainType for ActionDutchAuctionWithdrawView {
type Proto = pb::ActionDutchAuctionWithdrawView;
}

impl From<ActionDutchAuctionWithdrawView> for pb::ActionDutchAuctionWithdrawView {
fn from(domain: ActionDutchAuctionWithdrawView) -> Self {
pb::ActionDutchAuctionWithdrawView {
action: Some(domain.action.into()),
reserves: domain
.reserves
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
}
}
}

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

fn try_from(msg: pb::ActionDutchAuctionWithdrawView) -> Result<Self, Self::Error> {
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::<Result<_, _>>()?,
})
}
}

This file was deleted.

0 comments on commit a7714b6

Please sign in to comment.