JsonRpcResponse

data class JsonRpcResponse(val id: JsonElement?, val result: JsonElement? = null, val error: JsonRpcErrorBody? = null)

A JSON-RPC 2.0 response. Exactly one of result and error is set; ok and failed are the honest way to ask which.

result may legitimately be JSON null — disconnect and prepareExecute both return the OpenRPC Null schema — so "result is null" cannot stand in for "this is an error".

Constructors

Link copied to clipboard
constructor(id: JsonElement?, result: JsonElement? = null, error: JsonRpcErrorBody? = null)

Types

Link copied to clipboard
object Companion

Constructors for the two shapes a response can take, plus the decoder.

Properties

Link copied to clipboard
Link copied to clipboard

True when the response carries an error.

Link copied to clipboard
val id: JsonElement?
Link copied to clipboard
val ok: Boolean

True when the response carries no error.

Link copied to clipboard
val result: JsonElement?

Functions

Link copied to clipboard
fun encode(): JsonObject

The frame as a JSON object. id is emitted as JSON null when absent, and when there is no error a null result is emitted as JSON null too — both are what the spec requires of a response, unlike a request.

Link copied to clipboard
fun resultOrThrow(): JsonElement

The result, or throws the error as a DappException.