Skip to content

Commit 229e670

Browse files
feat: Upgrade to ktor 3
1 parent 114bfa1 commit 229e670

File tree

3 files changed

+101
-24
lines changed

3 files changed

+101
-24
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (!project.hasProperty("isGithubActions")) {
1919
}
2020

2121
group = "io.newm"
22-
version = "2.3.3-SNAPSHOT"
22+
version = "2.4.0-SNAPSHOT"
2323

2424
java.sourceCompatibility = JavaVersion.VERSION_21
2525
java.targetCompatibility = JavaVersion.VERSION_21

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
object Versions {
2-
const val COMMONS_LOGGING = "1.3.4"
2+
const val COMMONS_LOGGING = "1.3.5"
33
const val COMMONS_NUMBERS = "1.2"
44
const val COROUTINES = "1.10.1"
55
const val GOOGLE_TRUTH = "1.4.4"
66
const val JUNIT = "5.11.4"
77
const val KOTLIN = "2.1.10"
8-
const val KOTLINX_DATETIME = "0.6.1"
8+
const val KOTLINX_DATETIME = "0.6.2"
99
const val KOTLINX_SERIALIZATION = "1.8.0"
1010
const val KTLINT = "1.5.0"
1111
const val KTLINT_PLUGIN = "12.1.2"
12-
const val KTOR = "2.3.12"
12+
const val KTOR = "3.1.0"
1313
const val LOGBACK = "1.5.16"
1414
const val MAVEN_REPO_AUTH_PLUGIN = "3.0.4"
1515
const val MOCKK = "1.13.16"

src/main/kotlin/io/newm/kogmios/ClientImpl.kt

Lines changed: 97 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,108 @@
11
package io.newm.kogmios
22

3-
import io.ktor.client.*
4-
import io.ktor.client.engine.cio.*
5-
import io.ktor.client.plugins.websocket.*
6-
import io.ktor.client.request.*
3+
import io.ktor.client.HttpClient
4+
import io.ktor.client.engine.cio.CIO
5+
import io.ktor.client.plugins.websocket.DefaultClientWebSocketSession
6+
import io.ktor.client.plugins.websocket.WebSockets
7+
import io.ktor.client.plugins.websocket.receiveDeserialized
8+
import io.ktor.client.plugins.websocket.sendSerialized
9+
import io.ktor.client.plugins.websocket.webSocket
10+
import io.ktor.client.request.get
11+
import io.ktor.client.request.headers
12+
import io.ktor.client.request.url
713
import io.ktor.client.statement.bodyAsText
8-
import io.ktor.http.*
9-
import io.ktor.serialization.*
10-
import io.ktor.util.reflect.*
11-
import io.ktor.utils.io.charsets.*
12-
import io.ktor.websocket.*
14+
import io.ktor.http.HttpMethod
15+
import io.ktor.serialization.WebsocketContentConverter
16+
import io.ktor.util.reflect.TypeInfo
17+
import io.ktor.utils.io.charsets.Charset
18+
import io.ktor.websocket.CloseReason
19+
import io.ktor.websocket.Frame
20+
import io.ktor.websocket.FrameType
21+
import io.ktor.websocket.close
22+
import io.ktor.websocket.readText
1323
import io.newm.kogmios.exception.KogmiosException
14-
import io.newm.kogmios.protocols.messages.*
15-
import io.newm.kogmios.protocols.model.*
24+
import io.newm.kogmios.protocols.messages.Cbor
25+
import io.newm.kogmios.protocols.messages.HasTransaction
26+
import io.newm.kogmios.protocols.messages.JsonRpcErrorResponse
27+
import io.newm.kogmios.protocols.messages.JsonRpcRequest
28+
import io.newm.kogmios.protocols.messages.JsonRpcResponse
29+
import io.newm.kogmios.protocols.messages.JsonRpcSuccessResponse
30+
import io.newm.kogmios.protocols.messages.MsgAcquire
31+
import io.newm.kogmios.protocols.messages.MsgAcquireMempool
32+
import io.newm.kogmios.protocols.messages.MsgAcquireMempoolResponse
33+
import io.newm.kogmios.protocols.messages.MsgAcquireResponse
34+
import io.newm.kogmios.protocols.messages.MsgEvaluateTx
35+
import io.newm.kogmios.protocols.messages.MsgEvaluateTxResponse
36+
import io.newm.kogmios.protocols.messages.MsgFindIntersect
37+
import io.newm.kogmios.protocols.messages.MsgFindIntersectResponse
38+
import io.newm.kogmios.protocols.messages.MsgHasTransaction
39+
import io.newm.kogmios.protocols.messages.MsgHasTransactionResponse
40+
import io.newm.kogmios.protocols.messages.MsgNextBlock
41+
import io.newm.kogmios.protocols.messages.MsgNextBlockResponse
42+
import io.newm.kogmios.protocols.messages.MsgNextTransaction
43+
import io.newm.kogmios.protocols.messages.MsgNextTransactionResponse
44+
import io.newm.kogmios.protocols.messages.MsgQuery
45+
import io.newm.kogmios.protocols.messages.MsgQueryBlockHeightResponse
46+
import io.newm.kogmios.protocols.messages.MsgQueryEpochResponse
47+
import io.newm.kogmios.protocols.messages.MsgQueryEraStartResponse
48+
import io.newm.kogmios.protocols.messages.MsgQueryEraSummariesResponse
49+
import io.newm.kogmios.protocols.messages.MsgQueryGenesisConfigResponse
50+
import io.newm.kogmios.protocols.messages.MsgQueryLiveStakeDistributionResponse
51+
import io.newm.kogmios.protocols.messages.MsgQueryNetworkStartTimeResponse
52+
import io.newm.kogmios.protocols.messages.MsgQueryProjectedRewardsResponse
53+
import io.newm.kogmios.protocols.messages.MsgQueryProposedProtocolParametersResponse
54+
import io.newm.kogmios.protocols.messages.MsgQueryProtocolParametersResponse
55+
import io.newm.kogmios.protocols.messages.MsgQueryRewardAccountSummariesResponse
56+
import io.newm.kogmios.protocols.messages.MsgQueryStakePoolsResponse
57+
import io.newm.kogmios.protocols.messages.MsgQueryTipResponse
58+
import io.newm.kogmios.protocols.messages.MsgQueryUtxoResponse
59+
import io.newm.kogmios.protocols.messages.MsgRelease
60+
import io.newm.kogmios.protocols.messages.MsgReleaseMempool
61+
import io.newm.kogmios.protocols.messages.MsgReleaseMempoolResponse
62+
import io.newm.kogmios.protocols.messages.MsgReleaseResponse
63+
import io.newm.kogmios.protocols.messages.MsgSizeOfMempool
64+
import io.newm.kogmios.protocols.messages.MsgSizeOfMempoolResponse
65+
import io.newm.kogmios.protocols.messages.MsgSubmitTx
66+
import io.newm.kogmios.protocols.messages.MsgSubmitTxResponse
67+
import io.newm.kogmios.protocols.messages.SubmitOrEvalTx
68+
import io.newm.kogmios.protocols.model.FindIntersect
69+
import io.newm.kogmios.protocols.model.GenesisEra
70+
import io.newm.kogmios.protocols.model.ParamsGenesisConfig
71+
import io.newm.kogmios.protocols.model.ParamsPoolParameters
72+
import io.newm.kogmios.protocols.model.ParamsProjectedRewards
73+
import io.newm.kogmios.protocols.model.ParamsRewardAccountSummaries
74+
import io.newm.kogmios.protocols.model.ParamsUtxo
75+
import io.newm.kogmios.protocols.model.PointDetailOrOrigin
76+
import io.newm.kogmios.protocols.model.PointOrOrigin
77+
import io.newm.kogmios.protocols.model.StakePool
1678
import io.newm.kogmios.protocols.model.fault.InternalErrorFault
1779
import io.newm.kogmios.protocols.model.fault.StringFaultData
1880
import io.newm.kogmios.protocols.model.result.HealthResult
1981
import io.newm.kogmios.serializers.BigFractionSerializer
2082
import io.newm.kogmios.serializers.BigIntegerSerializer
2183
import java.io.IOException
2284
import java.math.BigInteger
23-
import java.util.*
2485
import java.util.concurrent.ConcurrentHashMap
25-
import kotlin.collections.set
2686
import kotlin.coroutines.CoroutineContext
27-
import kotlinx.coroutines.*
87+
import kotlinx.coroutines.CompletableDeferred
88+
import kotlinx.coroutines.CoroutineScope
89+
import kotlinx.coroutines.DelicateCoroutinesApi
90+
import kotlinx.coroutines.Dispatchers
91+
import kotlinx.coroutines.SupervisorJob
92+
import kotlinx.coroutines.async
93+
import kotlinx.coroutines.awaitAll
2894
import kotlinx.coroutines.channels.Channel
2995
import kotlinx.coroutines.channels.ClosedReceiveChannelException
3096
import kotlinx.coroutines.channels.ClosedSendChannelException
3197
import kotlinx.coroutines.channels.consumeEach
98+
import kotlinx.coroutines.coroutineScope
99+
import kotlinx.coroutines.delay
100+
import kotlinx.coroutines.job
101+
import kotlinx.coroutines.launch
102+
import kotlinx.coroutines.runBlocking
32103
import kotlinx.coroutines.sync.Mutex
33104
import kotlinx.coroutines.sync.withLock
34-
import kotlinx.serialization.encodeToString
105+
import kotlinx.coroutines.withTimeout
35106
import kotlinx.serialization.json.Json
36107
import kotlinx.serialization.modules.SerializersModule
37108
import org.apache.commons.numbers.fraction.BigFraction
@@ -81,7 +152,7 @@ internal class ClientImpl(
81152
override suspend fun serialize(
82153
charset: Charset,
83154
typeInfo: TypeInfo,
84-
value: Any
155+
value: Any?
85156
): Frame {
86157
log.trace("serialize() - charset: {}, typeInfo: {}, value: {}", charset, typeInfo, value)
87158
return Frame.Text(
@@ -92,7 +163,7 @@ internal class ClientImpl(
92163
log.debug("sending: {}", it)
93164
}
94165

95-
else -> throw IllegalArgumentException("Unable to serialize ${value::class.java.canonicalName}")
166+
else -> throw IllegalArgumentException("Unable to serialize ${value!!::class.java.canonicalName}")
96167
},
97168
)
98169
}
@@ -102,15 +173,21 @@ internal class ClientImpl(
102173
typeInfo: TypeInfo,
103174
content: Frame
104175
): Any {
105-
log.trace("deserialize() - charset: {}, typeInfo: {}, content: {}", charset, typeInfo, content)
176+
log.trace(
177+
"deserialize() - charset: {}, typeInfo: {}, content: {}",
178+
charset,
179+
typeInfo,
180+
content
181+
)
106182
val jsonString = (content as Frame.Text).readText()
107183
log.debug("received: {}", jsonString)
108184
return try {
109185
json.decodeFromString<JsonRpcResponse>(jsonString)
110186
} catch (e: Throwable) {
111187
// This should never happen unless WE have made an error in our parsers somewhere.
112-
val idRegex = """"id":"([^:{},]*: [a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})""""
113-
.toRegex()
188+
val idRegex =
189+
""""id":"([^:{},]*: [a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})""""
190+
.toRegex()
114191
val id = idRegex.find(jsonString)?.let { it.groupValues[1] } ?: "-1"
115192
JsonRpcErrorResponse(
116193
error =

0 commit comments

Comments
 (0)