yungwine / TonTools

High-level OOP Python library to interact with TON Blockchain
MIT License
119 stars 26 forks source link

Error when parsing jetton data for USD address #22

Open QuisEgoSum opened 2 months ago

QuisEgoSum commented 2 months ago
import asyncio

from TonTools.Contracts.Jetton import Jetton
from TonTools.Providers.LsClient import LsClient

usd_master = 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'

async def main():
    client = LsClient(ls_index=0, default_timeout=30)
    await client.init_tonlib()
    jetton = Jetton(usd_master, provider=client)
    await jetton.update()
    print(jetton)

if __name__ == '__main__':
    asyncio.run(main())
Traceback (most recent call last):
  File "<rootDir>/toontools_test/bugs/get_jetton_data.py", line 18, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "<rootDir>/toontools_test/bugs/get_jetton_data.py", line 13, in main
    await jetton.update()
  File "<rootDir>/.venv/lib/python3.11/site-packages/TonTools/Contracts/Jetton.py", line 34, in update
    jetton = await self.provider.get_jetton_data(self.address)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<rootDir>/.venv/lib/python3.11/site-packages/TonTools/Providers/LsClient.py", line 250, in get_jetton_data
    result = process_jetton_data(data[3].cell.bytes) if isinstance(process_jetton_data(data[3].cell.bytes), dict) else await get(process_jetton_data(data[3].cell.bytes))
                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<rootDir>/.venv/lib/python3.11/site-packages/TonTools/Providers/utils.py", line 29, in process_jetton_data
    symbol = Cell.one_from_boc(b64decode(data)).refs[0].refs[1].refs[0].refs[1].refs[0].bits.get_top_upped_array().decode().split('\x00')[-1]
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
xll970211 commented 1 month ago

I have same problem, Did you solve it?

QuisEgoSum commented 1 month ago

I have same problem, Did you solve it?

No. I need to send jetton usdt, but due to this error, it cannot be done. I rewrote the original sending method without using `get_jetton_data'. This data is used to determine decimals, I just specified this value manually.