dash_sdk::platform

Trait FetchMany

source
pub trait FetchMany<K: Ord, O>
where Self: Sized, O: MockResponse + FromProof<Self::Request, Request = Self::Request, Response = <Self::Request as TransportRequest>::Response> + Send + Default + FromIterator<(K, Option<Self>)>,
{ type Request: TransportRequest + Into<<O as FromProof<<Self as FetchMany<K, O>>::Request>>::Request>; // Provided methods fn fetch_many<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, ) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + 'async_trait>> where Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait { ... } fn fetch_many_with_metadata<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, settings: Option<RequestSettings>, ) -> Pin<Box<dyn Future<Output = Result<(O, ResponseMetadata), Error>> + Send + 'async_trait>> where Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait { ... } fn fetch_many_with_metadata_and_proof<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, settings: Option<RequestSettings>, ) -> Pin<Box<dyn Future<Output = Result<(O, ResponseMetadata, Proof), Error>> + Send + 'async_trait>> where Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait { ... } fn fetch_by_identifiers<'life0, 'async_trait, I>( sdk: &'life0 Sdk, identifiers: I, ) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + 'async_trait>> where Vec<Identifier>: Query<<Self as FetchMany<K, O>>::Request>, I: 'async_trait + IntoIterator<Item = Identifier> + Send, Self: Send + 'async_trait, 'life0: 'async_trait { ... } fn fetch_many_with_limit<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, limit: u32, ) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + 'async_trait>> where LimitQuery<Q>: Query<<Self as FetchMany<K, O>>::Request>, Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait { ... } }
Expand description

Fetch multiple objects from Platform.

To fetch multiple objects from Platform, you need to define some query (criteria that fetched objects must match) and use FetchMany::fetch_many() for your object type.

You can also use convenience methods:

§Generic Parameters

  • K: The type of the key used to index the object
  • O: The type of returned container (eg. map) that holds the fetched objects

§Example

An example use case is to fetch multiple Data Contracts by their Identifiers. As [&[Identifier]] implements Query for this type of requests, you need to:

use dash_sdk::{Sdk, platform::{Query, Identifier, FetchMany, DataContract}};

let sdk = Sdk::new_mock();

let id1 = Identifier::new(SOME_IDENTIFIER_1);
let id2 = Identifier::new(SOME_IDENTIFIER_2);

let query = vec![id1, id2];

let data_contract = DataContract::fetch_many(&sdk, query);

Required Associated Types§

source

type Request: TransportRequest + Into<<O as FromProof<<Self as FetchMany<K, O>>::Request>>::Request>

Type of request used to fetch multiple objects from Platform.

Most likely, one of the types defined in dapi_grpc::platform::v0.

This type must implement [TransportRequest] and MockRequest.

Provided Methods§

source

fn fetch_many<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, ) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + 'async_trait>>
where Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait,

Fetch (or search) multiple objects on the Dash Platform

FetchMany::fetch_many() is an asynchronous method that fetches multiple objects from the Dash Platform.

Note that this method might introduce some predefined limit on the number of objects returned. If you need to specify the limit yourself, use FetchMany::fetch_many_with_limit() or LimitQuery instead.

§Per-object type documentation

See documentation of FetchMany trait implementations for each object type for more details, including list of supported queries.

§Generic Parameters
  • Q: The type of Query used to generate a request
§Parameters
  • sdk: An instance of Sdk.
  • query: A query parameter implementing Query to specify the data to be retrieved.
§Returns

Returns a Result containing either:

  • list of objects matching the Query indexed by a key type K, where an item can be None of the object was not found for provided key
  • Error.

Note that behavior when no items are found can be either empty collection or collection containing None values.

§Usage

See tests/fetch/document.rs for a full example.

§Error Handling

Any errors encountered during the execution are returned as Error instances.

source

fn fetch_many_with_metadata<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, settings: Option<RequestSettings>, ) -> Pin<Box<dyn Future<Output = Result<(O, ResponseMetadata), Error>> + Send + 'async_trait>>
where Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait,

Fetch multiple objects from Platform with metadata.

Fetch objects from Platform that satisfy the provided Query. This method allows you to retrieve the metadata associated with the response.

§Parameters
  • sdk: An instance of Sdk.
  • query: A query parameter implementing crate::platform::query::Query to specify the data to be fetched.
  • settings: An optional RequestSettings to give greater flexibility on the request.
§Returns

Returns a Result containing either:

  • A tuple (O, ResponseMetadata) where O is the collection of fetched objects, and ResponseMetadata contains metadata about the response.
  • Error when an error occurs.
§Error Handling

Any errors encountered during the execution are returned as Error instances.

source

fn fetch_many_with_metadata_and_proof<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, settings: Option<RequestSettings>, ) -> Pin<Box<dyn Future<Output = Result<(O, ResponseMetadata, Proof), Error>> + Send + 'async_trait>>
where Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait,

Fetch multiple objects from Platform with metadata and underlying proof.

Fetch objects from Platform that satisfy the provided Query. This method allows you to retrieve the metadata and the underlying proof associated with the response.

§Parameters
  • sdk: An instance of Sdk.
  • query: A query parameter implementing crate::platform::query::Query to specify the data to be fetched.
  • settings: An optional RequestSettings to give greater flexibility on the request.
§Returns

Returns a Result containing either:

  • A tuple (O, ResponseMetadata, Proof) where O is the collection of fetched objects, ResponseMetadata contains metadata about the response, and Proof is the underlying proof.
  • Error when an error occurs.
§Error Handling

Any errors encountered during the execution are returned as Error instances.

source

fn fetch_by_identifiers<'life0, 'async_trait, I>( sdk: &'life0 Sdk, identifiers: I, ) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + 'async_trait>>
where Vec<Identifier>: Query<<Self as FetchMany<K, O>>::Request>, I: 'async_trait + IntoIterator<Item = Identifier> + Send, Self: Send + 'async_trait, 'life0: 'async_trait,

Fetch multiple objects from Platform by their identifiers.

Convenience method to fetch multiple objects by their identifiers. See FetchMany and FetchMany::fetch_many() for more detailed documentation.

§Parameters
  • sdk: An instance of Sdk.
  • identifiers: A collection of Identifiers to fetch.
§Requirements

Vec<Identifier> must implement Query for Self::Request.

source

fn fetch_many_with_limit<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, limit: u32, ) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + 'async_trait>>
where LimitQuery<Q>: Query<<Self as FetchMany<K, O>>::Request>, Q: 'async_trait + Query<<Self as FetchMany<K, O>>::Request>, Self: Send + 'async_trait, 'life0: 'async_trait,

Fetch multiple objects from Platform with limit.

Fetches up to limit objects matching the query. See FetchMany and FetchMany::fetch_many() for more detailed documentation.

§Parameters
  • sdk: An instance of Sdk.
  • query: A query parameter implementing Query to specify the data to be retrieved.
  • limit: Maximum number of objects to fetch.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FetchMany<u16, IndexMap<u16, Option<ExtendedEpochInfo>>> for ExtendedEpochInfo

Retrieve epochs.

Returns ExtendedEpochInfos.

§Supported query types
source§

impl FetchMany<u64, VotePollsGroupedByTimestamp> for VotePoll

Fetch multiple vote polls grouped by timestamp.

§Supported query types
  • [VotePollsByEndDateDriveQuery]
source§

impl FetchMany<Vec<u8>, IndexMap<Vec<u8>, Option<Element>>> for Element

Fetch multiple elements.

§Supported query types
  • [KeysInPath]
source§

impl FetchMany<Identifier, Contenders> for ContenderWithSerializedDocument

Fetch multiple contenders for a contested document resource vote poll.

Returns Contender indexed by Identifier.

§Supported query types
  • [ContestedDocumentVotePollDriveQuery]
source§

impl FetchMany<Identifier, IndexMap<Identifier, Option<ResourceVote>>> for ResourceVote

Fetch votes of some identity for a contested document resource vote poll.

§Supported query types
  • [ContestedResourceVotesGivenByIdentityQuery]

Implementors§

source§

impl FetchMany<u32, IndexMap<u32, Option<IdentityPublicKey>>> for IdentityPublicKey

Retrieve public keys for a given identity.

Returns IdentityPublicKeys indexed by KeyID.

§Supported query types
source§

impl FetchMany<u32, IndexMap<u32, Option<u64>>> for ProtocolVersionVoteCount

Fetch information about number of votes for each protocol version upgrade.

Returns ProtocolVersionUpgrades indexed by ProtocolVersion.

§Supported query types

It requires no query, so you can use () as the query parameter.

§Example
use dash_sdk::{Sdk, platform::FetchMany, Error};
use drive_proof_verifier::types::{ProtocolVersionUpgrades, ProtocolVersionVoteCount};

let sdk = Sdk::new_mock();
let result: Result<ProtocolVersionUpgrades, Error> = ProtocolVersionVoteCount::fetch_many(&sdk, ()).await;
source§

impl FetchMany<usize, Voters> for Voter

  Fetch voters

§Supported query types
  • [ContestedDocumentVotePollVotesDriveQuery]
source§

impl FetchMany<Identifier, ContestedResources> for ContestedResource

Fetch multiple ContestedResource, indexed by Identifier.

§Supported query types
  • [VotePollsByDocumentTypeQuery]
source§

impl FetchMany<Identifier, IndexMap<Identifier, Option<DataContract>>> for DataContract

Fetch multiple data contracts.

Returns DataContracts indexed by Identifier.

§Supported query types
  • Vec - list of identifiers of data contracts to fetch
source§

impl FetchMany<Identifier, IndexMap<Identifier, Option<Document>>> for Document

Fetch documents from Platform.

Returns Documents indexed by their Identifier.

§Supported query types
source§

impl FetchMany<Identifier, IndexMap<Identifier, Option<u64>>> for IdentityBalance

Fetch multiple identity balances.

§Supported query types
  • Vec - list of identifiers of identities whose balance we want to fetch
source§

impl FetchMany<ProTxHash, IndexMap<ProTxHash, Option<MasternodeProtocolVote>>> for MasternodeProtocolVote

Fetch information about protocol version upgrade voted by each node.

Returns list of MasternodeProtocolVotes indexed by ProTxHash. Each item in this list represents node protxhash and its preferred protocol version.

§Supported query types
source§

impl FetchMany<ProTxHash, ProposerBlockCounts> for ProposerBlockCountById

Fetch information about the proposed block count by proposers for a given epoch.

Returns list of ProposerBlockCounts indexed by ProTxHash. Each item in this list represents node pro_tx_hash and the amount of blocks that were proposed.

§Supported query types
  • ProTxHash - proTxHash of an evonode to find; will return one evonode block count
source§

impl FetchMany<ProTxHash, ProposerBlockCounts> for ProposerBlockCountByRange

Fetch information about the proposed block count by proposers for a given epoch.

Returns list of ProposerBlockCounts indexed by ProTxHash. Each item in this list represents node protxhash and the amount of blocks that were proposed.

§Supported query types