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

[Bug] Map decoding #37

Open
m229abd opened this issue Oct 24, 2024 · 0 comments
Open

[Bug] Map decoding #37

m229abd opened this issue Oct 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@m229abd
Copy link

m229abd commented Oct 24, 2024

🐛 Bug Description

Hi guys. I have a question. So, I haven't worked on Aptos for a while, and today I realized that the package has changed a lot. I'm trying to conduct the following trasnaction:

https://explorer.aptoslabs.com/txn/1829613228/userTxnOverview?network=mainnet

The problem is, the code seems alright by Aptos SDK, I've tried every combination but the map (dict since I'm using python) gets encoded but doesn't get decoded on the network. Now, to solve this I can either figure out what is wrong with Aptos SDK, or get the exact bytes for the payload (I can deserialize it or even send it as is, because remains exactly the same). I would appropriate it if you help me with either of them.

I have tried examples, they work seamlessly, but there is no example of using map, and I think that's exactly the problem, since explorers are OK decoding everything else but a map.

How to reproduce

Code snippet to reproduce

from aptos_sdk.account import Account
from aptos_sdk.async_client import RestClient
from aptos_sdk.account_address import AccountAddress
from typing import Dict, Any
from aptos_sdk.transactions import RawTransaction, TransactionPayload, EntryFunction, ModuleId, TransactionArgument, SignedTransaction, TypeTag, StructTag
from aptos_sdk.bcs import Serializer
import time
class LaunchpadMinting:
    __aptos_client: RestClient
    __account: Account

    def __init__(self, private_key: str, aptos_rpc: str = 'https://api.mainnet.aptoslabs.com/v1') -> None:
        self.__account = Account.load_key(private_key)
        self.__aptos_client = RestClient(aptos_rpc)

    async def mint_token(self, collection_address: str, quantity: int):
        inner_map = lambda x,y: x.map(y, key_encoder=Serializer.str, value_encoder=Serializer.str)
        vec_map = lambda x,y: x.map(y, key_encoder=Serializer.str, value_encoder=Serializer.sequence_serializer(Serializer.str))
        inner = TransactionArgument({'inner': collection_address}, inner_map)
        vec = TransactionArgument({'vec': [str(quantity)]}, vec_map)
        tx = RawTransaction(
            self.__account.account_address,
            await self.__aptos_client.account_sequence_number(self.__account.account_address),
            TransactionPayload(
                EntryFunction(
                    ModuleId(
                        AccountAddress.from_str('0x96c192a4e3c529f0f6b3567f1281676012ce65ba4bb0a9b20b46dec4e371cccd'),
                        'unmanaged_launchpad'
                        ),
                    'mint',
                    [],
                    [
                        inner.encode(),
                        vec.encode()
                        ]
                    )
                ),
            max_gas_amount=1000,
            gas_unit_price=100,
            expiration_timestamps_secs=int(time.time()) + 10,
            chain_id=1
            )
        signed_tx = SignedTransaction(tx, self.__account.sign_transaction(tx))
        tx_hash = await self.__aptos_client.submit_bcs_transaction(signed_tx)
        await self.__aptos_client.wait_for_transaction(tx_hash)
        print("Mint TX HASH:", tx_hash)
        return tx_hash
async def main():
    launchpad = LaunchpadMinting(private_key='PK')
    await launchpad.mint_token(collection_address="0xd42cd397c41a62eaf03e83ad0324ff6822178a3e40aa596c4b9930561d4753e5", quantity=1)

import asyncio
asyncio.run(main())

Stack trace / error message
This account is what I've been conducting my tests on:
https://explorer.aptoslabs.com/account/0x71073d5ec015ceb546278fe46b5282a7c6ee59d5bf081be3e63cc6c16d141d85?network=mainnet

Expected Behavior

https://explorer.aptoslabs.com/txn/1829613228/userTxnOverview?network=mainnet

System information

System details:

  • Python 3.10.12
  • aptos-sdk==0.9.2
@m229abd m229abd added the bug Something isn't working label Oct 24, 2024
@m229abd m229abd changed the title [Bug] <Bug Title> [Bug] Map decoding Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant