From a6023140f1d214e22a8cf75519b65078819c42e5 Mon Sep 17 00:00:00 2001 From: Erwan Or Date: Tue, 16 Apr 2024 13:21:58 -0400 Subject: [PATCH] auction: add `auction_id_exists` helper --- .../core/component/auction/src/component/auction.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/core/component/auction/src/component/auction.rs b/crates/core/component/auction/src/component/auction.rs index e726bba09f..f14203768c 100644 --- a/crates/core/component/auction/src/component/auction.rs +++ b/crates/core/component/auction/src/component/auction.rs @@ -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 {} @@ -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 StateReadExt for T {}