MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / find_attestations_for_view

Method find_attestations_for_view

atomic-repository/src/repository/changes.rs:396–504  ·  view source on GitHub ↗

Find all attestations relevant to a view. Iterates over all changes in the view, checks REV_DEPS for each, and collects unique attestations. Returns them with coverage info showing which changes each attestation covers within this view. # Arguments `view_name` - The name of the view to query # Returns A vector of `(Hash, Attestation, Vec )` where the third element is the subset of `chang

(
        &self,
        view_name: &str,
    )

Source from the content-addressed store, hash-verified

394 /// A vector of `(Hash, Attestation, Vec<Hash>)` where the third element
395 /// is the subset of `changes_covered` that are in this view.
396 pub fn find_attestations_for_view(
397 &self,
398 view_name: &str,
399 ) -> Result<Vec<(Hash, atomic_core::change::Attestation, Vec<Hash>)>, RepositoryError> {
400 use atomic_core::pristine::{node_type, GraphTxnT, ViewTxnT};
401 use std::collections::{HashMap, HashSet};
402
403 let txn = self
404 .pristine
405 .read_txn()
406 .map_err(|e| RepositoryError::Database(e.to_string()))?;
407
408 // Get the view
409 let view = match txn
410 .get_view(view_name)
411 .map_err(|e| RepositoryError::Database(e.to_string()))?
412 {
413 Some(s) => s,
414 None => return Ok(Vec::new()),
415 };
416
417 // Collect all change IDs and hashes in this view
418 let mut view_change_ids: HashSet<u64> = HashSet::new();
419 let mut view_change_hashes: HashSet<Hash> = HashSet::new();
420
421 let iter = txn
422 .iter_changes(&view, 0)
423 .map_err(|e| RepositoryError::Database(e.to_string()))?;
424
425 for result in iter {
426 let (_seq, change_id, _merkle) =
427 result.map_err(|e| RepositoryError::Database(e.to_string()))?;
428
429 view_change_ids.insert(change_id.get());
430
431 if let Ok(Some(hash)) = txn.get_external(change_id) {
432 view_change_hashes.insert(hash);
433 }
434 }
435
436 // For each change in the view, find attestation nodes via REV_DEPS
437 let mut seen_attestations: HashMap<Hash, (atomic_core::change::Attestation, Vec<Hash>)> =
438 HashMap::new();
439
440 for change_id_raw in &view_change_ids {
441 let change_id = NodeId::new(*change_id_raw);
442
443 let rev_deps = match txn.get_rev_deps(change_id) {
444 Ok(ids) => ids,
445 Err(_) => continue,
446 };
447
448 for dep_id in rev_deps {
449 // Check node type
450 let node_type_val = match txn.get_node_type(dep_id) {
451 Ok(Some(t)) => t,
452 _ => continue,
453 };

Callers 1

show_for_viewMethod · 0.80

Calls 15

read_txnMethod · 0.80
contains_keyMethod · 0.80
get_mutMethod · 0.80
covers_changeMethod · 0.80
getMethod · 0.65
get_viewMethod · 0.45
iter_changesMethod · 0.45
insertMethod · 0.45
get_externalMethod · 0.45
get_rev_depsMethod · 0.45
get_node_typeMethod · 0.45
containsMethod · 0.45

Tested by 1

show_for_viewMethod · 0.64