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:
- [FetchMany::fetch_many_by_identifiers()] - to fetch multiple objects by their identifiers,
- FetchMany::fetch_many_with_limit() - to fetch not more than
limit
objects.
§Generic Parameters
K
: The type of the key used to index the objectO
: 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:
- define Identifiers of data contracts to fetch,
- create a query by grouping identifiers in a collection, like a Vec or a slice,
- call DataContract::fetch_many() with the query and an instance of Sdk.
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§
sourcetype Request: TransportRequest + Into<<O as FromProof<<Self as FetchMany<K, O>>::Request>>::Request>
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§
sourcefn fetch_many<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + 'async_trait>>
fn fetch_many<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, ) -> Pin<Box<dyn Future<Output = Result<O, Error>> + Send + '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 implementingQuery
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.
sourcefn 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_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.
sourcefn 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>>
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>>
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
Object Safety§
Implementations on Foreign Types§
source§impl FetchMany<u16, BTreeMap<u16, Option<ExtendedEpochInfo>>> for ExtendedEpochInfo
impl FetchMany<u16, BTreeMap<u16, Option<ExtendedEpochInfo>>> for ExtendedEpochInfo
Retrieve epochs.
Returns ExtendedEpochInfos.
§Supported query types
- EpochQuery - query that specifies epoch matching criteria
- EpochIndex - epoch index of first object to find; will return up to DEFAULT_EPOCH_QUERY_LIMIT objects starting from this index
LimitQuery<EpochQuery>
,LimitQuery<EpochIndex>
- limit query that allows to specify maximum number of objects to fetch; see also FetchMany::fetch_many_with_limit().
type Request = GetEpochsInfoRequest
source§impl FetchMany<u32, BTreeMap<u32, Option<u64>>> for ProtocolVersionVoteCount
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
impl FetchMany<u64, VotePollsGroupedByTimestamp> for VotePoll
Fetch multiple vote polls grouped by timestamp.
§Supported query types
- [VotePollsByEndDateDriveQuery]
source§impl FetchMany<Identifier, BTreeMap<Identifier, Option<ResourceVote>>> for ResourceVote
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
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
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
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
- ProTxHash - proTxHash of first object to find; will return up to DEFAULT_NODES_VOTING_LIMIT objects
Option<ProTxHash>
- proTxHash that can be and Option; if it isNone
, the query will return all objectsLimitQuery<ProTxHash>
- limit query that allows to specify maximum number of objects to fetch; see also FetchMany::fetch_many_with_limit().
Implementors§
source§impl FetchMany<u32, BTreeMap<u32, Option<IdentityPublicKey>>> for IdentityPublicKey
impl FetchMany<u32, BTreeMap<u32, Option<IdentityPublicKey>>> for IdentityPublicKey
Retrieve public keys for a given identity.
Returns IdentityPublicKeys indexed by KeyID.
§Supported query types
- Identifier - Identity ID for which to retrieve keys
type Request = GetIdentityKeysRequest
source§impl FetchMany<Identifier, BTreeMap<Identifier, Option<DataContract>>> for DataContract
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
type Request = GetDataContractsRequest
source§impl FetchMany<Identifier, BTreeMap<Identifier, Option<Document>>> for Document
impl FetchMany<Identifier, BTreeMap<Identifier, Option<Document>>> for Document
Fetch documents from Platform.
Returns Documents indexed by their Identifier.
§Supported query types
- DriveQuery - query that specifies document matching criteria
- DocumentQuery