Skip to main content

redeem_code

Function redeem_code 

Source
pub async fn redeem_code(
    pool: &SqlitePool,
    code: &str,
    did: &str,
    handle: Option<&str>,
    cap: i64,
) -> Result<Result<(), RedeemError>>
Expand description

Atomically redeem an invite code for did, granting a beta seat.

Runs entirely in one transaction so the capacity check and the seat grant cannot race (two redeems can’t both slip past a cap - 1 count). Steps:

  1. verify the code exists, is active, and is not past expires_at;
  2. verify the current seat count is < cap;
  3. flip the code activeredeemed (stamping invitee_did + redeemed_at);
  4. insert the beta_access row.

On a policy failure returns the matching RedeemError (the tx rolls back); a real SQLite error propagates as the outer anyhow::Error.