ContextProvider

Trait ContextProvider 

Source
pub trait ContextProvider: Send + Sync {
    // Required methods
    fn get_data_contract(
        &self,
        id: &Identifier,
        platform_version: &PlatformVersion,
    ) -> Result<Option<Arc<DataContract>>, ContextProviderError>;
    fn get_token_configuration(
        &self,
        token_id: &Identifier,
    ) -> Result<Option<TokenConfiguration>, ContextProviderError>;
    fn get_quorum_public_key(
        &self,
        quorum_type: u32,
        quorum_hash: [u8; 32],
        core_chain_locked_height: u32,
    ) -> Result<[u8; 48], ContextProviderError>;
    fn get_platform_activation_height(
        &self,
    ) -> Result<CoreBlockHeight, ContextProviderError>;
}
Expand description

Interface between the Sdk and state of the application.

ContextProvider is called by the FromProof trait (and similar) to get information about the application and/or network state, including data contracts that might be cached by the application or quorum public keys.

Developers using the Dash Platform SDK should implement this trait to provide required information to the Sdk, especially implementation of FromProof trait.

A ContextProvider should be thread-safe and manage timeouts and other concurrency-related issues internally, as the FromProof implementations can block on ContextProvider calls.

Required Methods§

Source

fn get_data_contract( &self, id: &Identifier, platform_version: &PlatformVersion, ) -> Result<Option<Arc<DataContract>>, ContextProviderError>

Fetches the data contract for a specified data contract ID. This method is used by FromProof implementations to fetch data contracts referenced in proofs.

§Arguments
  • data_contract_id: The ID of the data contract to fetch.
  • platform_version: The platform version to use.
§Returns
  • Ok(Option<Arc<DataContract>>): On success, returns the data contract if it exists, or None if it does not. We use Arc to avoid copying the data contract.
  • Err(Error): On failure, returns an error indicating why the operation failed.
Source

fn get_token_configuration( &self, token_id: &Identifier, ) -> Result<Option<TokenConfiguration>, ContextProviderError>

Fetches the token configuration for a specified token ID. This method is used by FromProof implementations to fetch token configurations referenced in proofs.

§Arguments
  • token_id: The ID of the token to fetch.
  • platform_version: The platform version to use.
§Returns
  • Ok(Option<TokenConfiguration>): On success, returns the token configuration if it exists, or None if it does not. We use Arc to avoid copying the token configuration.
  • Err(Error): On failure, returns an error indicating why the operation failed.
Source

fn get_quorum_public_key( &self, quorum_type: u32, quorum_hash: [u8; 32], core_chain_locked_height: u32, ) -> Result<[u8; 48], ContextProviderError>

Fetches the public key for a specified quorum.

§Arguments
  • quorum_type: The type of the quorum.
  • quorum_hash: The hash of the quorum. This is used to determine which quorum’s public key to fetch.
  • core_chain_locked_height: Core chain locked height for which the quorum must be valid
§Returns
  • Ok(Vec<u8>): On success, returns a byte vector representing the public key of the quorum.
  • Err(Error): On failure, returns an error indicating why the operation failed.
Source

fn get_platform_activation_height( &self, ) -> Result<CoreBlockHeight, ContextProviderError>

Gets the platform activation height from core. Once this has happened this can be hardcoded.

§Returns
  • Ok(CoreBlockHeight): On success, returns the platform activation height as defined by mn_rr
  • Err(Error): On failure, returns an error indicating why the operation failed.

Trait Implementations§

Source§

impl<'a, T: ContextProvider + 'a> AsRef<dyn ContextProvider + 'a> for Arc<T>

Source§

fn as_ref(&self) -> &(dyn ContextProvider + 'a)

Converts this type into a shared reference of the (usually inferred) input type.

Implementations on Foreign Types§

Source§

impl<T: ContextProvider> ContextProvider for Mutex<T>
where Self: Sync + Send,

Implementors§

Source§

impl ContextProvider for MockContextProvider

Available on crate feature mocks only.
Source§

impl<C: AsRef<dyn ContextProvider> + Send + Sync> ContextProvider for C