-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auction: define schedule action and AH validation scaffold (#4210)
## Describe your changes Create the action definition module and adds the `ActionDutchAuctionSchedule` domain + pb message. ## Issue ticket number and link Part of #4206. ## Checklist before requesting a review - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > Internal and the auction component is not hooked to the rest of the app yet
- Loading branch information
Showing
12 changed files
with
363 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
crates/core/component/auction/src/auction/dutch/actions/end.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use anyhow::anyhow; | ||
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::auction::id::AuctionId; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[serde( | ||
try_from = "pb::ActionDutchAuctionEnd", | ||
into = "pb::ActionDutchAuctionEnd" | ||
)] | ||
pub struct ActionDutchAuctionEnd { | ||
pub auction_id: AuctionId, | ||
} | ||
|
||
/* Protobuf impls */ | ||
impl DomainType for ActionDutchAuctionEnd { | ||
type Proto = pb::ActionDutchAuctionEnd; | ||
} | ||
|
||
impl From<ActionDutchAuctionEnd> for pb::ActionDutchAuctionEnd { | ||
fn from(domain: ActionDutchAuctionEnd) -> Self { | ||
pb::ActionDutchAuctionEnd { | ||
auction_id: Some(domain.auction_id.into()), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<pb::ActionDutchAuctionEnd> for ActionDutchAuctionEnd { | ||
type Error = anyhow::Error; | ||
|
||
fn try_from(msg: pb::ActionDutchAuctionEnd) -> Result<Self, Self::Error> { | ||
Ok(ActionDutchAuctionEnd { | ||
auction_id: msg | ||
.auction_id | ||
.ok_or_else(|| anyhow!("ActionDutchAuctionEnd message is missing an auction_id"))? | ||
.try_into()?, | ||
}) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/core/component/auction/src/auction/dutch/actions/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod schedule; | ||
pub use schedule::ActionDutchAuctionSchedule; | ||
|
||
pub mod end; | ||
pub use end::ActionDutchAuctionEnd; |
41 changes: 41 additions & 0 deletions
41
crates/core/component/auction/src/auction/dutch/actions/schedule.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::auction::dutch::DutchAuctionDescription; | ||
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::ActionDutchAuctionSchedule", | ||
into = "pb::ActionDutchAuctionSchedule" | ||
)] | ||
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()?, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// use cnidarium_component::ActionHandler; | ||
pub mod dutch; |
18 changes: 18 additions & 0 deletions
18
crates/core/component/auction/src/component/action_handler/dutch/end.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::ActionDutchAuctionEnd; | ||
|
||
#[async_trait] | ||
impl ActionHandler for ActionDutchAuctionEnd { | ||
type CheckStatelessContext = (); | ||
async fn check_stateless(&self, _context: ()) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
async fn check_and_execute<S: StateWrite>(&self, mut _state: S) -> Result<()> { | ||
Ok(()) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
crates/core/component/auction/src/component/action_handler/dutch/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod end; | ||
mod schedule; |
18 changes: 18 additions & 0 deletions
18
crates/core/component/auction/src/component/action_handler/dutch/schedule.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::ActionDutchAuctionSchedule; | ||
|
||
#[async_trait] | ||
impl ActionHandler for ActionDutchAuctionSchedule { | ||
type CheckStatelessContext = (); | ||
async fn check_stateless(&self, _context: ()) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
async fn check_and_execute<S: StateWrite>(&self, mut _state: S) -> Result<()> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
crates/proto/src/gen/penumbra.core.component.auction.v1alpha1.serde.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.