Skip to content

Commit

Permalink
Updated gas fetch. References #55
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Jan 5, 2023
1 parent 8fa41d8 commit f661c45
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions pysui/sui/sui_builders/exec_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# limitations under the License.

# -*- coding: utf-8 -*-
# pylint: disable=too-many-lines

"""Sui Builders: Complex transaction."""

Expand Down
3 changes: 2 additions & 1 deletion pysui/sui/sui_builders/get_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pysui.sui.sui_types.collections import SuiMap, EventID
from pysui.sui.sui_types.address import SuiAddress
from pysui.sui.sui_txresults.single_tx import (
SuiCoinBalance,
SuiCoinMetadata,
CoinBalances,
SuiCoinObjects,
Expand Down Expand Up @@ -74,7 +75,7 @@ def __init__(self, *, owner: SuiAddress, coin_type: SuiString = None):
:param coin_type: fully qualified type names for the coin (e.g., 0x2::sui::SUI), defaults to None
:type coin_type: SuiString, optional
"""
super().__init__("sui_getBalance", handler_cls=CoinBalances, handler_func="ingest_data")
super().__init__("sui_getBalance", handler_cls=SuiCoinBalance, handler_func="from_dict")
self.owner = None
self.coin_type = SuiNullType()
self.set_owner(owner)
Expand Down
3 changes: 2 additions & 1 deletion pysui/sui/sui_clients/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# limitations under the License.

# -*- coding: utf-8 -*-
# pylint: disable=too-many-instance-attributes, too-many-public-methods, line-too-long

"""Sui Asynchronous RPC Client module."""

Expand Down Expand Up @@ -176,7 +177,7 @@ async def _get_coins_for_type(
"""
result = await self.execute(GetCoinTypeBalance(owner=address, coin_type=coin_type))
if result.is_ok():
limit = SuiInteger(result.result_data.items[0].coin_object_count)
limit = SuiInteger(result.result_data.coin_object_count)
result = await self.execute(GetCoins(owner=address, coin_type=coin_type, limit=limit))
return result

Expand Down
1 change: 1 addition & 0 deletions pysui/sui/sui_clients/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

"""Sui Client common classes module."""

import json
from abc import abstractmethod
from typing import Any, Union
from pkg_resources import packaging
Expand Down
15 changes: 8 additions & 7 deletions pysui/sui/sui_clients/sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# limitations under the License.

# -*- coding: utf-8 -*-
# pylint: disable=too-many-instance-attributes, too-many-public-methods, line-too-long

"""Sui Synchronous RPC Client module."""

Expand Down Expand Up @@ -68,15 +69,15 @@ def _execute(self, builder: SuiBaseBuilder) -> Union[SuiRpcResult, Exception]:
"""Execute the builder construct."""
# Validate builder and send request
try:
result = self._client.post(
self.config.rpc_url,
headers=builder.header,
json=self._validate_builder(builder),
)
return SuiRpcResult(
True,
None,
self._client.post(
self.config.rpc_url,
headers=builder.header,
json=self._validate_builder(builder),
timeout=15,
).json(),
result.json(),
)
except JSONDecodeError as jexc:
return SuiRpcResult(False, f"JSON Decoder Error {jexc.msg}", vars(jexc))
Expand Down Expand Up @@ -174,7 +175,7 @@ def _get_coins_for_type(
"""
result = self.execute(GetCoinTypeBalance(owner=address, coin_type=coin_type))
if result.is_ok():
limit = SuiInteger(result.result_data.items[0].coin_object_count)
limit = SuiInteger(result.result_data.coin_object_count)
result = self.execute(GetCoins(owner=address, coin_type=coin_type, limit=limit))
return result

Expand Down
1 change: 0 additions & 1 deletion samples/async_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ async def get_all_gas(client: SuiClient) -> dict[SuiAddress, list[SuiGas]]:
:rtype: dict[SuiAddress, list[SuiGas]]
"""
config: SuiConfig = client.config
# Build up gas descriptor fetch for each address
addys = [SuiAddress(x) for x in config.addresses]
addy_list = [client.get_gas(x) for x in addys]
gresult = await asyncio.gather(*addy_list, return_exceptions=True)
Expand Down

0 comments on commit f661c45

Please sign in to comment.