Skip to content
Open
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
25 changes: 13 additions & 12 deletions contracts/identity-registry-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn batch_add_experts(env: Env, experts: Vec<Address>) -> Result<(), Registry
}
// Default empty URI for batch adds
let empty_uri = String::from_str(&env, "");
storage::set_expert_record(&env, &expert, ExpertStatus::Verified, empty_uri);
storage::set_expert_record(&env, &expert, ExpertStatus::Verified, empty_uri, 0);
storage::add_expert_to_index(&env, &expert);
events::emit_status_change(&env, expert, status, ExpertStatus::Verified, admin.clone());
}
Expand All @@ -54,7 +54,7 @@ pub fn batch_ban_experts(env: Env, experts: Vec<Address>) -> Result<(), Registry
return Err(RegistryError::AlreadyBanned);
}
let existing = storage::get_expert_record(&env, &expert);
storage::set_expert_record(&env, &expert, ExpertStatus::Banned, existing.data_uri);
storage::set_expert_record(&env, &expert, ExpertStatus::Banned, existing.data_uri, existing.category_id);
events::emit_status_change(&env, expert, status, ExpertStatus::Banned, admin.clone());
}

Expand Down Expand Up @@ -82,6 +82,7 @@ pub fn verify_expert(
caller: &Address,
expert: &Address,
data_uri: String,
category_id: u32,
) -> Result<(), RegistryError> {
let admin = storage::get_admin(env).ok_or(RegistryError::NotInitialized)?;

Expand All @@ -104,7 +105,7 @@ pub fn verify_expert(
return Err(RegistryError::UriTooLong);
}

storage::set_expert_record(env, expert, ExpertStatus::Verified, data_uri);
storage::set_expert_record(env, expert, ExpertStatus::Verified, data_uri, category_id);
storage::add_expert_to_index(env, expert);

events::emit_status_change(
Expand Down Expand Up @@ -136,9 +137,9 @@ pub fn ban_expert(env: &Env, caller: &Address, expert: &Address) -> Result<(), R
return Err(RegistryError::AlreadyBanned);
}

// Preserve existing data_uri when banning
// Preserve existing data_uri and category_id when banning
let existing = storage::get_expert_record(env, expert);
storage::set_expert_record(env, expert, ExpertStatus::Banned, existing.data_uri);
storage::set_expert_record(env, expert, ExpertStatus::Banned, existing.data_uri, existing.category_id);

events::emit_status_change(
env,
Expand All @@ -162,9 +163,9 @@ pub fn unban_expert(env: &Env, expert: &Address) -> Result<(), RegistryError> {
return Err(RegistryError::NotBanned);
}

// Preserve existing data_uri when unbanning
// Preserve existing data_uri and category_id when unbanning
let existing = storage::get_expert_record(env, expert);
storage::set_expert_record(env, expert, ExpertStatus::Verified, existing.data_uri);
storage::set_expert_record(env, expert, ExpertStatus::Verified, existing.data_uri, existing.category_id);

events::emit_status_change(
env,
Expand Down Expand Up @@ -199,7 +200,7 @@ pub fn is_verified(env: &Env, expert: &Address) -> bool {
}

/// Allow a verified expert to update their own profile URI
pub fn update_profile(env: &Env, expert: &Address, new_uri: String) -> Result<(), RegistryError> {
pub fn update_profile(env: &Env, expert: &Address, new_uri: String, category_id: u32) -> Result<(), RegistryError> {
expert.require_auth();

// Validate URI length
Expand All @@ -213,7 +214,7 @@ pub fn update_profile(env: &Env, expert: &Address, new_uri: String) -> Result<()
}

// Update record preserving status
storage::set_expert_record(env, expert, status, new_uri.clone());
storage::set_expert_record(env, expert, status, new_uri.clone(), category_id);
events::emit_profile_updated(env, expert.clone(), new_uri);
Ok(())
}
Expand All @@ -222,7 +223,7 @@ pub fn update_profile(env: &Env, expert: &Address, new_uri: String) -> Result<()
/// Allows admins to update multiple expert metadata URIs in a single transaction
pub fn batch_update_profiles(
env: &Env,
updates: Vec<(Address, String, u32)>,
updates: Vec<(Address, String, u32, u32)>,
) -> Result<(), RegistryError> {
// Limit batch size to prevent DoS
if updates.len() > 20 {
Expand All @@ -233,7 +234,7 @@ pub fn batch_update_profiles(
admin.require_auth();

for update in updates {
let (expert, new_uri, status_u32) = update;
let (expert, new_uri, status_u32, category_id) = update;

// Validate URI length
if new_uri.len() > 64 {
Expand All @@ -249,7 +250,7 @@ pub fn batch_update_profiles(
};

// Update the expert record
storage::set_expert_record(env, &expert, status, new_uri);
storage::set_expert_record(env, &expert, status, new_uri, category_id);
}

Ok(())
Expand Down
9 changes: 5 additions & 4 deletions contracts/identity-registry-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ impl IdentityRegistryContract {
caller: Address,
expert: Address,
data_uri: String,
category_id: u32,
) -> Result<(), RegistryError> {
contract::verify_expert(&env, &caller, &expert, data_uri)
contract::verify_expert(&env, &caller, &expert, data_uri, category_id)
}

/// Ban an expert and revoke their verification status (Admin or Moderator)
Expand Down Expand Up @@ -85,15 +86,15 @@ impl IdentityRegistryContract {
}

/// Allow a verified expert to update their own profile URI
pub fn update_profile(env: Env, expert: Address, new_uri: String) -> Result<(), RegistryError> {
contract::update_profile(&env, &expert, new_uri)
pub fn update_profile(env: Env, expert: Address, new_uri: String, category_id: u32) -> Result<(), RegistryError> {
contract::update_profile(&env, &expert, new_uri, category_id)
}

/// Batch update expert profiles (Admin only)
/// Allows admins to update multiple expert metadata URIs in a single transaction
pub fn batch_update_profiles(
env: Env,
updates: Vec<(Address, String, u32)>,
updates: Vec<(Address, String, u32, u32)>,
) -> Result<(), RegistryError> {
contract::batch_update_profiles(&env, updates)
}
Expand Down
4 changes: 3 additions & 1 deletion contracts/identity-registry-contract/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ pub fn remove_moderator(env: &Env, address: &Address) {
// ... [Expert Helpers] ...

/// Set the expert record with status, data_uri and timestamp
pub fn set_expert_record(env: &Env, expert: &Address, status: ExpertStatus, data_uri: String) {
pub fn set_expert_record(env: &Env, expert: &Address, status: ExpertStatus, data_uri: String, category_id: u32) {
let key = DataKey::Expert(expert.clone());

let record = ExpertRecord {
status,
updated_at: env.ledger().timestamp(),
data_uri,
category_id,
};

// 1. Save the data
Expand Down Expand Up @@ -107,6 +108,7 @@ pub fn get_expert_record(env: &Env, expert: &Address) -> ExpertRecord {
status: ExpertStatus::Unverified,
updated_at: 0,
data_uri: String::from_str(env, ""),
category_id: 0,
})
}

Expand Down
Loading
Loading