Skip to content

Instantly share code, notes, and snippets.

@90K2
Created July 23, 2022 15:30
Show Gist options
  • Save 90K2/46d125b3d7aeafb56f13cd2db74a91e7 to your computer and use it in GitHub Desktop.
Save 90K2/46d125b3d7aeafb56f13cd2db74a91e7 to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.reactor.mono
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 getBlockTransactions(
api: LiteClient,
blockId: TonNodeBlockIdExt,
count: Int,
after: LiteServerTransactionId3?
): LiteServerBlockTransactions {
val mode = if (after == null) 7 else 7 + 128
return api.listBlockTransactions(
blockId, mode, count, after
)
}
suspend fun loadTransactions() {
val liteClient = getLiteClient()
liteClient.getMasterchainInfo().last.let {lastMCBlockId ->
liteClient.getBlock(lastMCBlockId).toBlock().let { lastMcBlock ->
val d = lastMcBlock.extra.custom.value?.shard_hashes
?.nodes().orEmpty().map {
val workchain = BigInt(it.first.toByteArray()).toInt()
it.second.nodes().map { workchain to it }
}.toFlux()
.flatMap {
mono {
val (workchain, descr) = it.first()
getBlockTransactions(liteClient, getBlockId(workchain, descr), 100, null)
}
}.collectList().block()
}
}
}
suspend fun main() {
loadTransactions()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment