Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-p committed Apr 15, 2024
1 parent d60d050 commit 1e3797e
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 242 deletions.
6 changes: 3 additions & 3 deletions src/algokit_utils/beta/account_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def get_asset_information(self, sender: str, asset_id: int) -> dict[str, Any]:
# return self.signer_account(rekeyed_account(account, sender) if sender else account)

def from_kmd(
self,
name: str,
predicate: Callable[[dict[str, Any]], bool] | None = None,
self,
name: str,
predicate: Callable[[dict[str, Any]], bool] | None = None,
) -> AddressAndSigner:
"""
Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
Expand Down
44 changes: 28 additions & 16 deletions src/algokit_utils/beta/algorand_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AlgorandClientSendMethods:
"""
Methods used to send a transaction to the network and wait for confirmation
"""

payment: Callable[[PayParams], dict[str, Any]]
asset_create: Callable[[AssetCreateParams], dict[str, Any]]
asset_config: Callable[[AssetConfigParams], dict[str, Any]]
Expand All @@ -53,6 +54,7 @@ class AlgorandClientTransactionMethods:
"""
Methods used to form a transaction without signing or sending to the network
"""

payment: Callable[[PayParams], Transaction]
asset_create: Callable[[AssetCreateParams], Transaction]
asset_config: Callable[[AssetConfigParams], Transaction]
Expand Down Expand Up @@ -81,7 +83,7 @@ def __init__(self, config: AlgoClientConfigs | AlgoSdkClients):
def _unwrap_single_send_result(self, results: AtomicTransactionResponse) -> dict[str, Any]:
return {
"confirmation": wait_for_confirmation(self._client_manager.algod, results.tx_ids[0]),
"tx_id": results.tx_ids[0]
"tx_id": results.tx_ids[0],
}

def set_default_validity_window(self, validity_window: int) -> Self:
Expand Down Expand Up @@ -140,7 +142,7 @@ def set_suggested_params_timeout(self, timeout: int) -> Self:
def get_suggested_params(self) -> SuggestedParams:
"""Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)"""
if self._cached_suggested_params and (
self._cached_suggested_params_expiry is None or self._cached_suggested_params_expiry > time.time()
self._cached_suggested_params_expiry is None or self._cached_suggested_params_expiry > time.time()
):
return copy.deepcopy(self._cached_suggested_params)

Expand Down Expand Up @@ -174,22 +176,30 @@ def send(self) -> AlgorandClientSendMethods:
return AlgorandClientSendMethods(
payment=lambda params: self._unwrap_single_send_result(self.new_group().add_payment(params).execute()),
asset_create=lambda params: self._unwrap_single_send_result(
self.new_group().add_asset_create(params).execute()),
self.new_group().add_asset_create(params).execute()
),
asset_config=lambda params: self._unwrap_single_send_result(
self.new_group().add_asset_config(params).execute()),
self.new_group().add_asset_config(params).execute()
),
asset_freeze=lambda params: self._unwrap_single_send_result(
self.new_group().add_asset_freeze(params).execute()),
self.new_group().add_asset_freeze(params).execute()
),
asset_destroy=lambda params: self._unwrap_single_send_result(
self.new_group().add_asset_destroy(params).execute()),
self.new_group().add_asset_destroy(params).execute()
),
asset_transfer=lambda params: self._unwrap_single_send_result(
self.new_group().add_asset_transfer(params).execute()),
self.new_group().add_asset_transfer(params).execute()
),
app_call=lambda params: self._unwrap_single_send_result(self.new_group().add_app_call(params).execute()),
online_key_reg=lambda params: self._unwrap_single_send_result(
self.new_group().add_online_key_reg(params).execute()),
self.new_group().add_online_key_reg(params).execute()
),
method_call=lambda params: self._unwrap_single_send_result(
self.new_group().add_method_call(params).execute()),
self.new_group().add_method_call(params).execute()
),
asset_opt_in=lambda params: self._unwrap_single_send_result(
self.new_group().add_asset_opt_in(params).execute())
self.new_group().add_asset_opt_in(params).execute()
),
)

@property
Expand All @@ -206,7 +216,7 @@ def transactions(self) -> AlgorandClientTransactionMethods:
app_call=lambda params: self.new_group().add_app_call(params).build_group()[0].txn,
online_key_reg=lambda params: self.new_group().add_online_key_reg(params).build_group()[0].txn,
method_call=lambda params: [txn.txn for txn in self.new_group().add_method_call(params).build_group()],
asset_opt_in=lambda params: self.new_group().add_asset_opt_in(params).build_group()[0].txn
asset_opt_in=lambda params: self.new_group().add_asset_opt_in(params).build_group()[0].txn,
)

@staticmethod
Expand Down Expand Up @@ -275,11 +285,13 @@ def from_environment() -> Self:
:return: The `AlgorandClient`
"""
return AlgorandClient(AlgoSdkClients(
algod=get_algod_client(),
kmd=get_kmd_client(),
indexer=get_indexer_client(),
))
return AlgorandClient(
AlgoSdkClients(
algod=get_algod_client(),
kmd=get_kmd_client(),
indexer=get_indexer_client(),
)
)

@staticmethod
def from_config(config: AlgoClientConfigs) -> Self:
Expand Down
18 changes: 10 additions & 8 deletions src/algokit_utils/beta/client_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import algosdk
from algokit_utils.dispenser_api import TestNetDispenserApiClient
from algokit_utils.network_clients import AlgoClientConfigs, get_algod_client, get_indexer_client, get_kmd_client
Expand All @@ -17,8 +16,12 @@ class AlgoSdkClients:
kmd (Optional[KMDClient]): Optional KMD client, see https://developer.algorand.org/docs/rest-apis/kmd/
"""

def __init__(self, algod: algosdk.v2client.algod.AlgodClient, indexer: IndexerClient | None = None,
kmd: KMDClient | None = None):
def __init__(
self,
algod: algosdk.v2client.algod.AlgodClient,
indexer: IndexerClient | None = None,
kmd: KMDClient | None = None,
):
self.algod = algod
self.indexer = indexer
self.kmd = kmd
Expand All @@ -38,8 +41,9 @@ def __init__(self, clients_or_configs: AlgoClientConfigs | AlgoSdkClients):
elif isinstance(clients_or_configs, AlgoClientConfigs):
_clients = AlgoSdkClients(
algod=get_algod_client(clients_or_configs.algod_config),
indexer=get_indexer_client(
clients_or_configs.indexer_config) if clients_or_configs.indexer_config else None,
indexer=get_indexer_client(clients_or_configs.indexer_config)
if clients_or_configs.indexer_config
else None,
kmd=get_kmd_client(clients_or_configs.kmd_config) if clients_or_configs.kmd_config else None,
)
self._algod = _clients.algod
Expand All @@ -66,9 +70,7 @@ def kmd(self) -> KMDClient:
return self._kmd

def get_testnet_dispenser(
self,
auth_token: str | None = None,
request_timeout: int | None = None
self, auth_token: str | None = None, request_timeout: int | None = None
) -> TestNetDispenserApiClient:
if request_timeout:
return TestNetDispenserApiClient(auth_token=auth_token, request_timeout=request_timeout)
Expand Down
Loading

0 comments on commit 1e3797e

Please sign in to comment.