Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HashMapE.fromMap conversion error #78

Open
90K2 opened this issue Feb 9, 2023 · 2 comments
Open

HashMapE.fromMap conversion error #78

90K2 opened this issue Feb 9, 2023 · 2 comments

Comments

@90K2
Copy link
Contributor

90K2 commented Feb 9, 2023

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)
@andreypfau
Copy link
Collaborator

What is AbstractWallet?
Please provide complete example with imports

andreypfau added a commit that referenced this issue Feb 10, 2023
@90K2
Copy link
Contributor Author

90K2 commented Feb 10, 2023

updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants