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

Method find_attestations_for_view

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

798 /// A vector of `(Hash, Attestation, Vec<Hash>)` where the third element
799 /// is the subset of `changes_covered` that are in this view.
800 pub fn find_attestations_for_view(
801 &self,
802 view_name: &str,
803 ) -> Result<Vec<(Hash, atomic_core::change::Attestation, Vec<Hash>)>, RepositoryError> {
804 use atomic_core::pristine::{node_type, GraphTxnT, ViewTxnT};
805 use std::collections::{HashMap, HashSet};
806
807 let txn = self
808 .pristine
809 .read_txn()
810 .map_err(|e| RepositoryError::Database(e.to_string()))?;
811
812 // Get the view
813 let view = match txn
814 .get_view(view_name)
815 .map_err(|e| RepositoryError::Database(e.to_string()))?
816 {
817 Some(s) => s,
818 None => return Ok(Vec::new()),
819 };
820
821 // Collect all change IDs and hashes in this view
822 let mut view_change_ids: HashSet<u64> = HashSet::new();
823 let mut view_change_hashes: HashSet<Hash> = HashSet::new();
824
825 let iter = txn
826 .iter_changes(&view, 0)
827 .map_err(|e| RepositoryError::Database(e.to_string()))?;
828
829 for result in iter {
830 let (_seq, change_id, _merkle) =
831 result.map_err(|e| RepositoryError::Database(e.to_string()))?;
832
833 view_change_ids.insert(change_id.get());
834
835 if let Ok(Some(hash)) = txn.get_external(change_id) {
836 view_change_hashes.insert(hash);
837 }
838 }
839
840 // For each change in the view, find attestation nodes via REV_DEPS
841 let mut seen_attestations: HashMap<Hash, (atomic_core::change::Attestation, Vec<Hash>)> =
842 HashMap::new();
843
844 for change_id_raw in &view_change_ids {
845 let change_id = NodeId::new(*change_id_raw);
846
847 let rev_deps = match txn.get_rev_deps(change_id) {
848 Ok(ids) => ids,
849 Err(_) => continue,
850 };
851
852 for dep_id in rev_deps {
853 // Check node type
854 let node_type_val = match txn.get_node_type(dep_id) {
855 Ok(Some(t)) => t,
856 _ => continue,
857 };

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