Trait dash_sdk::platform::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_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_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, BTreeMap<u16, Option<ExtendedEpochInfo>>> for ExtendedEpochInfo

Retrieve epochs.

Returns ExtendedEpochInfos.

§Supported query types
source§

impl FetchMany<u32, BTreeMap<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};
use drive_proof_verifier::types::ProtocolVersionVoteCount;

let sdk = Sdk::new_mock();
let result = ProtocolVersionVoteCount::fetch_many(&sdk, ()).await;
source§

impl FetchMany<u64, VotePollsGroupedByTimestamp> for VotePoll

Fetch multiple vote polls grouped by timestamp.

§Supported query types
  • [VotePollsByEndDateDriveQuery]
source§

impl FetchMany<usize, Voters> for Voter

  Fetch voters

§Supported query types
  • [ContestedDocumentVotePollVotesDriveQuery]
source§

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

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

§Supported query types
  • [ContestedResourceVotesGivenByIdentityQuery]
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, ContestedResources> for ContestedResource

Fetch multiple [ContestedResource], indexed by Identifier.

§Supported query types
  • [VotePollsByDocumentTypeQuery]
source§

impl FetchMany<ProTxHash, BTreeMap<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

Implementors§

source§

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

Retrieve public keys for a given identity.

Returns IdentityPublicKeys indexed by KeyID.

§Supported query types
source§

impl FetchMany<Identifier, BTreeMap<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, BTreeMap<Identifier, Option<Document>>> for Document

Fetch documents from Platform.

Returns Documents indexed by their Identifier.

§Supported query types