Trait dash_sdk::platform::ContextProvider

pub trait ContextProvider: Send + Sync {
    // Required methods
    fn get_quorum_public_key(
        &self,
        quorum_type: u32,
        quorum_hash: [u8; 32],
        core_chain_locked_height: u32,
    ) -> Result<[u8; 48], ContextProviderError>;
    fn get_data_contract(
        &self,
        id: &Identifier,
    ) -> Result<Option<Arc<DataContract>>, ContextProviderError>;
    fn get_platform_activation_height(
        &self,
    ) -> Result<u32, 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§

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.

fn get_data_contract( &self, id: &Identifier, ) -> 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.
§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.

fn get_platform_activation_height(&self) -> Result<u32, 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.

Implementations on Foreign Types§

§

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

§

fn get_data_contract( &self, id: &Identifier, ) -> Result<Option<Arc<DataContract>>, 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<u32, ContextProviderError>

Implementors§