(
&self,
request: Request<ListAttestationsRequest>,
)
| 3561 | } |
| 3562 | |
| 3563 | async fn list_attestations( |
| 3564 | &self, |
| 3565 | request: Request<ListAttestationsRequest>, |
| 3566 | ) -> Result<Response<ListAttestationsResponse>, Status> { |
| 3567 | let request = request.into_inner(); |
| 3568 | let handle = self.state.resolve(request.repository.as_ref().unwrap())?; |
| 3569 | self.state.log_rpc("ListAttestations", Some(&handle)); |
| 3570 | let gate_handle = handle.clone(); |
| 3571 | let _gate = gate_handle.exclusive().await; |
| 3572 | |
| 3573 | // `agent attest --hash <prefix>`: resolve ONE attestation by hash |
| 3574 | // or prefix (the hash names an attestation; the change-oriented Log |
| 3575 | // cannot resolve it) and serve its full detail — the domain |
| 3576 | // payload plus the per-view coverage — as versioned-opaque bytes |
| 3577 | // the client renders with its existing detail code. |
| 3578 | if let Some(prefix) = request.hash_prefix.clone().filter(|p| !p.is_empty()) { |
| 3579 | let handle_for_task = handle.clone(); |
| 3580 | let detail = tokio::task::spawn_blocking(move || -> Result<VersionedBytes, Status> { |
| 3581 | let repo = handle_for_task.repository()?; |
| 3582 | // Exact match first, then the prefix scan — the same |
| 3583 | // resolution the CLI's find_by_prefix performs. |
| 3584 | let mut matches: Vec<(atomic_core::types::Hash, Attestation)> = Vec::new(); |
| 3585 | if let Some(hash) = |
| 3586 | atomic_core::types::Hash::from_base32(prefix.as_bytes()) |
| 3587 | { |
| 3588 | if let Ok(attest) = repo.load_attestation(&hash) { |
| 3589 | return attestation_detail_bundle(&repo, &hash, &attest); |
| 3590 | } |
| 3591 | } |
| 3592 | let prefix_upper = prefix.to_uppercase(); |
| 3593 | for result in repo.change_store().iter_attestations() { |
| 3594 | let hash = match result { |
| 3595 | Ok(hash) => hash, |
| 3596 | Err(_) => continue, |
| 3597 | }; |
| 3598 | if hash.to_base32().starts_with(&prefix_upper) { |
| 3599 | if let Ok(attest) = repo.load_attestation(&hash) { |
| 3600 | matches.push((hash, attest)); |
| 3601 | } |
| 3602 | } |
| 3603 | } |
| 3604 | match matches.len() { |
| 3605 | 0 => Err(domain_status( |
| 3606 | ErrorCode::NotFound, |
| 3607 | format!("No attestation found matching '{prefix}'"), |
| 3608 | )), |
| 3609 | 1 => Ok(attestation_detail_bundle( |
| 3610 | &repo, |
| 3611 | &matches[0].0, |
| 3612 | &matches[0].1, |
| 3613 | )?), |
| 3614 | n => Err(domain_status( |
| 3615 | ErrorCode::NotFound, |
| 3616 | format!( |
| 3617 | "Ambiguous hash prefix '{prefix}' matches {n} attestations. Be more specific." |
| 3618 | ), |
| 3619 | )), |
| 3620 | } |
nothing calls this directly
no test coverage detected