Skip to content

Commit

Permalink
auction: add auction_id_exists helper
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Apr 16, 2024
1 parent 542331f commit 12d8302
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/core/component/auction/src/component/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::sync::Arc;
use tendermint::v0_37::abci;
use tracing::instrument;

use crate::{auction::id::AuctionId, state_key};

pub struct Auction {}
impl Auction {}

Expand Down Expand Up @@ -43,7 +45,15 @@ impl Component for Auction {

/// Extension trait providing read access to auction data.
#[async_trait]
pub trait StateReadExt: StateRead {}
pub trait StateReadExt: StateRead {
/// Returns `true` if the suppied `auction_id` is already used.
async fn auction_id_exists(&self, auction_id: AuctionId) -> bool {
self.get_raw(&state_key::auction_store::by_id(auction_id))
.await
.expect("no storage errors")
.map_or(false, |_| true)
}
}

impl<T: StateRead + ?Sized> StateReadExt for T {}

Expand Down

0 comments on commit 12d8302

Please sign in to comment.