diff --git a/CHANGELOG.md b/CHANGELOG.md index 996f1b34..de6e6dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added new TL with kotlinx-serialization support - All cryptography moved to `ton-kotlin-crypto` module under `org.ton.kotlin.crypto` package +- Updated Ktor to 3.3.0 ### Deprecated diff --git a/adnl/src/connection/AdnlClientImpl.kt b/adnl/src/connection/AdnlClientImpl.kt index 35b5039d..0aecce60 100644 --- a/adnl/src/connection/AdnlClientImpl.kt +++ b/adnl/src/connection/AdnlClientImpl.kt @@ -1,9 +1,9 @@ package org.ton.adnl.connection -import io.ktor.utils.io.core.* import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.withTimeout import kotlinx.io.bytestring.ByteString +import kotlinx.io.readByteArray import org.ton.api.adnl.message.AdnlMessageAnswer import org.ton.api.adnl.message.AdnlMessageQuery import org.ton.api.liteserver.LiteServerDesc @@ -28,7 +28,7 @@ public class AdnlClientImpl( ), context ) AdnlMessageAnswer.decodeBoxed( - response.body.readBytes() + response.body.readByteArray() ).answer.toByteArray() } } catch (e: Throwable) { diff --git a/adnl/src/connection/AdnlConnection.kt b/adnl/src/connection/AdnlConnection.kt index 21c1f7f4..c760adb4 100644 --- a/adnl/src/connection/AdnlConnection.kt +++ b/adnl/src/connection/AdnlConnection.kt @@ -2,12 +2,13 @@ package org.ton.adnl.connection import io.ktor.utils.io.* import io.ktor.utils.io.core.* -import io.ktor.utils.io.errors.* import kotlinx.atomicfu.atomic import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.datetime.Clock import kotlinx.datetime.Instant +import kotlinx.io.* +import kotlinx.io.Buffer import org.ton.adnl.network.TcpClient import org.ton.api.liteserver.LiteServerDesc import org.ton.kotlin.crypto.* @@ -66,10 +67,11 @@ public class AdnlConnection( } } - connection.output.writePacket { - writeFully(serverPublicKey.computeShortId().toByteArray()) + val handshakePacket = Buffer().apply { + write(serverPublicKey.computeShortId()) writeFully(serverPublicKey.encryptToByteArray(nonce)) } + connection.output.writePacket(handshakePacket) connection.output.flush() val cipher = ChannelCipher(nonce) @@ -127,7 +129,7 @@ public class AdnlConnection( } finally { output.flush() if (closeChannel) { - output.close() + output.flushAndClose() } } } @@ -150,20 +152,20 @@ public class AdnlConnection( private suspend fun readRaw( input: ByteReadChannel, cipher: AesCtr - ): ByteReadPacket { - val encryptedLength = input.readPacket(4).readBytes() + ): Source { + val encryptedLength = input.readPacket(4).readByteArray() val plainLength = ByteArray(4) cipher.processBytes(encryptedLength, plainLength) - val length = ByteReadPacket(plainLength).readIntLittleEndian() + val length = ByteReadPacket(plainLength).readIntLe() check(length in 32..(1 shl 24)) { "Invalid length" } - val encryptedData = input.readPacket(length).readBytes() + val encryptedData = input.readPacket(length).readByteArray() val plainData = ByteArray(length) cipher.processBytes(encryptedData, plainData) val data = ByteReadPacket(plainData) - val payload = data.readBytes((data.remaining - 32).toInt()) - val hash = data.readBytes(32) + val payload = data.readByteArray((data.remaining - 32).toInt()) + val hash = data.readByteArray(32) require(sha256(payload).contentEquals(hash)) { "sha256 mismatch" @@ -177,12 +179,12 @@ public class AdnlConnection( private suspend fun writeRaw( output: ByteWriteChannel, cipher: AesCtr, - packet: ByteReadPacket + packet: Source ) { val dataSize = (packet.remaining + 32 + 32).toInt() require(dataSize in 32..(1 shl 24)) { "Invalid packet size: $dataSize" } val nonce = SecureRandom.nextBytes(32) - val payload = packet.readBytes() + val payload = packet.readByteArray() val hash = Sha256().apply { update(nonce) @@ -190,14 +192,14 @@ public class AdnlConnection( }.digest() val data = buildPacket { - writeIntLittleEndian(dataSize) + writeIntLe(dataSize) writeFully(nonce) writeFully(payload) writeFully(hash) } val encryptedData = ByteArray(data.remaining.toInt()) - cipher.processBytes(data.readBytes(), encryptedData) + cipher.processBytes(data.readByteArray(), encryptedData) output.writeFully(encryptedData) } diff --git a/adnl/src/connection/AdnlRequestData.kt b/adnl/src/connection/AdnlRequestData.kt index d4cfb273..590ebdfc 100644 --- a/adnl/src/connection/AdnlRequestData.kt +++ b/adnl/src/connection/AdnlRequestData.kt @@ -1,10 +1,10 @@ package org.ton.adnl.connection -import io.ktor.utils.io.core.* import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Job import kotlinx.datetime.Clock import kotlinx.datetime.Instant +import kotlinx.io.Source import org.ton.api.http.functions.HttpRequest import kotlin.coroutines.CoroutineContext @@ -15,7 +15,7 @@ public class AdnlRequestData( public class AdnlResponseData( public val requestTime: Instant, - public val body: ByteReadPacket, + public val body: Source, public val callContext: CoroutineContext ) { public val responseTime: Instant = Clock.System.now() diff --git a/adnl/src/engine/AdnlNetworkEngine.kt b/adnl/src/engine/AdnlNetworkEngine.kt index fe5786b5..25150457 100644 --- a/adnl/src/engine/AdnlNetworkEngine.kt +++ b/adnl/src/engine/AdnlNetworkEngine.kt @@ -1,9 +1,9 @@ package org.ton.adnl.engine -import io.ktor.utils.io.core.* +import kotlinx.io.Source import org.ton.api.adnl.AdnlAddressUdp public interface AdnlNetworkEngine { - public suspend fun sendDatagram(adnlAddress: AdnlAddressUdp, payload: ByteReadPacket) - public suspend fun receiveDatagram(): Pair + public suspend fun sendDatagram(adnlAddress: AdnlAddressUdp, payload: Source) + public suspend fun receiveDatagram(): Pair } diff --git a/adnl/src@jvm/engine/CIOAdnlNetworkEngine.kt b/adnl/src@jvm/engine/CIOAdnlNetworkEngine.kt index 57fb8918..5cff0fcd 100644 --- a/adnl/src@jvm/engine/CIOAdnlNetworkEngine.kt +++ b/adnl/src@jvm/engine/CIOAdnlNetworkEngine.kt @@ -2,9 +2,10 @@ package org.ton.adnl.engine import io.ktor.network.selector.* import io.ktor.network.sockets.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.newFixedThreadPoolContext +import kotlinx.coroutines.runBlocking +import kotlinx.io.Source import org.ton.adnl.ipv4 import org.ton.adnl.utils.toAdnlUdpAddress import org.ton.adnl.utils.toSocketAddress @@ -16,14 +17,18 @@ public class CIOAdnlNetworkEngine( public constructor(port: Int) : this(AdnlAddressUdp(ipv4("0.0.0.0"), port)) public val socket: BoundDatagramSocket = - aSocket(ActorSelectorManager(DISPATCHER)).udp().bind(localAddress.toSocketAddress()) + aSocket(ActorSelectorManager(DISPATCHER)).udp().let { + runBlocking { + it.bind(localAddress.toSocketAddress()) + } + } - override suspend fun sendDatagram(adnlAddress: AdnlAddressUdp, payload: ByteReadPacket) { + override suspend fun sendDatagram(adnlAddress: AdnlAddressUdp, payload: Source) { val datagram = Datagram(payload, adnlAddress.toSocketAddress()) socket.send(datagram) } - override suspend fun receiveDatagram(): Pair { + override suspend fun receiveDatagram(): Pair { val datagram = socket.receive() val adnlAddress = datagram.address.toAdnlUdpAddress() val payload = datagram.packet diff --git a/adnl/src@jvm/network/TcpClientImpl.kt b/adnl/src@jvm/network/TcpClientImpl.kt index d549baee..6d7825cd 100644 --- a/adnl/src@jvm/network/TcpClientImpl.kt +++ b/adnl/src@jvm/network/TcpClientImpl.kt @@ -18,7 +18,7 @@ public actual class TcpClientImpl actual constructor( get() = connection.output actual override suspend fun connect(host: String, port: Int) { - socket = aSocket(selectorManager).tcpNoDelay().tcp().connect(host, port) + socket = aSocket(selectorManager).tcp().connect(host, port) connection = socket.connection() isClosed = false } diff --git a/bitstring/test/BitStringTest.kt b/bitstring/test/BitStringTest.kt index 09c53e38..c3cd3036 100644 --- a/bitstring/test/BitStringTest.kt +++ b/bitstring/test/BitStringTest.kt @@ -105,9 +105,9 @@ class BitStringTest { @Test fun `toString on a zero number`() { - assertEquals("0", BitString(List(4) { false }).toHex()) - assertEquals("00000000", BitString(List(32) { false }).toHex()) - assertEquals("0000000000000000", BitString(List(64) { false }).toHex()) + assertEquals("0", BitString(List(4) { false }).toHexString()) + assertEquals("00000000", BitString(List(32) { false }).toHexString()) + assertEquals("0000000000000000", BitString(List(64) { false }).toHexString()) } } @@ -117,11 +117,11 @@ fun assertBitString(binary: String, hex: String) { val hexBits = BitString(hex) assertEquals(binaryBits, hexBits) - assertEquals(hex, binaryBits.toHex()) - assertEquals(hex, hexBits.toHex()) + assertEquals(hex, binaryBits.toHexString()) + assertEquals(hex, hexBits.toHexString()) assertEquals(binary, binaryBits.toBooleanArray().joinToBits()) assertEquals(binary, hexBits.toBooleanArray().joinToBits()) - assertEquals(binaryBits.toHex(), hexBits.toHex()) + assertEquals(binaryBits.toHexString(), hexBits.toHexString()) assertContentEquals(binaryBits.toBooleanArray(), hexBits.toBooleanArray()) assertContentEquals(binaryBits.toByteArray(), hexBits.toByteArray()) assertEquals(BitString(binaryBits.size), BitString(hexBits.size)) diff --git a/block-tlb/src/AddrStd.kt b/block-tlb/src/AddrStd.kt index 58e4ead9..f3f8d0f7 100644 --- a/block-tlb/src/AddrStd.kt +++ b/block-tlb/src/AddrStd.kt @@ -113,7 +113,7 @@ public data class AddrStd( Base64.encode(data) } } else { - "${address.workchainId}:${address.address.toHex()}" + "${address.workchainId}:${address.address.toHexString()}" } } diff --git a/block-tlb/test/StateInitTest.kt b/block-tlb/test/StateInitTest.kt index c378b002..51176fab 100644 --- a/block-tlb/test/StateInitTest.kt +++ b/block-tlb/test/StateInitTest.kt @@ -41,6 +41,6 @@ class StateInitTest { assertEquals(BitString(publicKey), loadBits(256)) } - assertEquals(hash, stateInitCell.hash().toHex().lowercase()) + assertEquals(hash, stateInitCell.hash().toHexString().lowercase()) } } diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index dd1f4dc8..84d35852 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -8,6 +8,6 @@ repositories { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20") - implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.20") + implementation("com.vanniktech:gradle-maven-publish-plugin:0.34.0") } diff --git a/build-logic/src/main/kotlin/multiplatform.gradle.kts b/build-logic/src/main/kotlin/multiplatform.gradle.kts index 3aaf84f5..baac9814 100644 --- a/build-logic/src/main/kotlin/multiplatform.gradle.kts +++ b/build-logic/src/main/kotlin/multiplatform.gradle.kts @@ -8,14 +8,12 @@ kotlin { // explicitApiWarning() explicitApi() - //optin + compilerOptions { + freeCompilerArgs.add("-Xexpect-actual-classes") + } jvm { - compilations.all { - kotlinOptions { - jvmTarget = "1.8" - } - } + } sourceSets { diff --git a/build-logic/src/main/kotlin/publish.gradle.kts b/build-logic/src/main/kotlin/publish.gradle.kts index c683ef68..bd088149 100644 --- a/build-logic/src/main/kotlin/publish.gradle.kts +++ b/build-logic/src/main/kotlin/publish.gradle.kts @@ -1,4 +1,3 @@ -import com.vanniktech.maven.publish.SonatypeHost plugins { id("com.vanniktech.maven.publish") @@ -9,7 +8,7 @@ mavenPublishing { name = project.name description = "Kotlin/Multiplatform SDK for The Open Network" inceptionYear = "2025" - url = "https://github.com/ton-community/ton-kotlin" + url = "https://github.com/ton-blockchain/ton-kotlin" licenses { license { @@ -27,10 +26,9 @@ mavenPublishing { } } scm { - url = "https://github.com/ton-community/ton-kotlin" + url = "https://github.com/ton-blockchain/ton-kotlin" } } - publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) signAllPublications() } diff --git a/libs.versions.toml b/libs.versions.toml index 1fc4573c..b1dc0841 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,7 +1,7 @@ [versions] datetime = "0.5.0" # https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-datetime benchmark = "0.4.7" # https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-benchmark-runtime -ktor = "2.3.7" # https://search.maven.org/artifact/io.ktor/ktor +ktor = "3.3.0" # https://central.sonatype.com/artifact/io.ktor/ktor-server/versions bignum = "0.3.8" # https://search.maven.org/artifact/com.ionspin.kotlin/bignum cache4k = "0.12.0" # https://central.sonatype.com/namespace/io.github.reactivecircus.cache4k bcv = "0.13.2" diff --git a/tl-legacy/src/commonMain/kotlin/AbstractTlCombinator.kt b/tl-legacy/src/commonMain/kotlin/AbstractTlCombinator.kt index 6293b616..cfaeaf43 100644 --- a/tl-legacy/src/commonMain/kotlin/AbstractTlCombinator.kt +++ b/tl-legacy/src/commonMain/kotlin/AbstractTlCombinator.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl import kotlin.reflect.KClass diff --git a/tl-legacy/src/commonMain/kotlin/TlCodec.kt b/tl-legacy/src/commonMain/kotlin/TlCodec.kt index 39908189..415ed75c 100644 --- a/tl-legacy/src/commonMain/kotlin/TlCodec.kt +++ b/tl-legacy/src/commonMain/kotlin/TlCodec.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl @Deprecated(DEPRECATION_MESSAGE) diff --git a/tl-legacy/src/commonMain/kotlin/TlCombinator.kt b/tl-legacy/src/commonMain/kotlin/TlCombinator.kt index e3519a32..585604c1 100644 --- a/tl-legacy/src/commonMain/kotlin/TlCombinator.kt +++ b/tl-legacy/src/commonMain/kotlin/TlCombinator.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl import kotlin.reflect.KClass diff --git a/tl-legacy/src/commonMain/kotlin/TlConstructor.kt b/tl-legacy/src/commonMain/kotlin/TlConstructor.kt index d2cc4deb..f7aec509 100644 --- a/tl-legacy/src/commonMain/kotlin/TlConstructor.kt +++ b/tl-legacy/src/commonMain/kotlin/TlConstructor.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl import org.ton.kotlin.crypto.crc32 diff --git a/tl-legacy/src/commonMain/kotlin/TlDecoder.kt b/tl-legacy/src/commonMain/kotlin/TlDecoder.kt index d9227df8..fd10422f 100644 --- a/tl-legacy/src/commonMain/kotlin/TlDecoder.kt +++ b/tl-legacy/src/commonMain/kotlin/TlDecoder.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl import kotlinx.io.Buffer diff --git a/tl-legacy/src/commonMain/kotlin/TlEncoder.kt b/tl-legacy/src/commonMain/kotlin/TlEncoder.kt index b5d7a3ea..4dc2adf4 100644 --- a/tl-legacy/src/commonMain/kotlin/TlEncoder.kt +++ b/tl-legacy/src/commonMain/kotlin/TlEncoder.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl import kotlinx.io.Buffer diff --git a/tl-legacy/src/commonMain/kotlin/TlReader.kt b/tl-legacy/src/commonMain/kotlin/TlReader.kt index 0efde805..ee2c8ded 100644 --- a/tl-legacy/src/commonMain/kotlin/TlReader.kt +++ b/tl-legacy/src/commonMain/kotlin/TlReader.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION", "NOTHING_TO_INLINE") + package org.ton.tl import kotlinx.io.* diff --git a/tl-legacy/src/commonMain/kotlin/TlWriter.kt b/tl-legacy/src/commonMain/kotlin/TlWriter.kt index 45525a89..ba0b575d 100644 --- a/tl-legacy/src/commonMain/kotlin/TlWriter.kt +++ b/tl-legacy/src/commonMain/kotlin/TlWriter.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl import kotlinx.io.* diff --git a/tl-legacy/src/commonMain/kotlin/constructors/BoolTlConstructor.kt b/tl-legacy/src/commonMain/kotlin/constructors/BoolTlConstructor.kt index 4d98a535..640b1a36 100644 --- a/tl-legacy/src/commonMain/kotlin/constructors/BoolTlConstructor.kt +++ b/tl-legacy/src/commonMain/kotlin/constructors/BoolTlConstructor.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl.constructors import org.ton.tl.DEPRECATION_MESSAGE diff --git a/tl-legacy/src/commonMain/kotlin/constructors/BytesTlConstructor.kt b/tl-legacy/src/commonMain/kotlin/constructors/BytesTlConstructor.kt index 9454cf64..b42984e5 100644 --- a/tl-legacy/src/commonMain/kotlin/constructors/BytesTlConstructor.kt +++ b/tl-legacy/src/commonMain/kotlin/constructors/BytesTlConstructor.kt @@ -1,4 +1,4 @@ -@file:Suppress("OPT_IN_USAGE") +@file:Suppress("OPT_IN_USAGE", "DEPRECATION") package org.ton.tl.constructors diff --git a/tl-legacy/src/commonMain/kotlin/constructors/EnumTlCombinator.kt b/tl-legacy/src/commonMain/kotlin/constructors/EnumTlCombinator.kt index aa0789d1..2bd43cad 100644 --- a/tl-legacy/src/commonMain/kotlin/constructors/EnumTlCombinator.kt +++ b/tl-legacy/src/commonMain/kotlin/constructors/EnumTlCombinator.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package org.ton.tl.constructors import org.ton.tl.* diff --git a/tl/src/commonMain/kotlin/internal/TlDecoderImpl.kt b/tl/src/commonMain/kotlin/internal/TlDecoderImpl.kt index 6e6d2c7d..3cb74378 100644 --- a/tl/src/commonMain/kotlin/internal/TlDecoderImpl.kt +++ b/tl/src/commonMain/kotlin/internal/TlDecoderImpl.kt @@ -40,6 +40,7 @@ internal open class TlDecoderImpl( override fun decodeInline(descriptor: SerialDescriptor): Decoder = this + @Suppress("UNCHECKED_CAST") @OptIn(InternalSerializationApi::class) override fun decodeSerializableValue(deserializer: DeserializationStrategy): T { if (tl.boxed && deserializer !is AbstractPolymorphicSerializer<*>) { diff --git a/tvm/src/boc/BagOfCells.kt b/tvm/src/boc/BagOfCells.kt index d76f76df..94b18b47 100644 --- a/tvm/src/boc/BagOfCells.kt +++ b/tvm/src/boc/BagOfCells.kt @@ -1,6 +1,7 @@ package org.ton.boc import io.ktor.utils.io.core.* +import kotlinx.io.readByteArray import org.ton.cell.Cell import kotlin.io.encoding.Base64 import kotlin.jvm.JvmStatic @@ -14,7 +15,7 @@ public interface BagOfCells : Iterable { public fun toByteArray(): ByteArray = buildPacket { writeBagOfCells(this@BagOfCells) - }.readBytes() + }.readByteArray() override fun toString(): String @@ -52,12 +53,8 @@ public interface BagOfCells : Iterable { } @JvmStatic - public fun read(input: Input): BagOfCells = if (input.canRead()) { - input.readBagOfCell() - } else { - BagOfCells(Cell()) - } + public fun read(input: Input): BagOfCells = input.readBagOfCell() } } -public fun String.base64ToCell(): Cell = BagOfCells(Base64.decode(this)).first() \ No newline at end of file +public fun String.base64ToCell(): Cell = BagOfCells(Base64.decode(this)).first() diff --git a/tvm/src/boc/BagOfCellsImpl.kt b/tvm/src/boc/BagOfCellsImpl.kt index f787a2b4..a8572e54 100644 --- a/tvm/src/boc/BagOfCellsImpl.kt +++ b/tvm/src/boc/BagOfCellsImpl.kt @@ -1,6 +1,7 @@ package org.ton.boc import io.ktor.utils.io.core.* +import kotlinx.io.readByteArray import org.ton.cell.Cell internal data class BagOfCellsImpl( @@ -17,7 +18,7 @@ internal data class BagOfCellsImpl( override fun toByteArray(): ByteArray = buildPacket { writeBagOfCells(this@BagOfCellsImpl) - }.readBytes() + }.readByteArray() override fun toString(): String = buildString { roots.forEach { cell -> diff --git a/tvm/src/boc/BagOfCellsUtils.kt b/tvm/src/boc/BagOfCellsUtils.kt index 6a3d02e8..da1f1d63 100644 --- a/tvm/src/boc/BagOfCellsUtils.kt +++ b/tvm/src/boc/BagOfCellsUtils.kt @@ -2,6 +2,7 @@ package org.ton.boc import io.ktor.utils.io.core.* import kotlinx.coroutines.* +import kotlinx.io.* import org.ton.bitstring.BitString import org.ton.cell.Cell import org.ton.cell.CellDescriptor @@ -91,7 +92,7 @@ internal fun Input.readBagOfCell(): BagOfCells { val hashes = ArrayList(descriptor.hashCount) val depths = ArrayList(descriptor.hashCount) repeat(descriptor.hashCount) { - hashes.add(readBytes(Cell.HASH_BYTES)) + hashes.add(readByteArray(Cell.HASH_BYTES)) } repeat(descriptor.hashCount) { depths.add(readInt(2)) @@ -99,7 +100,7 @@ internal fun Input.readBagOfCell(): BagOfCells { cellHashes[cellIndex] = hashes.zip(depths) } - val cellData = readBytes(descriptor.dataLength) + val cellData = readByteArray(descriptor.dataLength) val cellSize = if (descriptor.isAligned) descriptor.dataLength * Byte.SIZE_BITS else findAugmentTag(cellData) cellBits[cellIndex] = BitString(cellData, cellSize) cellRefs[cellIndex] = IntArray(descriptor.referenceCount) { k -> @@ -126,7 +127,7 @@ internal fun Input.readBagOfCell(): BagOfCells { // TODO: Crc32c check (calculate size of resulting bytearray) if (hashCrc32) { - readIntLittleEndian() + readIntLe() } val cells = runBlocking { @@ -233,7 +234,7 @@ internal fun Output.writeBagOfCells( if (hasCrc32c) { val crc32c = crc32c(serializedBagOfCells) writeFully(serializedBagOfCells) - writeIntLittleEndian(crc32c) + writeIntLe(crc32c) } else { writeFully(serializedBagOfCells) } @@ -265,7 +266,7 @@ private fun serializeBagOfCells( val refIndex = cells.indexOf(reference) writeInt(refIndex, sizeBytes) } - }.readBytes() + }.readByteArray() serializedCell } @@ -313,7 +314,7 @@ private fun serializeBagOfCells( serializedCells.forEach { serializedCell -> writeFully(serializedCell) } -}.readBytes() +}.readByteArray() private fun Input.readInt(bytes: Int): Int { return when (bytes) { diff --git a/tvm/src/boc/CachedBagOfCells.kt b/tvm/src/boc/CachedBagOfCells.kt index 70d911fd..0f2ecbe3 100644 --- a/tvm/src/boc/CachedBagOfCells.kt +++ b/tvm/src/boc/CachedBagOfCells.kt @@ -1,6 +1,7 @@ package org.ton.boc import io.ktor.utils.io.core.* +import kotlinx.io.readByteArray import org.ton.cell.Cell import kotlin.math.min @@ -22,7 +23,7 @@ public class CachedBagOfCells( override fun toByteArray(): ByteArray = buildPacket { writeBagOfCells(this@CachedBagOfCells) - }.readBytes() + }.readByteArray() override fun toString(): String = buildString { roots.forEachIndexed { _, cell ->