Skip to content
Merged
Show file tree
Hide file tree
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
51 changes: 51 additions & 0 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,15 +764,66 @@ impl EscrowContract {
.get(&DataKey::Admin)
.ok_or(Error::Unauthorized)?;
admin.require_auth();
let already = env
.storage()
.persistent()
.get::<DataKey, bool>(&DataKey::AllowedToken(token.clone()))
.unwrap_or(false);
env.storage()
.persistent()
.set(&DataKey::AllowedToken(token), &true);
if !already {
let count: u32 = env
.storage()
.instance()
.get(&DataKey::AllowedTokenCount)
.unwrap_or(0);
env.storage()
.instance()
.set(&DataKey::AllowedTokenCount, &(count + 1));
}
env.storage()
.instance()
.set(&DataKey::AllowlistEnabled, &true);
Ok(())
}

/// Remove a token from the allowlist. Requires admin auth.
/// When the last token is removed, the allowlist is disabled.
pub fn remove_allowed_token(env: Env, token: Address) -> Result<(), Error> {
let admin: Address = env
.storage()
.instance()
.get(&DataKey::Admin)
.ok_or(Error::Unauthorized)?;
admin.require_auth();
let present = env
.storage()
.persistent()
.get::<DataKey, bool>(&DataKey::AllowedToken(token.clone()))
.unwrap_or(false);
if present {
env.storage()
.persistent()
.remove(&DataKey::AllowedToken(token));
let count: u32 = env
.storage()
.instance()
.get(&DataKey::AllowedTokenCount)
.unwrap_or(1);
let new_count = count.saturating_sub(1);
env.storage()
.instance()
.set(&DataKey::AllowedTokenCount, &new_count);
if new_count == 0 {
env.storage()
.instance()
.set(&DataKey::AllowlistEnabled, &false);
}
}
Ok(())
}

/// Internal helper: remove `match_id` from the `ActiveMatches` index.
fn remove_from_active(env: &Env, match_id: u64) {
let mut active: Vec<u64> = env
Expand Down
1 change: 1 addition & 0 deletions contracts/escrow/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ pub enum DataKey {
ActiveMatches,
AllowedToken(Address),
AllowlistEnabled,
AllowedTokenCount,
}
Loading