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§
Sourcefn get_data_contract(
&self,
id: &Identifier,
platform_version: &PlatformVersion,
) -> Result<Option<Arc<DataContract>>, ContextProviderError>
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, orNoneif it does not. We use Arc to avoid copying the data contract.Err(Error): On failure, returns an error indicating why the operation failed.
Sourcefn get_token_configuration(
&self,
token_id: &Identifier,
) -> Result<Option<TokenConfiguration>, ContextProviderError>
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, orNoneif it does not. We use Arc to avoid copying the token configuration.Err(Error): On failure, returns an error indicating why the operation failed.
Sourcefn get_quorum_public_key(
&self,
quorum_type: u32,
quorum_hash: [u8; 32],
core_chain_locked_height: u32,
) -> Result<[u8; 48], ContextProviderError>
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.
Sourcefn get_platform_activation_height(
&self,
) -> Result<CoreBlockHeight, ContextProviderError>
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_rrErr(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>
impl<'a, T: ContextProvider + 'a> AsRef<dyn ContextProvider + 'a> for Arc<T>
Source§fn as_ref(&self) -> &(dyn ContextProvider + 'a)
fn as_ref(&self) -> &(dyn ContextProvider + 'a)
Implementations on Foreign Types§
Source§impl<T: ContextProvider> ContextProvider for Mutex<T>
impl<T: ContextProvider> ContextProvider for Mutex<T>
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>
Implementors§
impl ContextProvider for MockContextProvider
mocks only.