-
Notifications
You must be signed in to change notification settings - Fork 15
Implement Batch Update Expert Profiles #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,3 +157,40 @@ pub fn update_profile(env: &Env, expert: &Address, new_uri: String) -> Result<() | |
| events::emit_profile_updated(env, expert.clone(), new_uri); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// 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)>, | ||
| ) -> Result<(), RegistryError> { | ||
| // Limit batch size to prevent DoS | ||
| if updates.len() > 20 { | ||
| return Err(RegistryError::ExpertVecMax); | ||
| } | ||
|
|
||
| let admin = storage::get_admin(env).ok_or(RegistryError::NotInitialized)?; | ||
| admin.require_auth(); | ||
|
|
||
| for update in updates { | ||
| let (expert, new_uri, status_u32) = update; | ||
|
|
||
| // Validate URI length | ||
| if new_uri.len() > 64 { | ||
| return Err(RegistryError::UriTooLong); | ||
| } | ||
|
|
||
| // Convert u32 to ExpertStatus | ||
| let status = match status_u32 { | ||
| 0 => ExpertStatus::Unverified, | ||
| 1 => ExpertStatus::Verified, | ||
| 2 => ExpertStatus::Banned, | ||
| _ => return Err(RegistryError::NotVerified), // Invalid status value | ||
| }; | ||
|
|
||
| // Update the expert record | ||
| storage::set_expert_record(env, &expert, status, new_uri); | ||
| } | ||
|
Comment on lines
+175
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't bypass the registry side effects in the batch path. On Line 192, this loop only calls π€ Prompt for AI Agents |
||
|
|
||
| Ok(()) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a dedicated error for malformed status values.
Line 188 maps an out-of-range
status_u32toRegistryError::NotVerified, which is indistinguishable from a real domain error. Callers cannot tell βbad requestβ from βexpert is not verified,β so retries and client-side validation become ambiguous. A separateInvalidStatus-style error would make this API much safer to consume.π€ Prompt for AI Agents