kevinheavey / solders

A high-performance Python toolkit for Solana, written in Rust
https://kevinheavey.github.io/solders/
Apache License 2.0
232 stars 26 forks source link

How to use LookupTables resolution? #85

Closed OlegJakushkin closed 8 months ago

OlegJakushkin commented 8 months ago

So I try:

        keys = tx.value.transaction.transaction.message.account_keys
        if tx.value.transaction.transaction.message.address_table_lookups is not None:
            for tl in tx.value.transaction.transaction.message.address_table_lookups:
                lt = address_lookup_table_account.AddressLookupTable(tl.account_key, [])
                addrs = lt.lookup(tx.value.slot, tl.readonly_indexes + tl.writable_indexes, SLOT_HASHES)
                keys.extend(lt.addresses)

Yet sometimes it does not go after lt line silently and sometimes it throws:

lt = address_lookup_table_account.AddressLookupTable(tl.account_key, [])
TypeError: argument 'meta': 'Pubkey' object cannot be converted to 'LookupTableMeta'
python-BaseException

How to expand address table correctly?

kevinheavey commented 8 months ago

Yet sometimes it does not go after lt line

Which line?

OlegJakushkin commented 8 months ago

Thank you, got it after reading rust examples. Python example would look like:

        keys = tx.value.transaction.transaction.message.account_keys
        if tx.value.transaction.transaction.message.address_table_lookups is not None:
            for tl in tx.value.transaction.transaction.message.address_table_lookups:
                lookup_ai = await aclient.get_account_info(tl.account_key)
                tbl = address_lookup_table_account.AddressLookupTable.deserialize(lookup_ai.value.data)
                keys.extend( [tbl.addresses[i] for i in tl.writable_indexes ])
                keys.extend( [tbl.addresses[i] for i in tl.readonly_indexes ])