Trait dash_sdk::platform::Fetch

source ·
pub trait Fetch
where 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:

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§

source

type Request: TransportRequest + Into<<Self as FromProof<<Self as Fetch>::Request>>::Request>

Type of request used to fetch data 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<'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,

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
§Returns

Returns:

  • Ok(Some(Self)) when object is found
  • Ok(None) when object is not found
  • Err(Error) when an error occurs
§Error Handling

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

source

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,

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 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:

  • Ok(Some(Self)) when object is found
  • Ok(None) when object is not found
  • Err(Error) when an error occurs
§Error Handling

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

source

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,

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 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:

  • Ok(Some(Self)) when object is found
  • Ok(None) when object is not found
  • Err(Error) when an error occurs
§Error Handling

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

source

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,

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 implementing crate::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 found
  • Ok(None) when object is not found
  • Err(Error) when an error occurs
§Error Handling

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

source

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,

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Fetch for DataContractHistory

source§

impl Fetch for ExtendedEpochInfo

source§

impl Fetch for IdentityBalance

source§

impl Fetch for IdentityBalanceAndRevision

source§

impl Fetch for IdentityContractNonceFetcher

source§

impl Fetch for IdentityNonceFetcher

source§

impl Fetch for PrefundedSpecializedBalance

source§

impl Fetch for TotalCreditsInPlatform

source§

impl Fetch for Vote

Implementors§