drive/query/
vote_query.rs

1use crate::drive::votes::paths::vote_contested_resource_identity_votes_tree_path_for_identity_vec;
2use crate::error::Error;
3use crate::query::Query;
4use bincode::{Decode, Encode};
5use dpp::identifier::Identifier;
6use dpp::voting::vote_polls::VotePoll;
7use grovedb::{PathQuery, SizedQuery};
8
9/// Vote Drive Query struct
10#[derive(Debug, PartialEq, Clone, Encode, Decode)]
11pub struct IdentityBasedVoteDriveQuery {
12    /// The identity who would have made the vote
13    pub identity_id: Identifier,
14    /// What vote poll are we asking for?
15    pub vote_poll: VotePoll,
16}
17
18impl IdentityBasedVoteDriveQuery {
19    /// Operations to construct a path query.
20    pub fn construct_path_query(&self) -> Result<PathQuery, Error> {
21        // First we should get the overall document_type_path
22        let path = vote_contested_resource_identity_votes_tree_path_for_identity_vec(
23            self.identity_id.as_bytes(),
24        );
25
26        let vote_id = self.vote_poll.unique_id()?;
27
28        let mut query = Query::new();
29        query.insert_key(vote_id.to_vec());
30
31        Ok(PathQuery::new(path, SizedQuery::new(query, Some(1), None)))
32    }
33}