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,
)
| 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 | }; |