Skip to content

Commit

Permalink
0.2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypfau committed Mar 20, 2023
1 parent 36d9cac commit 55fcb4a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import org.ton.bitstring.BitString
import org.ton.bitstring.toBitString
import org.ton.crypto.HexByteArraySerializer
import org.ton.tl.ByteString
import org.ton.tl.ByteString.Companion.toByteString
import org.ton.tl.TlConstructor
import org.ton.tl.TlReader
import org.ton.tl.TlWriter
Expand All @@ -19,9 +20,10 @@ public data class LiteServerAccountId(
@get:JvmName("workchain")
val workchain: Int,
@get:JvmName("id")
val id: BitString
val id: ByteString
) {
public constructor(workchain: Int, id: ByteArray) : this(workchain, id.toBitString())
public constructor(workchain: Int, id: ByteArray) : this(workchain, id.toByteString())
public constructor(workchain: Int, id: BitString) : this(workchain, id.toByteArray())

public companion object : TlConstructor<LiteServerAccountId>(
schema = "liteServer.accountId workchain:int id:int256 = liteServer.AccountId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,17 @@ package org.ton.lite.api.liteserver

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.ton.bitstring.BitString
import org.ton.bitstring.toBitString
import org.ton.tl.TlCodec
import org.ton.tl.TlConstructor
import org.ton.tl.TlReader
import org.ton.tl.TlWriter
import org.ton.tl.*
import org.ton.tl.ByteString.Companion.toByteString

@Serializable
@SerialName("liteServer.signature")
public data class LiteServerSignature(
@SerialName("node_id_short")
val nodeIdShort: BitString,
val signature: ByteArray
val nodeIdShort: ByteString,
val signature: ByteString
) {
public constructor(nodeIdShort: ByteArray, signature: ByteArray) : this(nodeIdShort.toBitString(), signature)

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is LiteServerSignature) return false

if (nodeIdShort != other.nodeIdShort) return false
if (!signature.contentEquals(other.signature)) return false

return true
}

override fun hashCode(): Int {
var result = nodeIdShort.hashCode()
result = 31 * result + signature.contentHashCode()
return result
}
public constructor(nodeIdShort: ByteArray, signature: ByteArray) : this(nodeIdShort.toByteString(), signature.toByteString())

public companion object : TlCodec<LiteServerSignature> by LiteServerSignatureTlConstructor
}
Expand All @@ -41,13 +21,13 @@ private object LiteServerSignatureTlConstructor : TlConstructor<LiteServerSignat
schema = "liteServer.signature node_id_short:int256 signature:bytes = liteServer.Signature"
) {
override fun decode(reader: TlReader): LiteServerSignature {
val nodeIdShort = reader.readRaw(32)
val signature = reader.readBytes()
val nodeIdShort = reader.readByteString(32)
val signature = reader.readByteString()
return LiteServerSignature(nodeIdShort, signature)
}

override fun encode(writer: TlWriter, value: LiteServerSignature) {
writer.writeRaw(value.nodeIdShort.toByteArray())
writer.writeRaw(value.nodeIdShort)
writer.writeBytes(value.signature)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ package org.ton.lite.api.liteserver.functions
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import org.ton.bitstring.BitString
import org.ton.bitstring.toBitString
import org.ton.crypto.HexByteArraySerializer
import org.ton.lite.api.liteserver.LiteServerAccountId
import org.ton.lite.api.liteserver.LiteServerTransactionList
import org.ton.tl.*
import org.ton.tl.ByteString.Companion.toByteString

@Serializable
@SerialName("liteServer.getTransactions")
public data class LiteServerGetTransactions(
val count: Int,
val account: LiteServerAccountId,
val lt: Long,
val hash: BitString
val hash: ByteString
) : TLFunction<LiteServerGetTransactions, LiteServerTransactionList> {
public constructor(count: Int, account: LiteServerAccountId, lt: Long, hash: ByteArray) : this(
count, account, lt, hash.toBitString()
count, account, lt, hash.toByteString()
)

init {
require(hash.size == 256)
require(hash.size == 32)
}

override fun tlCodec(): TlCodec<LiteServerGetTransactions> = LiteServerGetTransactionsTlConstructor
Expand All @@ -42,14 +41,14 @@ public object LiteServerGetTransactionsTlConstructor : TlConstructor<LiteServerG
val count = reader.readInt()
val account = reader.read(LiteServerAccountId)
val lt = reader.readLong()
val hash = reader.readRaw(32)
val hash = reader.readByteString(32)
return LiteServerGetTransactions(count, account, lt, hash)
}

override fun encode(writer: TlWriter, value: LiteServerGetTransactions) {
writer.writeInt(value.count)
writer.write(LiteServerAccountId, value.account)
writer.writeLong(value.lt)
writer.writeRaw(value.hash.toByteArray())
writer.writeRaw(value.hash)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public class LiteClient(
fromTransactionId: TransactionId,
count: Int,
): List<TransactionInfo> {
val rawTransactionList = liteApi(LiteServerGetTransactions(count, accountAddress.toLiteServer(), fromTransactionId.lt, fromTransactionId.hash))
val rawTransactionList = liteApi(LiteServerGetTransactions(count, accountAddress.toLiteServer(), fromTransactionId.lt, fromTransactionId.hash.toByteArray()))
val transactionsCells = BagOfCells(base64(rawTransactionList.transactions)).roots
check(rawTransactionList.ids.size == transactionsCells.size)
return List(transactionsCells.size) { index ->
Expand Down Expand Up @@ -496,5 +496,5 @@ public class LiteClient(
knownBlockIds.addLast(blockIdExt)
}

private fun AddrStd.toLiteServer() = LiteServerAccountId(workchainId, address)
private fun AddrStd.toLiteServer() = LiteServerAccountId(workchainId, address.toByteArray())
}

0 comments on commit 55fcb4a

Please sign in to comment.