Skip to content

Commit 5327993

Browse files
authored
Fix transaction text message (#117)
1 parent 1960112 commit 5327993

File tree

8 files changed

+132
-26
lines changed

8 files changed

+132
-26
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66
[![Telegram][telegram-svg]][telegram]
77
[![Based on TON][ton-svg]][ton]
88

9-
## Gradle Kotlin DSL
9+
## Modules
1010

11-
```kotlin
12-
dependencies {
13-
implementation("org.ton:ton-kotlin:0.2.18")
14-
}
15-
```
11+
### Core components
1612

17-
## Maven
13+
* `org.ton:ton-kotlin-tvm:0.3.0` - TVM Primitives (Cells, BOC, etc.)
14+
* `org.ton:ton-kotlin-crypto:0.3.0` - Crypto primitives for TON (ED25519, SHA, etc.)
15+
* `org.ton:ton-kotlin-adnl:0.3.0` - ADNL (Abstract Datagram Network Layer) TON Network implementation
1816

19-
```xml
17+
### API Interfaces
2018

21-
<dependency>
22-
<groupId>org.ton</groupId>
23-
<artifactId>ton-kotlin-jvm</artifactId>
24-
<version>0.2.18</version>
25-
</dependency>
26-
```
19+
* `org.ton:ton-kotlin-contract:0.3.0` - Smart-contracts API interface
20+
* `org.ton:ton-kotlin-liteclient:0.3.0` - Lite-client API implementation
21+
22+
### TL-B (TL-Binary)
23+
24+
* `org.ton:ton-kotlin-tlb:0.3.0` - TON TL-B (TL-Binary) serialization/deserialization
25+
* `org.ton:ton-kotlin-block-tlb:0.3.0` - Pre-generated TL-B schemas for TON Blockchain
26+
* `org.ton:ton-kotlin-hashmap-tlb:0.3.0` - Pre-generated TL-B schemas for TON Hashmap (also known as Dictionary)
2727

2828
## Documentation
2929

3030
https://github.com/andreypfau/ton-kotlin/wiki/TON-Kotlin-documentation
3131

3232
<!-- Badges -->
3333

34-
[maven-central]: https://central.sonatype.com/artifact/org.ton/ton-kotlin/0.2.18
34+
[maven-central]: https://central.sonatype.com/artifact/org.ton/ton-kotlin-tvm/0.3.0
3535

3636
[license]: LICENSE
3737

@@ -41,9 +41,9 @@ https://github.com/andreypfau/ton-kotlin/wiki/TON-Kotlin-documentation
4141

4242
[telegram]: https://t.me/tonkotlin
4343

44-
[maven-central-svg]: https://img.shields.io/maven-central/v/org.ton/ton-kotlin?color=blue
44+
[maven-central-svg]: https://img.shields.io/maven-central/v/org.ton/ton-kotlin-tvm?color=blue
4545

46-
[kotlin-svg]: https://img.shields.io/badge/Kotlin-1.8.0-blue.svg?logo=kotlin
46+
[kotlin-svg]: https://img.shields.io/badge/Kotlin-1.9.22-blue.svg?logo=kotlin
4747

4848
[telegram-svg]: https://img.shields.io/badge/Telegram-join%20chat-blue.svg?logo=telegram
4949

block-tlb/test/TextTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.ton.block
2+
3+
import org.ton.bitstring.toBitString
4+
import kotlin.test.Test
5+
6+
class TextTest {
7+
@Test
8+
fun foo() {
9+
10+
val string =
11+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
12+
13+
val chunks = string.encodeToByteArray().toList().chunked(127).reversed()
14+
var next: TextChunk? = null
15+
chunks.forEach { chunk ->
16+
val textChunk = TextChunk(
17+
chunk.size.toUByte(),
18+
chunk.toByteArray().toBitString(),
19+
next?.let { ChunkRef(it) } ?: ChunkRefEmpty
20+
)
21+
next = textChunk
22+
}
23+
val result = Text(chunks.size.toUByte(), next ?: TextChunkEmpty)
24+
}
25+
}

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.gradle.internal.impldep.org.bouncycastle.cms.RecipientId.password
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
34

@@ -11,7 +12,7 @@ plugins {
1112

1213
allprojects {
1314
group = "org.ton"
14-
version = "0.3.0"
15+
version = "0.3.1"
1516

1617
repositories {
1718
mavenCentral()

contract/src/wallet/MessageText.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private object MessageTextTlbCombinator : TlbCombinator<MessageText>(
4747
)
4848

4949
private object TextTlbConstructor : TlbConstructor<MessageText.Raw>(
50-
"raw#00 text:BitString = MessageText"
50+
"raw#00000000 text:BitString = MessageText"
5151
) {
5252
override fun loadTlb(cellSlice: CellSlice): MessageText.Raw {
5353
val text = cellSlice.loadTlb(CellStringTlbConstructor)
@@ -60,7 +60,7 @@ private object TextTlbConstructor : TlbConstructor<MessageText.Raw>(
6060
}
6161

6262
private object EncryptedTextTlbConstructor : TlbConstructor<MessageText.Encrypted>(
63-
"encrypted#01 text:BitString = MessageText"
63+
"encrypted#00000001 text:BitString = MessageText"
6464
) {
6565
override fun loadTlb(cellSlice: CellSlice): MessageText.Encrypted {
6666
val text = cellSlice.loadTlb(CellStringTlbConstructor)

contract/test/wallet/LiteClient.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import org.ton.api.pub.PublicKeyEd25519
88
import org.ton.lite.client.LiteClient
99
import org.ton.tl.asByteString
1010

11-
fun liteClient() = LiteClient(
11+
fun liteClientTestnet() = LiteClient(
1212
liteClientConfigGlobal = LiteClientConfigGlobal(
1313
liteServers = listOf(
1414
LiteServerDesc(
15-
id = PublicKeyEd25519("n4VDnSCUuSpjnCyUk9e3QOOd6o0ItSWYbTnW3Wnn8wk=".decodeBase64Bytes().asByteString()),
16-
ip = 84478511,
17-
port = 19949
15+
id = PublicKeyEd25519(
16+
"B07X5mudyWG3zZu+Ad69+A3jHFkp+0mTrnX5sw+s3ZU=".decodeBase64Bytes().asByteString()
17+
),
18+
ip = -1178753158,
19+
port = 15400
1820
)
1921
)
2022
),
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.ton.contract.wallet
2+
3+
import io.github.andreypfau.kotlinx.crypto.sha2.sha256
4+
import kotlinx.coroutines.delay
5+
import kotlinx.coroutines.runBlocking
6+
import org.ton.api.pk.PrivateKeyEd25519
7+
import org.ton.block.AccountInfo
8+
import org.ton.block.AddrStd
9+
import org.ton.block.Coins
10+
import kotlin.test.Ignore
11+
import kotlin.test.Test
12+
13+
class WalletV4Example {
14+
@Ignore
15+
@Test
16+
fun walletExample(): Unit = runBlocking {
17+
val liteClient = liteClientTestnet()
18+
19+
val pk = PrivateKeyEd25519(sha256("example-key".encodeToByteArray()))
20+
val contract = WalletV4R2Contract(
21+
liteClient,
22+
WalletV4R2Contract.address(pk)
23+
)
24+
val testnetNonBounceAddr = contract.address.toString(userFriendly = true, testOnly = true, bounceable = false)
25+
println("Wallet Address: $testnetNonBounceAddr")
26+
27+
var accountState = liteClient.getAccountState(contract.address)
28+
val account = accountState.account.value as? AccountInfo
29+
if (account == null) {
30+
println("Account $testnetNonBounceAddr not initialized")
31+
return@runBlocking
32+
}
33+
34+
val balance = account.storage.balance.coins
35+
println("Account balance: $balance toncoins")
36+
37+
contract.transfer(pk) {
38+
coins = Coins.Companion.ofNano(100) // 100 nanoton
39+
destination = AddrStd("kf8ZzXwnCm23GeqkK8ekU0Dxzu_fiXqIYO48FElkd7rVnoix")
40+
messageData = MessageData.text("Hello, World!")
41+
}
42+
43+
while (true) {
44+
println("Wait for transaction to be processed...")
45+
delay(6000)
46+
val newAccountState = liteClient.getAccountState(contract.address)
47+
if (newAccountState != accountState) {
48+
accountState = newAccountState
49+
println("Got new account state with last transaction: ${accountState.lastTransactionId}")
50+
break
51+
}
52+
}
53+
54+
val lastTransactionId = accountState.lastTransactionId
55+
if (lastTransactionId == null) {
56+
println("No transactions found")
57+
return@runBlocking
58+
}
59+
60+
val transaction = liteClient.getTransactions(accountState.address, lastTransactionId, 1)
61+
.first().transaction.value
62+
println("Transaction: $lastTransactionId")
63+
64+
transaction.r1.value.outMsgs.forEach { (hash, outMsgCell) ->
65+
val outMsgBody = outMsgCell.value.body.let {
66+
requireNotNull(it.x ?: it.y?.value) { "Body for message $hash is empty!" }
67+
}
68+
69+
val rawMessageText = try {
70+
MessageText.loadTlb(outMsgBody)
71+
} catch (e: Exception) {
72+
null
73+
}
74+
75+
println("Message text: $rawMessageText")
76+
}
77+
}
78+
}

settings.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pluginManagement {
1010
}
1111

1212
plugins {
13-
kotlin("multiplatform") version "1.9.20"
14-
kotlin("plugin.serialization") version "1.9.20"
13+
kotlin("multiplatform") version "1.9.22"
14+
kotlin("plugin.serialization") version "1.9.22"
1515
}
1616
}
1717

0 commit comments

Comments
 (0)