dave08
07/25/2018, 11:31 AMclass KtorJsonRpcClient(val client: HttpClient, val endpoint: String): JsonRpcClient {
override suspend fun <R : Any> invoke(method: String, params: Any, type: Class<R>): R {
val response = client.get<JsonRpcResponse<R>>(endpoint) {
contentType(ContentType.Application.Json)
body = JsonRpcRequest(1, method, params)
}
if (response.result != null)
return response.result
else
throw response.error!!.run { JsonRpcException(code, message, data) }
}
}