IndexerClientImpl

class IndexerClientImpl(httpClient: HttpClient, baseUrl: String = NetworkConfig.forNetwork(MidnightNetwork.PREVIEW).indexerBaseUrl, pinnedCertificates: List<String> = emptyList(), developmentMode: Boolean = false) : IndexerClient

Ktor-based implementation of IndexerClient for the Midnight indexer GraphQL API.

Connection:

  • HTTPS endpoint: {baseUrl}/graphql (with TLS certificate pinning)

  • WebSocket endpoint: {baseUrl}/graphql/ws

GraphQL Protocol:

  • Uses HTTPS POST for queries/mutations

  • Uses WebSocket for subscriptions (graphql-ws protocol)

Security:

  • TLS certificate pinning enabled for production

  • Development mode allows localhost HTTP (for local testing)

Parameters

httpClient

HTTP client for making requests (injectable for testing)

baseUrl

Indexer API base URL. Typical values come from NetworkConfig.forNetwork(...).indexerBaseUrl.

pinnedCertificates

List of SHA-256 certificate fingerprints for pinning (production only)

developmentMode

If true, allows HTTP to localhost (INSECURE - testing only)

Constructors

Link copied to clipboard
constructor(baseUrl: String = NetworkConfig.forNetwork(MidnightNetwork.PREVIEW).indexerBaseUrl, pinnedCertificates: List<String> = emptyList(), developmentMode: Boolean = false)

Convenience constructor for production use (creates default HTTP client).

constructor(httpClient: HttpClient, baseUrl: String = NetworkConfig.forNetwork(MidnightNetwork.PREVIEW).indexerBaseUrl, pinnedCertificates: List<String> = emptyList(), developmentMode: Boolean = false)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun close()

Close the client and release resources.

Link copied to clipboard
open suspend override fun getCurrentBlockWithParams(): BlockInfo

Get current block with ledger parameters.

Link copied to clipboard
open suspend override fun getEventsInRange(fromId: Long, toId: Long): List<RawLedgerEvent>

Get historical events in range.

Link copied to clipboard
open suspend override fun getNetworkState(): NetworkState

Get current network synchronization state.

Link copied to clipboard
open suspend override fun isHealthy(): Boolean

Check if indexer is healthy and reachable.

Link copied to clipboard
open suspend override fun queryContractState(address: String): String

Query the current on-chain state of a deployed contract.

Link copied to clipboard
open suspend override fun queryDustEvents(maxBlocks: Int): String

Query all dust events via WebSocket subscription.

Link copied to clipboard
open suspend override fun queryDustEventsDelta(fromId: Long, timeoutMs: Long): DustSyncResult

Query dust events starting from a specific event ID (delta sync).

Link copied to clipboard
open suspend override fun queryZswapEvents(): String

Query all zswap (shielded) events from the blockchain via subscription.

Link copied to clipboard
open suspend override fun resetConnection()

Reset the WebSocket connection (close all active subscriptions).

Link copied to clipboard
open override fun subscribeToBlocks(): Flow<BlockInfo>

Subscribe to new blocks.

Link copied to clipboard
open override fun subscribeToDustEvents(fromId: Long?): Flow<RawLedgerEvent>

Subscribe to dust ledger events via WebSocket.

Link copied to clipboard
open override fun subscribeToUnshieldedTransactions(address: String, transactionId: Int?): Flow<UnshieldedTransactionUpdate>

Subscribe to unshielded transactions for an address.

Link copied to clipboard
open override fun subscribeToZswapEvents(fromId: Long?): Flow<RawLedgerEvent>

Subscribe to zswap ledger events.