From cfb6a7e6877a7d3c78c7d05f51330a13ce83dc33 Mon Sep 17 00:00:00 2001 From: Nafiu Ishaq <63783380+nafiuishaaq@users.noreply.github.com> Date: Sat, 21 Feb 2026 07:11:24 +0000 Subject: [PATCH 1/3] implemented the issue --- contract/src/types.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contract/src/types.rs b/contract/src/types.rs index 3e11e96eb..54bb416de 100644 --- a/contract/src/types.rs +++ b/contract/src/types.rs @@ -82,6 +82,13 @@ pub struct Room { pub created_at: u64, } +#[contracttype] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct ClaimWindowConfig { + pub is_enabled: bool, + pub claim_validity_ledgers: u32, +} + #[derive(Clone)] #[contracttype] pub enum DataKey { @@ -89,6 +96,8 @@ pub enum DataKey { Room(u128), RoomNames, // Global set of taken room names NextRoomId, // Counter for generating unique room IDs + Admin, // Admin address + ClaimWindowConfig, // Claim window configuration } #[cfg(test)] From 50fb3eec0a8542cac5ef8b82b8a599f991ea8a28 Mon Sep 17 00:00:00 2001 From: Nafiu Ishaq <63783380+nafiuishaaq@users.noreply.github.com> Date: Sat, 21 Feb 2026 07:11:39 +0000 Subject: [PATCH 2/3] implemented theclaim --- contract/src/error.rs | 2 ++ contract/src/lib.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/contract/src/error.rs b/contract/src/error.rs index 5bbd12fdd..b9e784e88 100644 --- a/contract/src/error.rs +++ b/contract/src/error.rs @@ -20,6 +20,8 @@ pub enum Error { OnlyRoomCreatorCanUpdate = 14, OnlyRoomCreatorCanDeactivate = 15, StorageError = 16, + AdminNotAuthorized = 17, + InvalidClaimValidityLedgers = 18, } pub fn handle_error(env: &Env, error: Error) -> ! { diff --git a/contract/src/lib.rs b/contract/src/lib.rs index c33fec159..9d57d808f 100644 --- a/contract/src/lib.rs +++ b/contract/src/lib.rs @@ -6,11 +6,18 @@ pub mod users; pub mod error; use rooms::rooms::RoomManager; -use soroban_sdk::{contract, contractimpl, Address, Env, Map, String}; -use types::{Room, RoomType, UserProfile}; +use soroban_sdk::{contract, contractimpl, contractevent, Address, Env, Map, String, symbol_short}; +use types::{Room, RoomType, UserProfile, ClaimWindowConfig, DataKey}; use users::users::UserManager; use crate::error::{Error}; +#[contractevent] +#[derive(Clone, Debug)] +pub struct ClaimConfigUpdated { + pub admin: Address, + pub old_config: ClaimWindowConfig, + pub new_config: ClaimWindowConfig, +} #[contract] pub struct WhsprContract; From 577de0dc288600fc6d4eb2f527451efe3acdc9fa Mon Sep 17 00:00:00 2001 From: Nafiu Ishaq <63783380+nafiuishaaq@users.noreply.github.com> Date: Sat, 21 Feb 2026 07:11:56 +0000 Subject: [PATCH 3/3] implemented the lib --- contract/src/lib.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/contract/src/lib.rs b/contract/src/lib.rs index 9d57d808f..7f2ee35be 100644 --- a/contract/src/lib.rs +++ b/contract/src/lib.rs @@ -80,6 +80,58 @@ impl WhsprContract { pub fn deactivate_room(env: Env, creator: Address, room_id: u128) -> Result { RoomManager::deactivate_room(&env, creator, room_id) } + + // Claim Window Configuration Functions + pub fn set_claim_window_config(env: Env, admin: Address, config: ClaimWindowConfig) -> Result<(), Error> { + admin.require_auth(); + + // Validate that admin is authorized + let admin_key = DataKey::Admin; + let stored_admin: Option
= env.storage().persistent().get(&admin_key); + + // If admin is set, only the stored admin can update config + // If admin is not set yet, allow the first caller to set it and update config + if let Some(stored_admin_addr) = stored_admin { + if admin != stored_admin_addr { + return Err(Error::AdminNotAuthorized); + } + } else { + // First time setting up - store the admin + env.storage().persistent().set(&admin_key, &admin); + } + + // Validate claim_validity_ledgers + if config.claim_validity_ledgers == 0 || config.claim_validity_ledgers >= 1_000_000 { + return Err(Error::InvalidClaimValidityLedgers); + } + + // Get old config or create default + let config_key = DataKey::ClaimWindowConfig; + let old_config: ClaimWindowConfig = env.storage().persistent().get(&config_key).unwrap_or(ClaimWindowConfig { + is_enabled: false, + claim_validity_ledgers: 0, + }); + + // Store new config + env.storage().persistent().set(&config_key, &config); + + // Emit event with old and new configs + env.events().publish( + (symbol_short!("claim_cfg_upd"),), + (admin.clone(), old_config, config.clone()), + ); + + Ok(()) + } + + pub fn get_claim_window_config(env: Env) -> Result { + let config_key = DataKey::ClaimWindowConfig; + let config: ClaimWindowConfig = env.storage().persistent().get(&config_key).unwrap_or(ClaimWindowConfig { + is_enabled: false, + claim_validity_ledgers: 0, + }); + Ok(config) + } } #[cfg(test)]