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 dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
16use dpp::data_contract::document_type::DocumentTypeRef;
17use dpp::version::PlatformVersion;
18use grovedb::TransactionArg;
19
20impl Drive {
21    /// One page of groups matching a having bound, read without a proof.
22    pub fn execute_document_having_range_no_proof(
23        &self,
24        contract_id: [u8; 32],
25        document_type: DocumentTypeRef,
26        document_type_name: String,
27        mode: &DocumentHavingMode,
28        transaction: TransactionArg,
29        platform_version: &PlatformVersion,
30    ) -> Result<Vec<RankedEntry>, Error> {
31        let indexes = document_type.indexes();
32        let having_query = resolve_having_query_for_mode(
33            contract_id,
34            document_type,
35            document_type_name,
36            indexes,
37            mode,
38            platform_version,
39        )?;
40        having_query.execute_range_no_proof(self, transaction, platform_version)
41    }
42
43    /// Proof of one page of groups matching a having bound.
44    ///
45    /// The client verifies it with
46    /// [`DriveDocumentHavingQuery::verify_having_range_proof`](crate::query::DriveDocumentHavingQuery::verify_having_range_proof),
47    /// reconstructing the same query from the same contract — which is
48    /// why index resolution is shared with the no-proof executor.
49    pub fn execute_document_having_range_proof(
50        &self,
51        contract_id: [u8; 32],
52        document_type: DocumentTypeRef,
53        document_type_name: String,
54        mode: &DocumentHavingMode,
55        transaction: TransactionArg,
56        platform_version: &PlatformVersion,
57    ) -> Result<Vec<u8>, Error> {
58        let indexes = document_type.indexes();
59        let having_query = resolve_having_query_for_mode(
60            contract_id,
61            document_type,
62            document_type_name,
63            indexes,
64            mode,
65            platform_version,
66        )?;
67        having_query.execute_range_with_proof(self, transaction, platform_version)
68    }
69}