Skip to content

Commit

Permalink
fix for compressed jetton
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Sep 17, 2024
1 parent 9f40413 commit 86e4b78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,13 @@ private fun RawMessageEntity.rebuildJettonTransferWithCustomPayload(
)
}

fun RawMessageEntity.getJettonAddress(): AddrStd? {
val slice = payload.beginParse()
val opCode = slice.loadOpCode()
if (opCode != TONOpCode.JETTON_TRANSFER) {
return null
}
slice.loadUInt(64)
slice.loadTlb(Coins.tlbCodec())
slice.loadTlb(AddrStd.tlbCodec())
val excessesAddress = slice.loadTlb(AddrStd.tlbCodec())
val customPayload = slice.loadMaybeRef()
if (customPayload != null) {
return null
}
return excessesAddress
}

fun RawMessageEntity.getWalletTransfer(
excessesAddress: AddrStd? = null,
newStateInit: StateInit? = null,
newCustomPayload: Cell? = null,
): WalletTransfer {
val builder = WalletTransferBuilder()
builder.stateInit = newStateInit ?: stateInit
builder.stateInit = stateInit ?: newStateInit
builder.destination = address
builder.body = if (excessesAddress != null) {
rebuildBodyWithCustomExcessesAccount(excessesAddress)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tonapps.tonkeeper.extensions

import com.tonapps.blockchain.ton.extensions.equalsAddress
import com.tonapps.blockchain.ton.extensions.toAccountId
import com.tonapps.wallet.api.API
import com.tonapps.wallet.data.account.entities.WalletEntity
Expand All @@ -18,8 +19,12 @@ suspend fun SignRequestEntity.getTransfers(
): List<WalletTransfer> = withContext(Dispatchers.IO) {
val transfers = mutableListOf<WalletTransfer>()
for (message in messages) {
val jettonCustomPayload = message.getJettonAddress()?.toAccountId()?.let {
api.getJettonCustomPayload(wallet.accountId, wallet.testnet, it)
val jetton = compressedTokens.firstOrNull {
it.address.equalsAddress(message.addressValue) ||
it.balance.walletAddress.equalsAddress(message.addressValue)
}
val jettonCustomPayload = jetton?.let {
api.getJettonCustomPayload(wallet.accountId, wallet.testnet, it.address)
}

val transfer = message.getWalletTransfer(
Expand Down

0 comments on commit 86e4b78

Please sign in to comment.