ton-kotlin icon indicating copy to clipboard operation
ton-kotlin copied to clipboard

HashMapE.fromMap conversion error

Open 90K2 opened this issue 1 year ago • 2 comments

Sample:


import org.junit.jupiter.api.Test
import org.ton.bitstring.BitString
import org.ton.block.*
import org.ton.cell.Cell
import org.ton.cell.CellBuilder
import org.ton.contract.wallet.WalletTransfer
import org.ton.hashmap.HashMapE
import org.ton.tlb.CellRef
import org.ton.tlb.constructor.AnyTlbConstructor
import org.ton.tlb.constructor.tlbCodec
import org.ton.tlb.storeTlb
import org.ton.tlb.storeRef


class HashMapTest {

    fun createIntMsg(gift: WalletTransfer): MessageRelaxed<Cell> {
        val info = CommonMsgInfoRelaxed.IntMsgInfoRelaxed(
                ihrDisabled = true,
                bounce = gift.bounceable,
                bounced = false,
                src = AddrNone,
                dest = gift.destination,
                value = gift.coins,
                ihrFee = Coins(),
                fwdFee = Coins(),
                createdLt = 0u,
                createdAt = 0u
        )
        val init = Maybe.of(gift.stateInit?.let {
            Either.of<StateInit, CellRef<StateInit>>(null, CellRef(it))
        })
        val body = if (gift.body == null) {
            Either.of<Cell, CellRef<Cell>>(Cell.of(), null)
        } else {
            Either.of<Cell, CellRef<Cell>>(null, CellRef(gift.body!!))
        }

        return MessageRelaxed(
                info = info,
                init = init,
                body = body,
        )
    }

    @Test
    fun hmapTest() {
        val targets = listOf(
                AddrStd("kQC7ryRspjsMrdnuuA98uGyLMUVd_dDWjroYLBHoIz9ovl7e")
        )
        val transfers = targets.map {
            WalletTransfer {
                destination = it
                coins = Coins.of(1)
                bounceable = true
                body = null
                stateInit = null
            }
        }
        val transfersBody = transfers.mapIndexed { index, walletTransfer ->
            BitString(index) to CellBuilder.createCell {
                storeUInt(walletTransfer.sendMode, 8)
                storeRef(MessageRelaxed.tlbCodec(AnyTlbConstructor), CellRef(createIntMsg(walletTransfer)))
            }
        }.toMap()

        CellBuilder.createCell {
            storeTlb(HashMapE.tlbCodec(16, Cell.tlbCodec()), HashMapE.fromMap(transfersBody))
        }
    }
}

StackTrace

class org.ton.hashmap.HmnLeaf cannot be cast to class org.ton.hashmap.HmnFork (org.ton.hashmap.HmnLeaf and org.ton.hashmap.HmnFork are in unnamed module of loader 'app')
java.lang.ClassCastException: class org.ton.hashmap.HmnLeaf cannot be cast to class org.ton.hashmap.HmnFork (org.ton.hashmap.HmnLeaf and org.ton.hashmap.HmnFork are in unnamed module of loader 'app')
	at org.ton.hashmap.HashMapNodeForkTlbConstructor.storeTlb(HmnFork.kt:52)
	at org.ton.hashmap.HashMapEdgeTlbConstructor.storeTlb(HmEdge.kt:122)
	at org.ton.hashmap.HashMapEdgeTlbConstructor.storeTlb(HmEdge.kt:92)
	at org.ton.tlb.CellRefValue$toCell$2.invoke(CellRef.kt:76)
	at org.ton.tlb.CellRefValue$toCell$2.invoke(CellRef.kt:75)
	at org.ton.cell.CellBuilder$Companion.createCell(CellBuilder.kt:97)
	at org.ton.tlb.CellRefValue.toCell(CellRef.kt:75)
	at org.ton.tlb.CellRefTlbConstructor.storeTlb(CellRef.kt:87)
	at org.ton.tlb.CellRefTlbConstructor.storeTlb(CellRef.kt:83)
	at org.ton.hashmap.RootHashMapETlbConstructor.storeTlb(HmeRoot.kt:73)
	at org.ton.hashmap.RootHashMapETlbConstructor.storeTlb(HmeRoot.kt:44)
	at org.ton.tlb.TlbCombinator.storeTlb(TlbCombinator.kt:59)

90K2 avatar Feb 09 '23 20:02 90K2

What is AbstractWallet? Please provide complete example with imports

andreypfau avatar Feb 10 '23 15:02 andreypfau

updated

90K2 avatar Feb 10 '23 17:02 90K2