pub trait Fetchwhere
Self: Sized + Debug + MockResponse + FromProof<Self::Request, Request = Self::Request, Response = <Self::Request as DapiRequest>::Response>,{
type Request: TransportRequest + Into<<Self as FromProof<<Self as Fetch>::Request>>::Request>;
// Provided methods
fn fetch<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
where Q: 'async_trait + Query<<Self as Fetch>::Request>,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn fetch_with_metadata<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
settings: Option<RequestSettings>,
) -> Pin<Box<dyn Future<Output = Result<(Option<Self>, ResponseMetadata), Error>> + Send + 'async_trait>>
where Q: 'async_trait + Query<<Self as Fetch>::Request>,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn fetch_with_metadata_and_proof<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
settings: Option<RequestSettings>,
) -> Pin<Box<dyn Future<Output = Result<(Option<Self>, ResponseMetadata, Proof), Error>> + Send + 'async_trait>>
where Q: 'async_trait + Query<<Self as Fetch>::Request>,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn fetch_with_settings<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
settings: RequestSettings,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
where Q: 'async_trait + Query<<Self as Fetch>::Request>,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn fetch_by_identifier<'life0, 'async_trait>(
sdk: &'life0 Sdk,
id: Identifier,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
where Identifier: Query<<Self as Fetch>::Request>,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
Trait implemented by objects that can be fetched from Platform.
To fetch an object from Platform, you need to define some query (criteria that fetched object must match) and use Fetch::fetch() for your object type.
Implementators of this trait should implement at least the fetch_with_metadata() method, as other methods are convenience methods that call it with default settings.
§Example
A common use case is to fetch an Identity object by its Identifier. As Identifier implements Query for identity requests, you need to:
- create a Query, which will be an Identifier instance that will be used to identify requested Identity,
- call Identity::fetch() with the query and an instance of Sdk.
use dash_sdk::{Sdk, platform::{Query, Identifier, Fetch, Identity}};
let sdk = Sdk::new_mock();
let query = Identifier::new(SOME_IDENTIFIER);
let identity = Identity::fetch(&sdk, query);
Required Associated Types§
Provided Methods§
sourcefn fetch<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
fn fetch<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, ) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
Fetch single object from Platform.
Fetch object from Platform that satisfies provided Query. Most often, the Query is an Identifier of the object to be fetched.
§Parameters
sdk
: An instance of Sdk.query
: A query parameter implementingcrate::platform::query::Query
to specify the data to be fetched.
§Returns
Returns:
Ok(Some(Self))
when object is foundOk(None)
when object is not foundErr(Error)
when an error occurs
§Error Handling
Any errors encountered during the execution are returned as Error instances.
sourcefn fetch_with_metadata<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
settings: Option<RequestSettings>,
) -> Pin<Box<dyn Future<Output = Result<(Option<Self>, ResponseMetadata), Error>> + Send + 'async_trait>>
fn fetch_with_metadata<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, settings: Option<RequestSettings>, ) -> Pin<Box<dyn Future<Output = Result<(Option<Self>, ResponseMetadata), Error>> + Send + 'async_trait>>
Fetch single object from Platform with metadata.
Fetch object from Platform that satisfies provided Query. Most often, the Query is an Identifier of the object to be fetched.
§Parameters
sdk
: An instance of Sdk.query
: A query parameter implementingcrate::platform::query::Query
to specify the data to be fetched.settings
: An optionalRequestSettings
to give greater flexibility on the request.
§Returns
Returns:
Ok(Some(Self))
when object is foundOk(None)
when object is not foundErr(Error)
when an error occurs
§Error Handling
Any errors encountered during the execution are returned as Error instances.
sourcefn fetch_with_metadata_and_proof<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
settings: Option<RequestSettings>,
) -> Pin<Box<dyn Future<Output = Result<(Option<Self>, ResponseMetadata, Proof), Error>> + Send + 'async_trait>>
fn fetch_with_metadata_and_proof<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, settings: Option<RequestSettings>, ) -> Pin<Box<dyn Future<Output = Result<(Option<Self>, ResponseMetadata, Proof), Error>> + Send + 'async_trait>>
Fetch single object from Platform with metadata and underlying proof.
Fetch object from Platform that satisfies provided Query. Most often, the Query is an Identifier of the object to be fetched.
This method is meant to give the user library a way to see the underlying proof for educational purposes. This method should most likely only be used for debugging.
§Parameters
sdk
: An instance of Sdk.query
: A query parameter implementingcrate::platform::query::Query
to specify the data to be fetched.settings
: An optionalRequestSettings
to give greater flexibility on the request.
§Returns
Returns:
Ok(Some(Self))
when object is foundOk(None)
when object is not foundErr(Error)
when an error occurs
§Error Handling
Any errors encountered during the execution are returned as Error instances.
sourcefn fetch_with_settings<'life0, 'async_trait, Q>(
sdk: &'life0 Sdk,
query: Q,
settings: RequestSettings,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
fn fetch_with_settings<'life0, 'async_trait, Q>( sdk: &'life0 Sdk, query: Q, settings: RequestSettings, ) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
Fetch single object from Platform.
Fetch object from Platform that satisfies provided Query. Most often, the Query is an Identifier of the object to be fetched.
§Parameters
sdk
: An instance of Sdk.query
: A query parameter implementingcrate::platform::query::Query
to specify the data to be fetched.settings
: Request settings for the connection to Platform.
§Returns
Returns:
Ok(Some(Self))
when object is foundOk(None)
when object is not foundErr(Error)
when an error occurs
§Error Handling
Any errors encountered during the execution are returned as Error instances.
sourcefn fetch_by_identifier<'life0, 'async_trait>(
sdk: &'life0 Sdk,
id: Identifier,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
fn fetch_by_identifier<'life0, 'async_trait>( sdk: &'life0 Sdk, id: Identifier, ) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
Fetch single object from Platform by identifier.
Convenience method that allows fetching objects by identifier for types that implement Query for Identifier.
See Fetch::fetch()
for more details.
§Parameters
sdk
: An instance of Sdk.id
: An Identifier of the object to be fetched.