moonproof-indexer-client
Rust client for the Midnight indexer's GraphQL API. Drop-in equivalent of @midnight-ntwrk/midnight-js-indexer-public-data-provider.
The indexer is read-only — transaction submission goes to the Midnight node directly via moonproof-node-client (crates/node-client).
Usage
use ;
async
HttpIndexerClient::new(base) appends /api/v4/graphql. Use HttpIndexerClient::with_endpoint(url) to point at a non-standard path.
Design
Consumers program against the PublicDataProvider trait, not the HTTP client directly. This keeps tests mockable and gives us room to add alternate transports (e.g. an in-process provider that talks to an embedded indexer) without breaking callers.
┌──────────────────┐
│ consumer code │
└────────┬─────────┘
│ trait PublicDataProvider
▼
┌──────────────────┐ ┌────────────────────────┐
│ HttpIndexerClient│───────▶│ graphql_client codegen │
└──────────────────┘ POST │ (from .graphql files) │
└────────────────────────┘
Public domain types in types.rs are deliberately distinct from the graphql_client-generated types so the public API stays stable across schema revisions. The client layer does the conversion.
Crate layout
crates/indexer-client/
├── graphql/
│ ├── schema.graphql # vendored from midnight-indexer
│ └── queries/ # one .graphql file per operation
│ └── block.graphql
└── src/
├── lib.rs # public re-exports
├── error.rs # IndexerError
├── types.rs # Block, BlockOffset, BlockRef, ...
├── provider.rs # PublicDataProvider trait
├── client.rs # HttpIndexerClient (generic execute<Q>)
└── queries/
├── mod.rs
└── block.rs # #[derive(GraphQLQuery)] wrapper
Syncing the schema
The schema is vendored from midnightntwrk/midnight-indexer at indexer-api/graphql/schema-v4.graphql. To pull the latest:
# or directly:
The script validates that the fetched file looks like a real GraphQL schema before overwriting the vendored copy. After syncing, run cargo check -p moonproof-indexer-client to catch codegen breakage early.
Commit the updated schema.graphql alongside any query-side adjustments.
Adding a new query
-
Write the operation in
graphql/queries/<name>.graphql. -
Add a wrapper in
src/queries/<name>.rs:use GraphQLQuery; pub type HexEncoded = String; // add other scalar aliases as needed ; -
Register the module in
src/queries/mod.rs. -
Add a method on
PublicDataProviderand implement it onHttpIndexerClientusingself.execute::<MyQuery>(variables). Map codegen response types to stabletypes::*shapes so the trait surface stays decoupled from generated code.
Status
All 28 queries + 2 mutations from the v4 schema are ported.
Chain reads:
block(offset)— latest / by-hash / by-heighttransactions(offset)— regular / system, discriminated viaTransactionKindcontractAction(address, offset)— deploy / call / update, discriminated viaContractActionKindzswapMerkleTreeCollapsedUpdate(startIndex, endIndex)
Dust:
dustGenerationStatus(cardanoRewardAddresses)dustGenerations(cardanoRewardAddresses)dustCommitmentMerkleTreeUpdate(startIndex, endIndex)dustGenerationMerkleTreeUpdate(startIndex, endIndex)
Governance history:
dParameterHistorytermsAndConditionsHistory
SPO identity / metadata:
spoIdentities(limit, offset),spoIdentityByPoolId(poolIdHex),spoCountpoolMetadata(poolIdHex),poolMetadataList(limit, offset, withNameOnly)spoByPoolId(poolIdHex),spoList(limit, offset, search)spoCompositeByPoolId(poolIdHex)stakePoolOperators(limit)
Performance & epoch:
spoPerformanceLatest(limit, offset)spoPerformanceBySpoSk(spoSkHex, limit, offset)epochPerformance(epoch, limit, offset)currentEpochInfo,epochUtilization(epoch),committee(epoch)
Registration stats:
registeredTotalsSeries(fromEpoch, toEpoch)registeredSpoSeries(fromEpoch, toEpoch)registeredPresence(fromEpoch, toEpoch)registeredFirstValidEpochs(uptoEpoch)
Stake distribution:
stakeDistribution(limit, offset, search, orderByStakeDesc)
Wallet session mutations:
connect(viewingKey, options)→ session IDdisconnect(sessionId)
WebSocket subscriptions (src/subscription.rs) run over graphql-transport-ws (with the +deflate variant when offered) and cover all 9 streams: blocks, contractActions, dustGenerations, dustLedgerEvents, dustNullifierTransactions, shieldedNullifierTransactions, shieldedTransactions, unshieldedTransactions, and zswapLedgerEvents.