Skip to content

Commit 04a0ef9

Browse files
committed
HashMap builders & kotlin-map conversions #41
1 parent 3bfbdf4 commit 04a0ef9

File tree

14 files changed

+66
-50
lines changed

14 files changed

+66
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
```kotlin
1313
dependencies {
14-
implementation("org.ton:ton-kotlin:0.2.7")
14+
implementation("org.ton:ton-kotlin:0.2.8")
1515
}
1616
```
1717

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ val isCI = System.getenv("CI") == "true"
1717

1818
allprojects {
1919
group = "org.ton"
20-
version = "0.2.7"
20+
version = "0.2.8"
2121

2222
apply(plugin = "kotlin-multiplatform")
2323
apply(plugin = "kotlinx-serialization")

ton-kotlin-block/src/commonMain/kotlin/org/ton/block/AccountInfo.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ public data class AccountInfo(
2020
) : Account {
2121
public companion object : TlbConstructorProvider<AccountInfo> by AccountInfoTlbConstructor
2222

23-
override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter = printer.type("account") {
24-
field("addr", addr)
25-
field("storage_stat", storageStat)
26-
field("storage", storage)
23+
override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter = printer {
24+
type("account") {
25+
field("addr", addr)
26+
field("storage_stat", storageStat)
27+
field("storage", storage)
28+
}
2729
}
2830

2931
override fun toString(): String = print().toString()

ton-kotlin-boc/jvm/test/test.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import io.ktor.util.*
2+
import org.ton.boc.BagOfCells
3+
import org.ton.crypto.base64
4+
import org.ton.crypto.encodeHex
5+
6+
fun main() {
7+
val bocBase64 =
8+
"te6ccuEBAQEASwCWAJIAAAAAQXVjdGlvbiBwcm9jZWVkcyBmb3IgdXNkdHh4eC50Lm1lIG1pbnVzIGNvbnZlcnNpb24gZmVlIGFuZCByb3lhbHRpZXMunEsqdg=="
9+
val boc = BagOfCells(base64(bocBase64))
10+
val cell = boc.first()
11+
println("cell: $cell")
12+
val newBoc = BagOfCells(cell)
13+
println("old boc: ${bocBase64.decodeBase64Bytes().encodeHex()}")
14+
println("new boc: ${newBoc.toByteArray().encodeHex()}")
15+
}

ton-kotlin-boc/src/commonMain/kotlin/org/ton/boc/BagOfCells.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public interface BagOfCells : Iterable<Cell> {
4949
}
5050

5151
@JvmStatic
52-
public fun read(input: Input): BagOfCells = input.readBagOfCell()
52+
public fun read(input: Input): BagOfCells = ByteReadPacket(input.readBytes()).readBagOfCell()
5353
}
5454
}

ton-kotlin-boc/src/commonMain/kotlin/org/ton/boc/BagOfCellsUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import org.ton.bitstring.BitString
55
import org.ton.cell.Cell
66
import org.ton.cell.LevelMask
77
import org.ton.crypto.crc32c
8+
import org.ton.crypto.encodeHex
89
import kotlin.experimental.and
910

1011
@OptIn(ExperimentalUnsignedTypes::class)
11-
internal fun Input.readBagOfCell(): BagOfCells {
12+
internal fun ByteReadPacket.readBagOfCell(): BagOfCells {
1213
val prefix = readInt()
1314
val hasIdx: Boolean
1415
val hashCrc32: Boolean

ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/GetPublicKeyContract.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface GetPublicKeyContract : Contract {
1111

1212
suspend fun getPublicKey(blockIdExt: TonNodeBlockIdExt): PublicKeyEd25519 {
1313
val address = address()
14-
val liteServerAccountId = LiteServerAccountId(address.workchainId, address.address.toByteArray())
14+
val liteServerAccountId = LiteServerAccountId(address.workchainId, address.address)
1515
val result = liteClient.runSmcMethod(
1616
address = liteServerAccountId,
1717
methodName = "get_public_key",

ton-kotlin-contract/src/commonMain/kotlin/org/ton/contract/wallet/SeqnoContract.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface SeqnoContract : Contract {
1010

1111
public suspend fun seqno(blockIdExt: TonNodeBlockIdExt): Int {
1212
val address = address()
13-
val liteServerAccountId = LiteServerAccountId(address.workchainId, address.address.toByteArray())
13+
val liteServerAccountId = LiteServerAccountId(address.workchainId, address.address)
1414
val result = liteClient.runSmcMethod(
1515
address = liteServerAccountId,
1616
methodName = "get_seqno",

ton-kotlin-liteapi/src/commonMain/kotlin/org/ton/lite/api/LiteApi.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ import org.ton.lite.api.liteserver.*
44
import org.ton.lite.api.liteserver.functions.*
55

66
public interface LiteApi {
7-
public suspend operator fun invoke(function: LiteServerGetMasterchainInfo): LiteServerMasterchainInfo
8-
public suspend operator fun invoke(function: LiteServerGetMasterchainInfoExt): LiteServerMasterchainInfoExt
7+
public suspend operator fun invoke(
8+
function: LiteServerGetMasterchainInfo,
9+
waitMasterchainSeqno: Int = -1
10+
): LiteServerMasterchainInfo
11+
12+
public suspend operator fun invoke(
13+
function: LiteServerGetMasterchainInfoExt,
14+
waitMasterchainSeqno: Int = -1
15+
): LiteServerMasterchainInfoExt
16+
917
public suspend operator fun invoke(function: LiteServerGetTime): LiteServerCurrentTime
1018
public suspend operator fun invoke(function: LiteServerGetVersion): LiteServerVersion
1119
public suspend operator fun invoke(function: LiteServerGetBlock): LiteServerBlockData
@@ -18,7 +26,11 @@ public interface LiteApi {
1826
public suspend operator fun invoke(function: LiteServerGetOneTransaction): LiteServerTransactionInfo
1927
public suspend operator fun invoke(function: LiteServerGetAllShardsInfo): LiteServerAllShardsInfo
2028
public suspend operator fun invoke(function: LiteServerGetTransactions): LiteServerTransactionList
21-
public suspend operator fun invoke(function: LiteServerLookupBlock): LiteServerBlockHeader
29+
public suspend operator fun invoke(
30+
function: LiteServerLookupBlock,
31+
waitMasterchainSeqno: Int = -1
32+
): LiteServerBlockHeader
33+
2234
public suspend operator fun invoke(function: LiteServerListBlockTransactions): LiteServerBlockTransactions
2335
public suspend operator fun invoke(function: LiteServerGetBlockProof): LiteServerPartialBlockProof
2436
public suspend operator fun invoke(function: LiteServerGetConfigAll): LiteServerConfigInfo

ton-kotlin-liteapi/src/commonMain/kotlin/org/ton/lite/api/LiteApiClient.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public interface LiteApiClient : LiteApi {
1111
queryCodec: TlCodec<Q>,
1212
answerCodec: TlCodec<A>,
1313
query: Q,
14-
seqno: Int = -1
14+
waitMasterchainSeqno: Int = -1
1515
): A {
1616
val rawQuery = buildPacket {
1717
// println("send query to lite server: $query")
18-
if (seqno >= 0) {
19-
val wait = LiteServerWaitMasterchainSeqno(seqno, 5000)
18+
if (waitMasterchainSeqno > 0) {
19+
val wait = LiteServerWaitMasterchainSeqno(waitMasterchainSeqno, 30000)
2020
// println("with prefix: $wait")
2121
LiteServerWaitMasterchainSeqno.encodeBoxed(this, wait)
2222
}
@@ -40,11 +40,17 @@ public interface LiteApiClient : LiteApi {
4040

4141
public suspend fun sendRawQuery(query: ByteReadPacket): ByteReadPacket
4242

43-
override suspend fun invoke(function: LiteServerGetMasterchainInfo): LiteServerMasterchainInfo =
44-
sendQuery(LiteServerGetMasterchainInfo, LiteServerMasterchainInfo, function)
43+
override suspend fun invoke(
44+
function: LiteServerGetMasterchainInfo,
45+
waitMasterchainSeqno: Int
46+
): LiteServerMasterchainInfo =
47+
sendQuery(LiteServerGetMasterchainInfo, LiteServerMasterchainInfo, function, waitMasterchainSeqno)
4548

46-
override suspend fun invoke(function: LiteServerGetMasterchainInfoExt): LiteServerMasterchainInfoExt =
47-
sendQuery(LiteServerGetMasterchainInfoExt, LiteServerMasterchainInfoExt, function)
49+
override suspend fun invoke(
50+
function: LiteServerGetMasterchainInfoExt,
51+
waitMasterchainSeqno: Int
52+
): LiteServerMasterchainInfoExt =
53+
sendQuery(LiteServerGetMasterchainInfoExt, LiteServerMasterchainInfoExt, function, waitMasterchainSeqno)
4854

4955
override suspend fun invoke(function: LiteServerGetTime): LiteServerCurrentTime =
5056
sendQuery(LiteServerGetTime, LiteServerCurrentTime, function)
@@ -82,8 +88,8 @@ public interface LiteApiClient : LiteApi {
8288
override suspend fun invoke(function: LiteServerGetTransactions): LiteServerTransactionList =
8389
sendQuery(LiteServerGetTransactions, LiteServerTransactionList, function)
8490

85-
override suspend fun invoke(function: LiteServerLookupBlock): LiteServerBlockHeader =
86-
sendQuery(LiteServerLookupBlock, LiteServerBlockHeader, function)
91+
override suspend fun invoke(function: LiteServerLookupBlock, waitMasterchainSeqno: Int): LiteServerBlockHeader =
92+
sendQuery(LiteServerLookupBlock, LiteServerBlockHeader, function, waitMasterchainSeqno)
8793

8894
override suspend fun invoke(function: LiteServerListBlockTransactions): LiteServerBlockTransactions =
8995
sendQuery(LiteServerListBlockTransactions, LiteServerBlockTransactions, function)

0 commit comments

Comments
 (0)