Skip to content

Commit 606ee2d

Browse files
committed
extract as helper
1 parent a206f59 commit 606ee2d

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

async_substrate_interface/sync_substrate.py

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
ScaleObj,
3737
)
3838
from async_substrate_interface.utils import hex_to_bytes, json
39+
from async_substrate_interface.utils.decoding import _determine_if_old_runtime_call
3940
from async_substrate_interface.utils.storage import StorageKey
4041
from async_substrate_interface.type_registry import _TYPE_REGISTRY
4142

@@ -2351,37 +2352,10 @@ def runtime_call(
23512352
except KeyError:
23522353
raise ValueError(f"Runtime API Call '{api}.{method}' not found in registry")
23532354

2354-
# Check if the output type is a Vec<u8>
2355-
# If so, call the API using the old method
2356-
output_type_def = [
2357-
x
2358-
for x in metadata_v15_value["types"]["types"]
2359-
if x["id"] == runtime_call_def["output"]
2360-
]
2361-
if output_type_def:
2362-
output_type_def = output_type_def[0]
2363-
2364-
if "sequence" in output_type_def["type"]["def"]:
2365-
output_type_seq_def_id = output_type_def["type"]["def"]["sequence"][
2366-
"type"
2367-
]
2368-
output_type_seq_def = [
2369-
x
2370-
for x in metadata_v15_value["types"]["types"]
2371-
if x["id"] == output_type_seq_def_id
2372-
]
2373-
if output_type_seq_def:
2374-
output_type_seq_def = output_type_seq_def[0]
2375-
if (
2376-
"primitive" in output_type_seq_def["type"]["def"]
2377-
and output_type_seq_def["type"]["def"]["primitive"] == "u8"
2378-
):
2379-
# This is Vec<u8>
2380-
result = self._do_runtime_call_old(
2381-
api, method, params, block_hash
2382-
)
2355+
if _determine_if_old_runtime_call(runtime_call_def, metadata_v15_value):
2356+
result = self._do_runtime_call_old(api, method, params, block_hash)
23832357

2384-
return result
2358+
return result
23852359

23862360
if isinstance(params, list) and len(params) != len(runtime_call_def["inputs"]):
23872361
raise ValueError(
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def _determine_if_old_runtime_call(runtime_call_def, metadata_v15_value) -> bool:
2+
# Check if the output type is a Vec<u8>
3+
# If so, call the API using the old method
4+
output_type_def = [
5+
x
6+
for x in metadata_v15_value["types"]["types"]
7+
if x["id"] == runtime_call_def["output"]
8+
]
9+
if output_type_def:
10+
output_type_def = output_type_def[0]
11+
12+
if "sequence" in output_type_def["type"]["def"]:
13+
output_type_seq_def_id = output_type_def["type"]["def"]["sequence"]["type"]
14+
output_type_seq_def = [
15+
x
16+
for x in metadata_v15_value["types"]["types"]
17+
if x["id"] == output_type_seq_def_id
18+
]
19+
if output_type_seq_def:
20+
output_type_seq_def = output_type_seq_def[0]
21+
if (
22+
"primitive" in output_type_seq_def["type"]["def"]
23+
and output_type_seq_def["type"]["def"]["primitive"] == "u8"
24+
):
25+
return True
26+
return False

0 commit comments

Comments
 (0)