NodeRpcClientImpl

class NodeRpcClientImpl(httpClient: HttpClient, nodeUrl: String = "http://localhost:9944", developmentMode: Boolean = true) : NodeRpcClient

Ktor-based implementation of NodeRpcClient for Midnight node JSON-RPC API.

Connection:

  • HTTP endpoint: POST to {nodeUrl} (e.g., http://localhost:9944)

  • JSON-RPC 2.0 protocol

  • Timeout: 30 seconds (configurable)

Security:

  • Development mode: Allows HTTP to localhost (testing only)

  • Production mode: Requires HTTPS (not yet implemented)

Parameters

httpClient

HTTP client for making requests (injectable for testing)

nodeUrl

Node RPC endpoint URL (e.g., "http://localhost:9944")

developmentMode

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

Constructors

Link copied to clipboard
constructor(nodeUrl: String = "http://localhost:9944", developmentMode: Boolean = true)

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

constructor(httpClient: HttpClient, nodeUrl: String = "http://localhost:9944", developmentMode: Boolean = true)

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 getFinalizedHead(): String

Get the hash of the latest finalized block.

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

Check if node is healthy and reachable.

Link copied to clipboard
open suspend override fun submitAndWaitForFinalization(serializedTxHex: String, timeoutMs: Long, onStage: suspend (NodeRpcClient.SubmissionStage) -> Unit?): TransactionFinalizationResult

Submit transaction and wait for finalization using WebSocket subscription.

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

Submit a serialized transaction to the Midnight node (fire-and-forget).