Skip to content

Instantly share code, notes, and snippets.

@90K2
Created July 24, 2022 08:24
Show Gist options
  • Save 90K2/a4c1603376d65e5b6abafc989a4ffe51 to your computer and use it in GitHub Desktop.
Save 90K2/a4c1603376d65e5b6abafc989a4ffe51 to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.reactor.mono
import org.ton.api.tonnode.TonNodeBlockId
import org.ton.api.tonnode.TonNodeBlockIdExt
import org.ton.bigint.BigInt
import org.ton.block.*
import org.ton.crypto.base64
import org.ton.lite.api.liteserver.LiteServerBlockTransactions
import org.ton.lite.api.liteserver.LiteServerTransactionId3
import org.ton.lite.client.LiteClient
import reactor.kotlin.core.publisher.toFlux
private suspend fun getLiteClient(): LiteClient {
return LiteClient(
host = "84478511",
port = 19949,
publicKey = base64("n4VDnSCUuSpjnCyUk9e3QOOd6o0ItSWYbTnW3Wnn8wk=")
).connect()
}
fun getBlockId(workchain: Int, descr: ShardDescr) = TonNodeBlockIdExt(
workchain = workchain,
shard = descr.next_validator_shard,
seqno = descr.seq_no.toInt(),
root_hash = descr.root_hash,
file_hash = descr.file_hash
)
suspend fun getBlock(seqNo: Int) {
val liteClient = getLiteClient()
val blockHeader = liteClient.lookupBlock(
TonNodeBlockId(
workchain = -1,
shard = 8000000000000000,
seqno = seqNo
)
)
println(blockHeader.id)
val block = liteClient.getBlock(blockHeader.id)
block.toBlock().extra.custom.value?.shard_hashes?.nodes()?.forEach {
val workchain = BigInt(it.first.toByteArray()).toInt()
val shards = it.second.nodes().toList()
shards.forEach {
val shardBlock = liteClient.getBlock(getBlockId(workchain, it)).toBlock()
shardBlock.extra.account_blocks.nodes().forEach {
it.first.transactions.nodes().forEach {
println("""
lt: ${it.first.lt}
account: ${AddrStd(workchain, it.first.account_addr)}
""".trimIndent())
}
}
}
}
}
suspend fun main() {
getBlock(22292326)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment