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

Wrong received int type in liteserver.get_account_state #11

Closed
vladimir-chernykh opened this issue Apr 24, 2024 · 1 comment
Closed

Comments

@vladimir-chernykh
Copy link
Contributor

vladimir-chernykh commented Apr 24, 2024

Hi!

I try to get the raw account state using liteserver method as follows:

from pytonapi import AsyncTonapi

client = AsyncTonapi(api_key="<API_KEY>")

account_address = "EQCqFPpSLtcstURtrXLRCv9wyjfrw7_44_nwvD8JiSmSjbUI"

state = await client.liteserver.get_account_state(account_address)

And I get the following error:

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[24], line 1
----> 1 state_tonapi = await client.liteserver.get_account_state(account_address)

File [/usr/local/lib/python3.10/site-packages/pytonapi/async_tonapi/methods/liteserver.py:121](http://localhost:8889/usr/local/lib/python3.10/site-packages/pytonapi/async_tonapi/methods/liteserver.py#line=120), in LiteserverMethod.get_account_state(self, account_address, target_block)
    118 params = {"target_block": target_block} if target_block else {}
    119 response = await self._get(method=method, params=params)
--> 121 return RawAccountState(**response)

File [/usr/local/lib/python3.10/site-packages/pydantic/v1/main.py:341](http://localhost:8889/usr/local/lib/python3.10/site-packages/pydantic/v1/main.py#line=340), in BaseModel.__init__(__pydantic_self__, **data)
    339 values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    340 if validation_error:
--> 341     raise validation_error
    342 try:
    343     object_setattr(__pydantic_self__, '__dict__', values)

ValidationError: 1 validation error for RawAccountState
shardblk -> shard
  value is not a valid integer (type=type_error.integer)

I'm pretty sure this error stems from int annotation here:

I tried to do the simple HTTP request without Pydantic response parsing like that:

response = await client._get(method=f"v2/liteserver/get_account_state/{account_address}", params={})

and get the following response

{'id': {'workchain': -1,
  'shard': '8000000000000000',
  'seqno': 37496117,
  'root_hash': '01166afa4bcb8b8bc65499ca755f434f0cfc4d13b7e90eb42ed436a831853e45',
  'file_hash': 'fd4620e8510e0d0b657f7edc6e3cc9f505fac97f63f8f79c8d9c9ee4082f5dd0'},
 'shardblk': {'workchain': 0,
  'shard': 'c000000000000000',
  'seqno': 43158333,
  'root_hash': 'bd96247321a94c9d17945286f85a13e296e2a4ce932764a6c95ddd0126e60bc3',
  'file_hash': 'f0728e43f52308da96a88b6c664a5b115ec01d51c499e8e057e83da901a9b322'},
 'shard_proof':
  .....

So response["shardblk"]["shard"] is indeed not an integer, at least not a decimal one.

I would be grateful if someone can help/share the experience with it.

@nessshon I'm also happy to make a PR, but I'm not quite sure how we should fix it.

@vladimir-chernykh vladimir-chernykh changed the title Wrong received int type in liteserver get_account_state Wrong received int type in liteserver.get_account_state Apr 24, 2024
@nessshon
Copy link
Collaborator

@vladimir-chernykh, Thank you for your contribution! Indeed, it was found that in the documentation, the shardblk.shard schema specifies the data type as str instead of the expected int. It will be corrected in the next update.

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