Skip to content

Commit

Permalink
auction(dutch): impl pb conversion for schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Apr 15, 2024
1 parent 0c82e9c commit 04f63d2
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::auction::dutch::DutchAuctionDescription;
use anyhow::anyhow;
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use serde::{Deserialize, Serialize};

Expand All @@ -10,3 +11,31 @@ use serde::{Deserialize, Serialize};
pub struct ActionDutchAuctionSchedule {
pub description: DutchAuctionDescription,
}

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

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

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

fn try_from(msg: pb::ActionDutchAuctionSchedule) -> Result<Self, Self::Error> {
Ok(ActionDutchAuctionSchedule {
description: msg
.description
.ok_or_else(|| {
anyhow!("ActionDutchAuctionSchedule message is missing a description")
})?
.try_into()?,
})
}
}

0 comments on commit 04f63d2

Please sign in to comment.