Save an attestation to the repository. Serializes the attestation to disk and registers it in the graph with `node_type::ATTESTATION`. Also registers dependencies from `changes_covered` in the DEPS table so the graph knows which changes this attestation covers. # Arguments `attestation` - The attestation to save # Returns The content hash of the saved attestation.
(
&self,
attestation: &atomic_core::change::Attestation,
)
| 253 | /// |
| 254 | /// The content hash of the saved attestation. |
| 255 | pub fn save_attestation( |
| 256 | &self, |
| 257 | attestation: &atomic_core::change::Attestation, |
| 258 | ) -> Result<Hash, RepositoryError> { |
| 259 | use atomic_core::pristine::MutTxnT; |
| 260 | |
| 261 | // Save to disk |
| 262 | let hash = self |
| 263 | .change_store |
| 264 | .save_attestation(attestation) |
| 265 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 266 | |
| 267 | // Register in the graph |
| 268 | let mut txn = self |
| 269 | .pristine |
| 270 | .write_txn() |
| 271 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 272 | |
| 273 | let attest_id = txn |
| 274 | .register_attestation(&hash) |
| 275 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 276 | |
| 277 | // Register dependencies: attestation → covered changes |
| 278 | for change_hash in &attestation.changes_covered { |
| 279 | if let Ok(Some(change_id)) = txn.get_internal(change_hash) { |
| 280 | txn.put_dep(attest_id, change_id) |
| 281 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // If chained, register dependency on previous attestation too |
| 286 | if let Some(ref prev_hash) = attestation.previous_attestation { |
| 287 | if let Ok(Some(prev_id)) = txn.get_internal(prev_hash) { |
| 288 | txn.put_dep(attest_id, prev_id) |
| 289 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | txn.commit() |
| 294 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 295 | |
| 296 | Ok(hash) |
| 297 | } |
| 298 | |
| 299 | /// Load an attestation from the repository by hash. |
| 300 | pub fn load_attestation( |