Skip to content

Commit 3c1c81f

Browse files
committed
chore: fix get_account with EthAccount type and cookie
1 parent c2ab981 commit 3c1c81f

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import asyncio
2+
import logging
3+
4+
from pyinjective.async_client import AsyncClient
5+
from pyinjective.constant import Network
6+
7+
async def main() -> None:
8+
network = Network.testnet()
9+
client = AsyncClient(network, insecure=False)
10+
address = "inj1knhahceyp57j5x7xh69p7utegnnnfgxavmahjr"
11+
acc = await client.get_account(address=address)
12+
print(acc)
13+
14+
if __name__ == '__main__':
15+
logging.basicConfig(level=logging.INFO)
16+
asyncio.get_event_loop().run_until_complete(main())

pyinjective/async_client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
injective_auction_rpc_pb2_grpc as auction_rpc_grpc,
5959
)
6060

61+
from proto.injective.types.v1beta1 import (
62+
account_pb2
63+
)
64+
6165
from .constant import Network
6266

6367
DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL = 20 # seconds
@@ -270,12 +274,13 @@ async def get_latest_block(self) -> tendermint_query.GetLatestBlockResponse:
270274
req = tendermint_query.GetLatestBlockRequest()
271275
return await self.stubCosmosTendermint.GetLatestBlock(req)
272276

273-
async def get_account(self, address: str) -> Optional[auth_type.BaseAccount]:
277+
async def get_account(self, address: str) -> Optional[account_pb2.EthAccount]:
274278
try:
275-
account_any = await self.stubAuth.Account(
276-
auth_query.QueryAccountRequest(address=address)
277-
).account
278-
account = auth_type.BaseAccount()
279+
metadata = await self.load_cookie(type="chain")
280+
account_any = (await self.stubAuth.Account(
281+
auth_query.QueryAccountRequest.__call__(address=address, metadata=metadata)
282+
)).account
283+
account = account_pb2.EthAccount()
279284
if account_any.Is(account.DESCRIPTOR):
280285
account_any.Unpack(account)
281286
return account

0 commit comments

Comments
 (0)