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

Method find_attestations_for_view

atomic-repository/src/repository/changes.rs:820–928  ·  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

818 /// A vector of `(Hash, Attestation, Vec<Hash>)` where the third element
819 /// is the subset of `changes_covered` that are in this view.
820 pub fn find_attestations_for_view(
821 &self,
822 view_name: &str,
823 ) -> Result<Vec<(Hash, atomic_core::change::Attestation, Vec<Hash>)>, RepositoryError> {
824 use atomic_core::pristine::{node_type, GraphTxnT, ViewTxnT};
825 use std::collections::{HashMap, HashSet};
826
827 let txn = self
828 .pristine
829 .read_txn()
830 .map_err(|e| RepositoryError::Database(e.to_string()))?;
831
832 // Get the view
833 let view = match txn
834 .get_view(view_name)
835 .map_err(|e| RepositoryError::Database(e.to_string()))?
836 {
837 Some(s) => s,
838 None => return Ok(Vec::new()),
839 };
840
841 // Collect all change IDs and hashes in this view
842 let mut view_change_ids: HashSet<u64> = HashSet::new();
843 let mut view_change_hashes: HashSet<Hash> = HashSet::new();
844
845 let iter = txn
846 .iter_changes(&view, 0)
847 .map_err(|e| RepositoryError::Database(e.to_string()))?;
848
849 for result in iter {
850 let (_seq, change_id, _merkle) =
851 result.map_err(|e| RepositoryError::Database(e.to_string()))?;
852
853 view_change_ids.insert(change_id.get());
854
855 if let Ok(Some(hash)) = txn.get_external(change_id) {
856 view_change_hashes.insert(hash);
857 }
858 }
859
860 // For each change in the view, find attestation nodes via REV_DEPS
861 let mut seen_attestations: HashMap<Hash, (atomic_core::change::Attestation, Vec<Hash>)> =
862 HashMap::new();
863
864 for change_id_raw in &view_change_ids {
865 let change_id = NodeId::new(*change_id_raw);
866
867 let rev_deps = match txn.get_rev_deps(change_id) {
868 Ok(ids) => ids,
869 Err(_) => continue,
870 };
871
872 for dep_id in rev_deps {
873 // Check node type
874 let node_type_val = match txn.get_node_type(dep_id) {
875 Ok(Some(t)) => t,
876 _ => continue,
877 };

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