Skip to content

Commit c13dc44

Browse files
committed
Formatting
1 parent a5ca68a commit c13dc44

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import asyncio
8-
from concurrent.futures import ProcessPoolExecutor
98
import inspect
109
import logging
1110
import random
@@ -57,10 +56,14 @@
5756
)
5857
from async_substrate_interface.utils.storage import StorageKey
5958
from async_substrate_interface.type_registry import _TYPE_REGISTRY
60-
from async_substrate_interface.utils.decoding_attempt import _decode_query_map, _decode_scale_with_runtime
59+
from async_substrate_interface.utils.decoding_attempt import (
60+
decode_query_map,
61+
_decode_scale_with_runtime,
62+
)
6163

6264
if TYPE_CHECKING:
6365
from websockets.asyncio.client import ClientConnection
66+
from concurrent.futures import ProcessPoolExecutor
6467

6568
ResultHandler = Callable[[dict, Any], Awaitable[tuple[dict, bool]]]
6669

@@ -415,7 +418,7 @@ def __init__(
415418
last_key: Optional[str] = None,
416419
max_results: Optional[int] = None,
417420
ignore_decoding_errors: bool = False,
418-
executor: Optional["ProcessPoolExecutor"] = None
421+
executor: Optional["ProcessPoolExecutor"] = None,
419422
):
420423
self.records = records
421424
self.page_size = page_size
@@ -441,7 +444,7 @@ async def retrieve_next_page(self, start_key) -> list:
441444
start_key=start_key,
442445
max_results=self.max_results,
443446
ignore_decoding_errors=self.ignore_decoding_errors,
444-
executor=self.executor
447+
executor=self.executor,
445448
)
446449
if len(result.records) < self.page_size:
447450
self.loading_complete = True
@@ -867,7 +870,6 @@ async def encode_scale(
867870
await self._wait_for_registry(_attempt, _retries)
868871
return self._encode_scale(type_string, value)
869872

870-
871873
async def decode_scale(
872874
self,
873875
type_string: str,
@@ -2865,7 +2867,7 @@ async def query_map(
28652867
page_size: int = 100,
28662868
ignore_decoding_errors: bool = False,
28672869
reuse_block_hash: bool = False,
2868-
executor: Optional["ProcessPoolExecutor"] = None
2870+
executor: Optional["ProcessPoolExecutor"] = None,
28692871
) -> AsyncQueryMapResult:
28702872
"""
28712873
Iterates over all key-pairs located at the given module and storage_function. The storage
@@ -2982,13 +2984,15 @@ async def query_map(
29822984
# )
29832985
result = await asyncio.get_running_loop().run_in_executor(
29842986
executor,
2985-
_decode_query_map,
2987+
decode_query_map,
29862988
result_group["changes"],
29872989
prefix,
29882990
runtime.registry.registry,
29892991
param_types,
29902992
params,
2991-
value_type, key_hashers, ignore_decoding_errors
2993+
value_type,
2994+
key_hashers,
2995+
ignore_decoding_errors,
29922996
)
29932997
# max_workers = executor._max_workers
29942998
# result_group_changes_groups = [result_group["changes"][i:i + max_workers] for i in range(0, len(result_group["changes"]), max_workers)]
@@ -3006,13 +3010,15 @@ async def query_map(
30063010
# for r in all_results:
30073011
# result.extend(r)
30083012
else:
3009-
result = _decode_query_map(
3013+
result = decode_query_map(
30103014
result_group["changes"],
30113015
prefix,
30123016
runtime.registry.registry,
30133017
param_types,
30143018
params,
3015-
value_type, key_hashers, ignore_decoding_errors
3019+
value_type,
3020+
key_hashers,
3021+
ignore_decoding_errors,
30163022
)
30173023
return AsyncQueryMapResult(
30183024
records=result,
@@ -3025,7 +3031,7 @@ async def query_map(
30253031
last_key=last_key,
30263032
max_results=max_results,
30273033
ignore_decoding_errors=ignore_decoding_errors,
3028-
executor=executor
3034+
executor=executor,
30293035
)
30303036

30313037
async def submit_extrinsic(

async_substrate_interface/utils/decoding_attempt.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class ScaleObj:
99
def __init__(self, value):
1010
self.value = value
1111

12+
1213
def _decode_scale_with_runtime(
13-
type_string: str,
14-
scale_bytes: bytes,
15-
runtime_registry: "Runtime",
16-
return_scale_obj: bool = False
14+
type_string: str,
15+
scale_bytes: bytes,
16+
runtime_registry: "Runtime",
17+
return_scale_obj: bool = False,
1718
):
1819
if scale_bytes == b"":
1920
return None
@@ -27,8 +28,17 @@ def _decode_scale_with_runtime(
2728
else:
2829
return obj
2930

30-
def _decode_query_map(result_group_changes, prefix, runtime_registry,
31-
param_types, params, value_type, key_hashers, ignore_decoding_errors):
31+
32+
def decode_query_map(
33+
result_group_changes,
34+
prefix,
35+
runtime_registry,
36+
param_types,
37+
params,
38+
value_type,
39+
key_hashers,
40+
ignore_decoding_errors,
41+
):
3242
def concat_hash_len(key_hasher: str) -> int:
3343
"""
3444
Helper function to avoid if statements
@@ -51,16 +61,14 @@ def concat_hash_len(key_hasher: str) -> int:
5161
# Determine type string
5262
key_type_string = []
5363
for n in range(len(params), len(param_types)):
54-
key_type_string.append(
55-
f"[u8; {concat_hash_len(key_hashers[n])}]"
56-
)
64+
key_type_string.append(f"[u8; {concat_hash_len(key_hashers[n])}]")
5765
key_type_string.append(param_types[n])
5866

5967
item_key_obj = _decode_scale_with_runtime(
6068
f"({', '.join(key_type_string)})",
61-
bytes.fromhex(item[0][len(prefix):]),
69+
bytes.fromhex(item[0][len(prefix) :]),
6270
runtime_registry,
63-
False
71+
False,
6472
)
6573

6674
# strip key_hashers to use as item key
@@ -81,10 +89,7 @@ def concat_hash_len(key_hasher: str) -> int:
8189
item_bytes = hex_to_bytes_(item[1])
8290

8391
item_value = _decode_scale_with_runtime(
84-
value_type,
85-
item_bytes,
86-
runtime_registry,
87-
True
92+
value_type, item_bytes, runtime_registry, True
8893
)
8994

9095
except Exception as _:

0 commit comments

Comments
 (0)