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:
- verify the code exists, is
active, and is not pastexpires_at; - verify the current seat count is
< cap; - flip the code
active→redeemed(stampinginvitee_did+redeemed_at); - insert the
beta_accessrow.
On a policy failure returns the matching RedeemError (the tx rolls back);
a real SQLite error propagates as the outer anyhow::Error.