Skip to content

Commit 7672c35

Browse files
author
abel
committed
(fix) Fixed scripts still referencing deprecated functions in AsyncClient
1 parent e72eedf commit 7672c35

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

examples/exchange_client/accounts_rpc/4_SubaccountBalancesList.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async def main() -> None:
99
client = AsyncClient(network)
1010
subaccount = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"
1111
denoms = ["inj", "peggy0x87aB3B4C8661e07D6372361211B96ed4Dc36B1B5"]
12-
subacc_balances_list = await client.get_subaccount_balances_list(subaccount_id=subaccount, denoms=denoms)
12+
subacc_balances_list = await client.fetch_subaccount_balances_list(subaccount_id=subaccount, denoms=denoms)
1313
print(subacc_balances_list)
1414

1515

examples/exchange_client/accounts_rpc/5_SubaccountHistory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22

33
from pyinjective.async_client import AsyncClient
4+
from pyinjective.client.model.pagination import PaginationOption
45
from pyinjective.core.network import Network
56

67

@@ -13,8 +14,12 @@ async def main() -> None:
1314
skip = 1
1415
limit = 15
1516
end_time = 1665118340224
17+
pagination = PaginationOption(skip=skip, limit=limit, end_time=end_time)
1618
subacc_history = await client.fetch_subaccount_history(
17-
subaccount_id=subaccount, denom=denom, transfer_types=transfer_types, skip=skip, limit=limit, end_time=end_time
19+
subaccount_id=subaccount,
20+
denom=denom,
21+
transfer_types=transfer_types,
22+
pagination=pagination,
1823
)
1924
print(subacc_history)
2025

examples/exchange_client/meta_rpc/4_StreamKeepAlive.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ async def keepalive_event_processor(event: Dict[str, Any]):
4444

4545

4646
async def get_markets(client):
47-
stream = await client.stream_spot_markets()
48-
async for market in stream:
49-
print(market)
47+
async def print_market_updates(event: Dict[str, Any]):
48+
print(event)
49+
50+
await client.listen_spot_markets_updates(
51+
callback=print_market_updates,
52+
on_end_callback=stream_closed_processor,
53+
on_status_callback=stream_error_processor,
54+
)
5055

5156

5257
if __name__ == "__main__":

pyinjective/async_client.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ async def send_tx_async_mode(self, tx_byte: bytes) -> abci_type.TxResponse:
458458
result = await self.stubTx.BroadcastTx(request=req, metadata=metadata)
459459
return result.tx_response
460460

461+
async def broadcast_tx_async_mode(self, tx_bytes: bytes) -> Dict[str, Any]:
462+
return await self.tx_api.broadcast(tx_bytes=tx_bytes, mode=tx_service.BroadcastMode.BROADCAST_MODE_ASYNC)
463+
461464
async def send_tx_block_mode(self, tx_byte: bytes) -> abci_type.TxResponse:
462465
"""
463466
This method is deprecated and will be removed soon. BLOCK broadcast mode should not be used
@@ -960,17 +963,13 @@ async def fetch_subaccount_history(
960963
subaccount_id: str,
961964
denom: Optional[str] = None,
962965
transfer_types: Optional[List[str]] = None,
963-
skip: Optional[int] = None,
964-
limit: Optional[int] = None,
965-
end_time: Optional[int] = None,
966+
pagination: Optional[PaginationOption] = None,
966967
) -> Dict[str, Any]:
967968
return await self.exchange_account_api.fetch_subaccount_history(
968969
subaccount_id=subaccount_id,
969970
denom=denom,
970971
transfer_types=transfer_types,
971-
skip=skip,
972-
limit=limit,
973-
end_time=end_time,
972+
pagination=pagination,
974973
)
975974

976975
async def get_subaccount_order_summary(self, subaccount_id: str, **kwargs):

pyinjective/client/indexer/grpc/indexer_grpc_account_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from grpc.aio import Channel
44

5+
from pyinjective.client.model.pagination import PaginationOption
56
from pyinjective.proto.exchange import (
67
injective_accounts_rpc_pb2 as exchange_accounts_pb,
78
injective_accounts_rpc_pb2_grpc as exchange_accounts_grpc,
@@ -66,17 +67,16 @@ async def fetch_subaccount_history(
6667
subaccount_id: str,
6768
denom: Optional[str] = None,
6869
transfer_types: Optional[List[str]] = None,
69-
skip: Optional[int] = None,
70-
limit: Optional[int] = None,
71-
end_time: Optional[int] = None,
70+
pagination: Optional[PaginationOption] = None,
7271
) -> Dict[str, Any]:
72+
pagination = pagination or PaginationOption()
7373
request = exchange_accounts_pb.SubaccountHistoryRequest(
7474
subaccount_id=subaccount_id,
7575
denom=denom,
7676
transfer_types=transfer_types,
77-
skip=skip,
78-
limit=limit,
79-
end_time=end_time,
77+
skip=pagination.skip,
78+
limit=pagination.limit,
79+
end_time=pagination.end_time,
8080
)
8181
response = await self._execute_call(call=self._stub.SubaccountHistory, request=request)
8282

pyinjective/core/broadcaster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ async def configure_gas_fee_for_transaction(
256256

257257
# simulate tx
258258
try:
259-
sim_res = await self._client.simulate_tx(sim_tx_raw_bytes)
259+
sim_res = await self._client.simulate(sim_tx_raw_bytes)
260260
except RpcError as ex:
261261
raise RuntimeError(f"Transaction simulation error: {ex}")
262262

263-
gas_limit = math.ceil(Decimal(str(sim_res.gas_info.gas_used)) * self._gas_limit_adjustment_multiplier)
263+
gas_limit = math.ceil(Decimal(str(sim_res["gasInfo"]["gasUsed"])) * self._gas_limit_adjustment_multiplier)
264264

265265
fee = [
266266
self._composer.Coin(

tests/client/indexer/grpc/test_indexer_grpc_account_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import time
2-
31
import grpc
42
import pytest
53

64
from pyinjective.client.indexer.grpc.indexer_grpc_account_api import IndexerGrpcAccountApi
5+
from pyinjective.client.model.pagination import PaginationOption
76
from pyinjective.core.network import Network
87
from pyinjective.proto.exchange import injective_accounts_rpc_pb2 as exchange_accounts_pb
98
from tests.client.indexer.configurable_account_query_servicer import ConfigurableAccountQueryServicer
@@ -256,9 +255,11 @@ async def test_subaccount_history(
256255
subaccount_id=transfer.dst_subaccount_id,
257256
denom=transfer.amount.denom,
258257
transfer_types=[transfer.transfer_type],
259-
skip=0,
260-
limit=5,
261-
end_time=int(time.time() * 1e3),
258+
pagination=PaginationOption(
259+
skip=0,
260+
limit=100,
261+
end_time=1699744939364,
262+
),
262263
)
263264
expected_subaccount_history = {
264265
"transfers": [

0 commit comments

Comments
 (0)