Skip to content

Commit

Permalink
(fix) Fixed scripts still referencing deprecated functions in AsyncCl…
Browse files Browse the repository at this point in the history
…ient
  • Loading branch information
abel committed Dec 4, 2023
1 parent e72eedf commit 7672c35
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main() -> None:
client = AsyncClient(network)
subaccount = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"
denoms = ["inj", "peggy0x87aB3B4C8661e07D6372361211B96ed4Dc36B1B5"]
subacc_balances_list = await client.get_subaccount_balances_list(subaccount_id=subaccount, denoms=denoms)
subacc_balances_list = await client.fetch_subaccount_balances_list(subaccount_id=subaccount, denoms=denoms)
print(subacc_balances_list)


Expand Down
7 changes: 6 additions & 1 deletion examples/exchange_client/accounts_rpc/5_SubaccountHistory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import Network


Expand All @@ -13,8 +14,12 @@ async def main() -> None:
skip = 1
limit = 15
end_time = 1665118340224
pagination = PaginationOption(skip=skip, limit=limit, end_time=end_time)
subacc_history = await client.fetch_subaccount_history(
subaccount_id=subaccount, denom=denom, transfer_types=transfer_types, skip=skip, limit=limit, end_time=end_time
subaccount_id=subaccount,
denom=denom,
transfer_types=transfer_types,
pagination=pagination,
)
print(subacc_history)

Expand Down
11 changes: 8 additions & 3 deletions examples/exchange_client/meta_rpc/4_StreamKeepAlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ async def keepalive_event_processor(event: Dict[str, Any]):


async def get_markets(client):
stream = await client.stream_spot_markets()
async for market in stream:
print(market)
async def print_market_updates(event: Dict[str, Any]):
print(event)

await client.listen_spot_markets_updates(
callback=print_market_updates,
on_end_callback=stream_closed_processor,
on_status_callback=stream_error_processor,
)


if __name__ == "__main__":
Expand Down
11 changes: 5 additions & 6 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ async def send_tx_async_mode(self, tx_byte: bytes) -> abci_type.TxResponse:
result = await self.stubTx.BroadcastTx(request=req, metadata=metadata)
return result.tx_response

async def broadcast_tx_async_mode(self, tx_bytes: bytes) -> Dict[str, Any]:
return await self.tx_api.broadcast(tx_bytes=tx_bytes, mode=tx_service.BroadcastMode.BROADCAST_MODE_ASYNC)

async def send_tx_block_mode(self, tx_byte: bytes) -> abci_type.TxResponse:
"""
This method is deprecated and will be removed soon. BLOCK broadcast mode should not be used
Expand Down Expand Up @@ -960,17 +963,13 @@ async def fetch_subaccount_history(
subaccount_id: str,
denom: Optional[str] = None,
transfer_types: Optional[List[str]] = None,
skip: Optional[int] = None,
limit: Optional[int] = None,
end_time: Optional[int] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.exchange_account_api.fetch_subaccount_history(
subaccount_id=subaccount_id,
denom=denom,
transfer_types=transfer_types,
skip=skip,
limit=limit,
end_time=end_time,
pagination=pagination,
)

async def get_subaccount_order_summary(self, subaccount_id: str, **kwargs):
Expand Down
12 changes: 6 additions & 6 deletions pyinjective/client/indexer/grpc/indexer_grpc_account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.proto.exchange import (
injective_accounts_rpc_pb2 as exchange_accounts_pb,
injective_accounts_rpc_pb2_grpc as exchange_accounts_grpc,
Expand Down Expand Up @@ -66,17 +67,16 @@ async def fetch_subaccount_history(
subaccount_id: str,
denom: Optional[str] = None,
transfer_types: Optional[List[str]] = None,
skip: Optional[int] = None,
limit: Optional[int] = None,
end_time: Optional[int] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
pagination = pagination or PaginationOption()
request = exchange_accounts_pb.SubaccountHistoryRequest(
subaccount_id=subaccount_id,
denom=denom,
transfer_types=transfer_types,
skip=skip,
limit=limit,
end_time=end_time,
skip=pagination.skip,
limit=pagination.limit,
end_time=pagination.end_time,
)
response = await self._execute_call(call=self._stub.SubaccountHistory, request=request)

Expand Down
4 changes: 2 additions & 2 deletions pyinjective/core/broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ async def configure_gas_fee_for_transaction(

# simulate tx
try:
sim_res = await self._client.simulate_tx(sim_tx_raw_bytes)
sim_res = await self._client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
raise RuntimeError(f"Transaction simulation error: {ex}")

Check warning on line 261 in pyinjective/core/broadcaster.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/core/broadcaster.py#L258-L261

Added lines #L258 - L261 were not covered by tests

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

Check warning on line 263 in pyinjective/core/broadcaster.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/core/broadcaster.py#L263

Added line #L263 was not covered by tests

fee = [
self._composer.Coin(
Expand Down
11 changes: 6 additions & 5 deletions tests/client/indexer/grpc/test_indexer_grpc_account_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import time

import grpc
import pytest

from pyinjective.client.indexer.grpc.indexer_grpc_account_api import IndexerGrpcAccountApi
from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import Network
from pyinjective.proto.exchange import injective_accounts_rpc_pb2 as exchange_accounts_pb
from tests.client.indexer.configurable_account_query_servicer import ConfigurableAccountQueryServicer
Expand Down Expand Up @@ -256,9 +255,11 @@ async def test_subaccount_history(
subaccount_id=transfer.dst_subaccount_id,
denom=transfer.amount.denom,
transfer_types=[transfer.transfer_type],
skip=0,
limit=5,
end_time=int(time.time() * 1e3),
pagination=PaginationOption(
skip=0,
limit=100,
end_time=1699744939364,
),
)
expected_subaccount_history = {
"transfers": [
Expand Down

0 comments on commit 7672c35

Please sign in to comment.