moonproof-indexer-client 0.2.2

Rust client for the Midnight indexer's GraphQL API
Documentation
//! The `PublicDataProvider` trait — Rust mirror of the midnight-js `PublicDataProvider`,
//! extended to cover the full indexer v4 query + mutation surface.
//!
//! Consumers program against this trait so tests can use an in-memory fake and
//! production code can use `HttpIndexerClient`.

use moonproof_macros::async_trait;

use crate::{
    Block, BlockOffset, CommitteeMember, ConnectOptions, ContractAction, ContractActionOffset,
    DParameterChange, DustGenerationStatus, DustGenerations, EpochInfo, EpochPerf, FirstValidEpoch,
    IndexerError, MerkleTreeCollapsedUpdate, PoolMetadata, PresenceEvent, RegisteredStat,
    RegisteredTotals, Spo, SpoComposite, SpoIdentity, StakeShare, TermsAndConditionsChange,
    Transaction, TransactionOffset,
};

#[async_trait]
#[allow(clippy::too_many_arguments)]
pub trait PublicDataProvider: Send + Sync {
    // --- Chain reads ------------------------------------------------------

    /// Fetch a block by hash or height. With `offset = None`, returns the latest block.
    async fn block(&self, offset: Option<BlockOffset>) -> Result<Option<Block>, IndexerError>;

    /// Fetch a collapsed Merkle tree update for the zswap state tree.
    async fn zswap_merkle_tree_collapsed_update(
        &self,
        start_index: i64,
        end_index: i64,
    ) -> Result<MerkleTreeCollapsedUpdate, IndexerError>;

    /// Fetch transactions matching the offset.
    async fn transactions(
        &self,
        offset: TransactionOffset,
    ) -> Result<Vec<Transaction>, IndexerError>;

    /// Fetch the latest contract action at `address`.
    async fn contract_action(
        &self,
        address: &str,
        offset: Option<ContractActionOffset>,
    ) -> Result<Option<ContractAction>, IndexerError>;

    // --- Dust -------------------------------------------------------------

    async fn dust_generation_status(
        &self,
        cardano_reward_addresses: Vec<String>,
    ) -> Result<Vec<DustGenerationStatus>, IndexerError>;

    async fn dust_generations(
        &self,
        cardano_reward_addresses: Vec<String>,
    ) -> Result<Vec<DustGenerations>, IndexerError>;

    async fn dust_commitment_merkle_tree_update(
        &self,
        start_index: i64,
        end_index: i64,
    ) -> Result<MerkleTreeCollapsedUpdate, IndexerError>;

    async fn dust_generation_merkle_tree_update(
        &self,
        start_index: i64,
        end_index: i64,
    ) -> Result<MerkleTreeCollapsedUpdate, IndexerError>;

    // --- Governance history -----------------------------------------------

    async fn d_parameter_history(&self) -> Result<Vec<DParameterChange>, IndexerError>;

    async fn terms_and_conditions_history(
        &self,
    ) -> Result<Vec<TermsAndConditionsChange>, IndexerError>;

    // --- SPO identity / metadata / composite ------------------------------

    async fn spo_identities(
        &self,
        limit: Option<i64>,
        offset: Option<i64>,
    ) -> Result<Vec<SpoIdentity>, IndexerError>;

    async fn spo_identity_by_pool_id(
        &self,
        pool_id_hex: &str,
    ) -> Result<Option<SpoIdentity>, IndexerError>;

    async fn spo_count(&self) -> Result<Option<i64>, IndexerError>;

    async fn pool_metadata(&self, pool_id_hex: &str) -> Result<Option<PoolMetadata>, IndexerError>;

    async fn pool_metadata_list(
        &self,
        limit: Option<i64>,
        offset: Option<i64>,
        with_name_only: Option<bool>,
    ) -> Result<Vec<PoolMetadata>, IndexerError>;

    async fn spo_by_pool_id(&self, pool_id_hex: &str) -> Result<Option<Spo>, IndexerError>;

    async fn spo_list(
        &self,
        limit: Option<i64>,
        offset: Option<i64>,
        search: Option<String>,
    ) -> Result<Vec<Spo>, IndexerError>;

    async fn spo_composite_by_pool_id(
        &self,
        pool_id_hex: &str,
    ) -> Result<Option<SpoComposite>, IndexerError>;

    async fn stake_pool_operators(&self, limit: Option<i64>) -> Result<Vec<String>, IndexerError>;

    // --- Performance ------------------------------------------------------

    async fn spo_performance_latest(
        &self,
        limit: Option<i64>,
        offset: Option<i64>,
    ) -> Result<Vec<EpochPerf>, IndexerError>;

    async fn spo_performance_by_spo_sk(
        &self,
        spo_sk_hex: &str,
        limit: Option<i64>,
        offset: Option<i64>,
    ) -> Result<Vec<EpochPerf>, IndexerError>;

    async fn epoch_performance(
        &self,
        epoch: i64,
        limit: Option<i64>,
        offset: Option<i64>,
    ) -> Result<Vec<EpochPerf>, IndexerError>;

    // --- Epoch ------------------------------------------------------------

    async fn current_epoch_info(&self) -> Result<Option<EpochInfo>, IndexerError>;

    async fn epoch_utilization(&self, epoch: i64) -> Result<Option<f64>, IndexerError>;

    async fn committee(&self, epoch: i64) -> Result<Vec<CommitteeMember>, IndexerError>;

    // --- Registration stats ----------------------------------------------

    async fn registered_totals_series(
        &self,
        from_epoch: i64,
        to_epoch: i64,
    ) -> Result<Vec<RegisteredTotals>, IndexerError>;

    async fn registered_spo_series(
        &self,
        from_epoch: i64,
        to_epoch: i64,
    ) -> Result<Vec<RegisteredStat>, IndexerError>;

    async fn registered_presence(
        &self,
        from_epoch: i64,
        to_epoch: i64,
    ) -> Result<Vec<PresenceEvent>, IndexerError>;

    async fn registered_first_valid_epochs(
        &self,
        upto_epoch: Option<i64>,
    ) -> Result<Vec<FirstValidEpoch>, IndexerError>;

    // --- Stake distribution ----------------------------------------------

    async fn stake_distribution(
        &self,
        limit: Option<i64>,
        offset: Option<i64>,
        search: Option<String>,
        order_by_stake_desc: Option<bool>,
    ) -> Result<Vec<StakeShare>, IndexerError>;

    // --- Wallet session mutations ----------------------------------------

    /// Connect a wallet session. Returns the hex-encoded session ID.
    async fn connect(
        &self,
        viewing_key: &str,
        options: Option<ConnectOptions>,
    ) -> Result<String, IndexerError>;

    /// Disconnect a wallet session.
    async fn disconnect(&self, session_id: &str) -> Result<(), IndexerError>;
}