Skip to main content

drive/query/drive_document_having_query/
executors.rs

1//! Per-mode having-range executors on `impl Drive`. The dispatcher
2//! ([`super::drive_dispatcher`]) picks between the two executors on the
3//! request's `prove` flag.
4//!
5//! Mode-to-query resolution — covering-index pick + equality-pin
6//! encoding — is [`resolve_having_query_for_mode`], shared with the
7//! SDK's proof helpers: both surfaces and both sides read the same
8//! indexed tree, and sharing the resolution is what guarantees a proof
9//! and an unproven read are about the same subtree.
10
11use super::super::drive_document_ranked_query::RankedEntry;
12use super::{resolve_having_query_for_mode, DocumentHavingMode};
13use crate::drive::Drive;
14use crate::error::Error;
15use crate::query::ResolvedTimeRange;
16use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
17use dpp::data_contract::document_type::DocumentTypeRef;
18use dpp::version::PlatformVersion;
19use grovedb::TransactionArg;
20
21impl Drive {
22    /// One page of groups matching a having bound, read without a proof.
23    #[allow(clippy::too_many_arguments)]
24    pub fn execute_document_having_range_no_proof(
25        &self,
26        contract_id: [u8; 32],
27        document_type: DocumentTypeRef,
28        document_type_name: String,
29        mode: &DocumentHavingMode,
30        resolved_time_ranges: &[ResolvedTimeRange],
31        transaction: TransactionArg,
32        platform_version: &PlatformVersion,
33    ) -> Result<Vec<RankedEntry>, Error> {
34        let indexes = document_type.indexes();
35        let having_query = resolve_having_query_for_mode(
36            contract_id,
37            document_type,
38            document_type_name,
39            indexes,
40            mode,
41            resolved_time_ranges,
42            platform_version,
43        )?;
44        having_query.execute_range_no_proof(self, transaction, platform_version)
45    }
46
47    /// Proof of one page of groups matching a having bound.
48    ///
49    /// The client verifies it with
50    /// [`DriveDocumentHavingQuery::verify_having_range_proof`](crate::query::DriveDocumentHavingQuery::verify_having_range_proof),
51    /// reconstructing the same query from the same contract — which is
52    /// why index resolution is shared with the no-proof executor.
53    #[allow(clippy::too_many_arguments)]
54    pub fn execute_document_having_range_proof(
55        &self,
56        contract_id: [u8; 32],
57        document_type: DocumentTypeRef,
58        document_type_name: String,
59        mode: &DocumentHavingMode,
60        resolved_time_ranges: &[ResolvedTimeRange],
61        transaction: TransactionArg,
62        platform_version: &PlatformVersion,
63    ) -> Result<Vec<u8>, Error> {
64        let indexes = document_type.indexes();
65        let having_query = resolve_having_query_for_mode(
66            contract_id,
67            document_type,
68            document_type_name,
69            indexes,
70            mode,
71            resolved_time_ranges,
72            platform_version,
73        )?;
74        having_query.execute_range_with_proof(self, transaction, platform_version)
75    }
76}