-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1960112
commit 5327993
Showing
8 changed files
with
132 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.ton.block | ||
|
||
import org.ton.bitstring.toBitString | ||
import kotlin.test.Test | ||
|
||
class TextTest { | ||
@Test | ||
fun foo() { | ||
|
||
val string = | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" | ||
|
||
val chunks = string.encodeToByteArray().toList().chunked(127).reversed() | ||
var next: TextChunk? = null | ||
chunks.forEach { chunk -> | ||
val textChunk = TextChunk( | ||
chunk.size.toUByte(), | ||
chunk.toByteArray().toBitString(), | ||
next?.let { ChunkRef(it) } ?: ChunkRefEmpty | ||
) | ||
next = textChunk | ||
} | ||
val result = Text(chunks.size.toUByte(), next ?: TextChunkEmpty) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.ton.contract.wallet | ||
|
||
import io.github.andreypfau.kotlinx.crypto.sha2.sha256 | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.runBlocking | ||
import org.ton.api.pk.PrivateKeyEd25519 | ||
import org.ton.block.AccountInfo | ||
import org.ton.block.AddrStd | ||
import org.ton.block.Coins | ||
import kotlin.test.Ignore | ||
import kotlin.test.Test | ||
|
||
class WalletV4Example { | ||
@Ignore | ||
@Test | ||
fun walletExample(): Unit = runBlocking { | ||
val liteClient = liteClientTestnet() | ||
|
||
val pk = PrivateKeyEd25519(sha256("example-key".encodeToByteArray())) | ||
val contract = WalletV4R2Contract( | ||
liteClient, | ||
WalletV4R2Contract.address(pk) | ||
) | ||
val testnetNonBounceAddr = contract.address.toString(userFriendly = true, testOnly = true, bounceable = false) | ||
println("Wallet Address: $testnetNonBounceAddr") | ||
|
||
var accountState = liteClient.getAccountState(contract.address) | ||
val account = accountState.account.value as? AccountInfo | ||
if (account == null) { | ||
println("Account $testnetNonBounceAddr not initialized") | ||
return@runBlocking | ||
} | ||
|
||
val balance = account.storage.balance.coins | ||
println("Account balance: $balance toncoins") | ||
|
||
contract.transfer(pk) { | ||
coins = Coins.Companion.ofNano(100) // 100 nanoton | ||
destination = AddrStd("kf8ZzXwnCm23GeqkK8ekU0Dxzu_fiXqIYO48FElkd7rVnoix") | ||
messageData = MessageData.text("Hello, World!") | ||
} | ||
|
||
while (true) { | ||
println("Wait for transaction to be processed...") | ||
delay(6000) | ||
val newAccountState = liteClient.getAccountState(contract.address) | ||
if (newAccountState != accountState) { | ||
accountState = newAccountState | ||
println("Got new account state with last transaction: ${accountState.lastTransactionId}") | ||
break | ||
} | ||
} | ||
|
||
val lastTransactionId = accountState.lastTransactionId | ||
if (lastTransactionId == null) { | ||
println("No transactions found") | ||
return@runBlocking | ||
} | ||
|
||
val transaction = liteClient.getTransactions(accountState.address, lastTransactionId, 1) | ||
.first().transaction.value | ||
println("Transaction: $lastTransactionId") | ||
|
||
transaction.r1.value.outMsgs.forEach { (hash, outMsgCell) -> | ||
val outMsgBody = outMsgCell.value.body.let { | ||
requireNotNull(it.x ?: it.y?.value) { "Body for message $hash is empty!" } | ||
} | ||
|
||
val rawMessageText = try { | ||
MessageText.loadTlb(outMsgBody) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
|
||
println("Message text: $rawMessageText") | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters