Skip to content

Bug report: query_account does not support PeriodicVestingAccount. Solution provided. #385

@ayyo2765

Description

@ayyo2765

Prerequisites

Expected Behavior

Usage:

account = ledger.query_account(wallet.address())

Issue:
query_account expects a BaseAccount type. Other chains Like Bostrom appear to have a mix of types. My guess is that the account change from BaseAccount to PeriodicVestingAccount happens after a "investmint" event is transacted.

Fix:
Add PeriodicVestingAccount import to https://github.com/fetchai/cosmpy/blob/main/cosmpy/aerial/client/__init__.py

from cosmpy.protos.cosmos.vesting.v1beta1.vesting_pb2 import PeriodicVestingAccount

Change https://github.com/fetchai/cosmpy/blob/main/cosmpy/aerial/client/__init__.py#L313-L316 to

    if response.account.Is(BaseAccount.DESCRIPTOR):
        account = BaseAccount()
        response.account.Unpack(account)
    elif response.account.Is(PeriodicVestingAccount.DESCRIPTOR):
        account = PeriodicVestingAccount() 
        response.account.Unpack(account)
        account = account.base_vesting_account.base_account 
    else:
        raise RuntimeError("Unexpected account type returned from query")

Remarks:
#324 and #328 report the same error message but did not make note of the account type they were using. It is uncertain if this is the cause for their issues as well.

Current Behavior

Traceback (most recent call last):
  File "/workdir/csms.py", line 114, in <module>
    loop.run_until_complete(main())
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/workdir/csms.py", line 62, in main
    account = ledger.query_account(wallet.address())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cosmpy/aerial/client/__init__.py", line 315, in query_account
    raise RuntimeError("Unexpected account type returned from query")
RuntimeError: Unexpected account type returned from query

To Reproduce

No response

Context

Debian 12 Bookworm
Python 3.11.6
Cosmpy v0.9.1 & v0.9.2

Failure Logs

No response

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions