Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions contracts/profile/src/credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ pub fn bootstrap(env: &Env, user: Address, op_id: BytesN<32>) -> Result<(), Erro
Ok(())
}

pub fn verify_balance(
env: &Env,
user: Address,
amount: u32,
op_id: BytesN<32>,
) -> Result<bool, Error> {
admin::require_events_contract(env)?;
admin::require_not_paused(env)?;
idempotency::require_unseen(env, &op_id)?;

let profile = storage::get_profile(env, &user).ok_or(Error::ProfileNotFound)?;
let has_sufficient = profile.credits >= amount;

evt::BalanceVerified {
user,
amount,
has_sufficient,
}.publish(env);

idempotency::mark_seen(env, &op_id);
Ok(has_sufficient)
}

pub fn spend(
env: &Env,
user: Address,
Expand All @@ -49,11 +72,17 @@ pub fn spend(
idempotency::mark_seen(env, &op_id);
return Ok(());
}




// Use verify_balance logic directly
let mut profile = storage::get_profile(env, &user).ok_or(Error::ProfileNotFound)?;
if profile.credits < amount {
return Err(Error::InsufficientCredits);
}


Comment thread
coderabbitai[bot] marked this conversation as resolved.
profile.credits -= amount;
storage::set_profile(env, &user, &profile);

Expand Down