Skip to main content

CodeStore

Trait CodeStore 

Source
pub trait CodeStore {
    // Required methods
    fn find_redeemable(
        &self,
        candidates: &[LookupKey],
        now: u64,
        scope: Option<&str>,
    ) -> impl Future<Output = Result<Option<RedeemableCode>, StoreError>>;
    fn claim_code(
        &self,
        req: &ClaimRequest<'_>,
    ) -> impl Future<Output = Result<ClaimOutcome, StoreError>>;
    fn insert_code(
        &self,
        record: CodeRecord,
    ) -> impl Future<Output = Result<(), StoreError>>;
    fn revoke_code(
        &self,
        code_id: &CodeId,
        scope: Option<&str>,
        now: u64,
    ) -> impl Future<Output = Result<(), StoreError>>;
}
Expand description

Atomic, single-winner code storage (RFC-005).

Implementors must guarantee:

  • find_redeemable never returns expired, used, or revoked records;
  • claim_code uses a conditional UPDATE (not read-then-write); the affected-row count is exactly 1 for a winner and 0 for all others;
  • changed > 1 is surfaced as StoreError::InvariantViolation, not silently mapped to Lost.

Required Methods§

Source

fn find_redeemable( &self, candidates: &[LookupKey], now: u64, scope: Option<&str>, ) -> impl Future<Output = Result<Option<RedeemableCode>, StoreError>>

Look up a redeemable code by its HMAC lookup key candidates.

Returns the first record that matches any candidate key and is currently redeemable (not used, revoked, or expired at now). Returns Ok(None) if no such record exists.

Source

fn claim_code( &self, req: &ClaimRequest<'_>, ) -> impl Future<Output = Result<ClaimOutcome, StoreError>>

Attempt to atomically claim a code record.

The adapter must execute a conditional UPDATE and classify via crate::state::classify_claim. Returns ClaimOutcome::Won if and only if exactly one row was updated.

Source

fn insert_code( &self, record: CodeRecord, ) -> impl Future<Output = Result<(), StoreError>>

Insert a new code record. Returns StoreError if the lookup key already exists (unique constraint violation on the HMAC column).

Source

fn revoke_code( &self, code_id: &CodeId, scope: Option<&str>, now: u64, ) -> impl Future<Output = Result<(), StoreError>>

Revoke a code by its record ID, scoped to scope when provided. Only affects records that are not yet used or revoked.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§