Skip to content

Commit ccb2fb8

Browse files
authored
Merge branch 'staging' into feat/thewhaleking/dynamically-pull-vec-account-id
2 parents eee4ac4 + 5569cff commit ccb2fb8

File tree

5 files changed

+98
-23
lines changed

5 files changed

+98
-23
lines changed

CHANGELOG.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,63 @@
11
# Changelog
22

3+
## 1.0.0 /2025-02-13
4+
5+
## What's new
6+
* New Async Substrate Interface by @thewhaleking and @roman-opentensor in https://github.com/opentensor/async-substrate-interface/tree/main
7+
* Github release + bumps version by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/1
8+
* Improve `ScaleObj` by @roman-opentensor in https://github.com/opentensor/async-substrate-interface/pull/2
9+
* Backmerge staging main by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/4
10+
* Release/1.0.0rc2 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/5
11+
* EventLoopManager, factory function by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/3
12+
* Adds nonce implementation by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/8
13+
* Exception for uninitialised by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/6
14+
* Update build/release to use pyproject.toml by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/10
15+
* Fixes nonce management & bumps version by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/11
16+
* Sync Substrate Rewritten by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/9
17+
* Remove ujson by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/12
18+
* Backmerge main to staging rc4 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/13
19+
* Release/1.0.0rc5 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/14
20+
* Update project name for PyPI by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/16
21+
* Fixes _metadata_cache, bumps version and changelog by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/17
22+
* feat: use bt_decode in runtime_call by @zyzniewski-reef in https://github.com/opentensor/async-substrate-interface/pull/15
23+
* Move logic to mixin + fix tests by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/18
24+
* Fix decode scale by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/19
25+
* Backmerge main to staging rc5 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/20
26+
* Release/1.0.0rc7 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/21
27+
* Release/1.0.0rc8 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/22
28+
* Fixes decoding acc ids by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/23
29+
* Backmerge/1.0.0rc8 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/24
30+
* Release/1.0.0rc9 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/25
31+
* Fixes sync ss58 decoding by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/26
32+
* Backmerge main staging rc9 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/27
33+
* Release/1.0.0rc10 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/28
34+
* Reuses the websocket for sync Substrate by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/29
35+
* Feat/metadata v15 cache by @camfairchild in https://github.com/opentensor/async-substrate-interface/pull/30
36+
* Backmerge main to staging rc10 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/31
37+
* Release/1.0.0rc11 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/32
38+
* python 3.9 support by @roman-opentensor in https://github.com/opentensor/async-substrate-interface/pull/33
39+
* Backmerge main to staging RC11 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/34
40+
* Release/1.0.0rc12 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/35
41+
* Improve logging by @roman-opentensor in https://github.com/opentensor/async-substrate-interface/pull/36
42+
* Backmerge main to staging rc12 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/37
43+
* Release/1.0.0rc13 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/38
44+
* Improves the error-handling of initialisation of the object by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/39
45+
* Backmerge main to staging rc12 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/40
46+
* Release/1.0.0rc14 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/41
47+
48+
**Full Changelog**: https://github.com/opentensor/async-substrate-interface/commits/v1.0.0
49+
50+
## 1.0.0rc14 /2025-02-11
51+
* Improves the error-handling of initialisation of the object @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/39
52+
* Backmerge main to staging rc12 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/40
53+
54+
## 1.0.0rc13 /2025-02-10
55+
* Improve logging by @roman-opentensor and @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/36
56+
* Backmerge main to staging rc12 by @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/37
57+
58+
## 1.0.0rc12 /2025-02-07
59+
* python 3.9 support by @roman-opentensor in https://github.com/opentensor/async-substrate-interface/pull/33
60+
361
## 1.0.0rc11 /2025-02-06
462
* Reuses the websocket for sync Substrate by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/29
563
* Feat/metadata v15 cache by @camfairchild in https://github.com/opentensor/async-substrate-interface/pull/30

async_substrate_interface/async_substrate.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
ResultHandler = Callable[[dict, Any], Awaitable[tuple[dict, bool]]]
6363

64+
logger = logging.getLogger("async_substrate_interface")
65+
6466

6567
class AsyncExtrinsicReceipt:
6668
"""
@@ -734,9 +736,13 @@ async def initialize(self):
734736
if not self._chain:
735737
chain = await self.rpc_request("system_chain", [])
736738
self._chain = chain.get("result")
737-
await asyncio.gather(
738-
self.load_registry(), self._first_initialize_runtime()
739+
init_load = await asyncio.gather(
740+
self.load_registry(), self._first_initialize_runtime(),
741+
return_exceptions=True
739742
)
743+
for potential_exception in init_load:
744+
if isinstance(potential_exception, Exception):
745+
raise potential_exception
740746
self.initialized = True
741747
self._initializing = False
742748

@@ -1020,7 +1026,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
10201026
if not self._metadata:
10211027
if self.runtime_version in self._metadata_cache:
10221028
# Get metadata from cache
1023-
logging.debug(
1029+
logger.debug(
10241030
"Retrieved metadata for {} from memory".format(
10251031
self.runtime_version
10261032
)
@@ -1034,7 +1040,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
10341040
metadata = self._metadata = await self.get_block_metadata(
10351041
block_hash=runtime_block_hash, decode=True
10361042
)
1037-
logging.debug(
1043+
logger.debug(
10381044
"Retrieved metadata for {} from Substrate node".format(
10391045
self.runtime_version
10401046
)
@@ -1047,7 +1053,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
10471053

10481054
if self.runtime_version in self._metadata_v15_cache:
10491055
# Get metadata v15 from cache
1050-
logging.debug(
1056+
logger.debug(
10511057
"Retrieved metadata v15 for {} from memory".format(
10521058
self.runtime_version
10531059
)
@@ -1059,7 +1065,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
10591065
metadata_v15 = (
10601066
self._old_metadata_v15
10611067
) = await self._load_registry_at_block(block_hash=runtime_block_hash)
1062-
logging.debug(
1068+
logger.debug(
10631069
"Retrieved metadata v15 for {} from Substrate node".format(
10641070
self.runtime_version
10651071
)
@@ -1072,7 +1078,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
10721078
self.reload_type_registry(use_remote_preset=False, auto_discover=True)
10731079

10741080
if self.implements_scaleinfo:
1075-
logging.debug("Add PortableRegistry from metadata to type registry")
1081+
logger.debug("Add PortableRegistry from metadata to type registry")
10761082
self.runtime_config.add_portable_registry(metadata)
10771083

10781084
# Set active runtime version
@@ -1108,6 +1114,11 @@ async def get_runtime(block_hash, block_id) -> Runtime:
11081114
if block_id and block_hash:
11091115
raise ValueError("Cannot provide block_hash and block_id at the same time")
11101116

1117+
if not self.metadata_v15:
1118+
raise SubstrateRequestException(
1119+
"Metadata V15 was not loaded. This usually indicates that you did not correctly initialize"
1120+
" the AsyncSubstrateInterface class with `async with` or by calling `initialize()`"
1121+
)
11111122
if (
11121123
not (runtime := self.runtime_cache.retrieve(block_id, block_hash))
11131124
or runtime.metadata is None
@@ -1991,14 +2002,14 @@ async def _make_rpc_request(
19912002
break
19922003
if time.time() - self.ws.last_received >= self.retry_timeout:
19932004
if attempt >= self.max_retries:
1994-
logging.warning(
2005+
logger.warning(
19952006
f"Timed out waiting for RPC requests {attempt} times. Exiting."
19962007
)
19972008
raise SubstrateRequestException("Max retries reached.")
19982009
else:
19992010
self.ws.last_received = time.time()
20002011
await self.ws.connect(force=True)
2001-
logging.error(
2012+
logger.error(
20022013
f"Timed out waiting for RPC requests. "
20032014
f"Retrying attempt {attempt + 1} of {self.max_retries}"
20042015
)
@@ -2070,7 +2081,7 @@ async def rpc_request(
20702081
"Failed to get runtime version"
20712082
in result[payload_id][0]["error"]["message"]
20722083
):
2073-
logging.warning(
2084+
logger.warning(
20742085
"Failed to get runtime. Re-fetching from chain, and retrying."
20752086
)
20762087
await self.init_runtime()
@@ -2547,7 +2558,7 @@ async def _do_runtime_call_old(
25472558
params: Optional[Union[list, dict]] = None,
25482559
block_hash: Optional[str] = None,
25492560
) -> ScaleType:
2550-
logging.debug(
2561+
logger.debug(
25512562
f"Decoding old runtime call: {api}.{method} with params: {params} at block hash: {block_hash}"
25522563
)
25532564
runtime_call_def = _TYPE_REGISTRY["runtime_api"][api]["methods"][method]
@@ -2585,7 +2596,7 @@ async def _do_runtime_call_old(
25852596
# Get correct type
25862597
result_decoded = runtime_call_def["decoder"](bytes(result_bytes))
25872598
as_dict = _bt_decode_to_dict_or_list(result_decoded)
2588-
logging.debug("Decoded old runtime call result: ", as_dict)
2599+
logger.debug("Decoded old runtime call result: ", as_dict)
25892600
result_obj = ScaleObj(as_dict)
25902601

25912602
return result_obj

async_substrate_interface/sync_substrate.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
ResultHandler = Callable[[dict, Any], tuple[dict, bool]]
4343

44+
logger = logging.getLogger("async_substrate_interface")
45+
4446

4547
class ExtrinsicReceipt:
4648
"""
@@ -771,7 +773,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
771773
if not self._metadata:
772774
if self.runtime_version in self._metadata_cache:
773775
# Get metadata from cache
774-
logging.debug(
776+
logger.debug(
775777
"Retrieved metadata for {} from memory".format(
776778
self.runtime_version
777779
)
@@ -783,7 +785,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
783785
metadata = self._metadata = self.get_block_metadata(
784786
block_hash=runtime_block_hash, decode=True
785787
)
786-
logging.debug(
788+
logger.debug(
787789
"Retrieved metadata for {} from Substrate node".format(
788790
self.runtime_version
789791
)
@@ -796,7 +798,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
796798

797799
if self.runtime_version in self._metadata_v15_cache:
798800
# Get metadata v15 from cache
799-
logging.debug(
801+
logger.debug(
800802
"Retrieved metadata v15 for {} from memory".format(
801803
self.runtime_version
802804
)
@@ -808,7 +810,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
808810
metadata_v15 = self._old_metadata_v15 = self._load_registry_at_block(
809811
block_hash=runtime_block_hash
810812
)
811-
logging.debug(
813+
logger.debug(
812814
"Retrieved metadata v15 for {} from Substrate node".format(
813815
self.runtime_version
814816
)
@@ -820,7 +822,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
820822
self.reload_type_registry(use_remote_preset=False, auto_discover=True)
821823

822824
if self.implements_scaleinfo:
823-
logging.debug("Add PortableRegistry from metadata to type registry")
825+
logger.debug("Add PortableRegistry from metadata to type registry")
824826
self.runtime_config.add_portable_registry(metadata)
825827

826828
# Set active runtime version
@@ -1693,7 +1695,7 @@ def _make_rpc_request(
16931695
response = json.loads(ws.recv(timeout=self.retry_timeout, decode=False))
16941696
except (TimeoutError, ConnectionClosed):
16951697
if attempt >= self.max_retries:
1696-
logging.warning(
1698+
logger.warning(
16971699
f"Timed out waiting for RPC requests {attempt} times. Exiting."
16981700
)
16991701
raise SubstrateRequestException("Max retries reached.")
@@ -1804,7 +1806,7 @@ def rpc_request(
18041806
"Failed to get runtime version"
18051807
in result[payload_id][0]["error"]["message"]
18061808
):
1807-
logging.warning(
1809+
logger.warning(
18081810
"Failed to get runtime. Re-fetching from chain, and retrying."
18091811
)
18101812
self.init_runtime()
@@ -2268,7 +2270,7 @@ def _do_runtime_call_old(
22682270
params: Optional[Union[list, dict]] = None,
22692271
block_hash: Optional[str] = None,
22702272
) -> ScaleType:
2271-
logging.debug(
2273+
logger.debug(
22722274
f"Decoding old runtime call: {api}.{method} with params: {params} at block hash: {block_hash}"
22732275
)
22742276
runtime_call_def = _TYPE_REGISTRY["runtime_api"][api]["methods"][method]
@@ -2304,7 +2306,7 @@ def _do_runtime_call_old(
23042306
# Get correct type
23052307
result_decoded = runtime_call_def["decoder"](bytes(result_bytes))
23062308
as_dict = _bt_decode_to_dict_or_list(result_decoded)
2307-
logging.debug("Decoded old runtime call result: ", as_dict)
2309+
logger.debug("Decoded old runtime call result: ", as_dict)
23082310
result_obj = ScaleObj(as_dict)
23092311

23102312
return result_obj

async_substrate_interface/types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from .utils import json
1717

1818

19+
logger = logging.getLogger("async_substrate_interface")
20+
21+
1922
class RuntimeCache:
2023
blocks: dict[int, "Runtime"]
2124
block_hashes: dict[str, "Runtime"]
@@ -342,6 +345,7 @@ class SubstrateMixin(ABC):
342345
_token_decimals = None
343346
_token_symbol = None
344347
_metadata = None
348+
metadata_v15 = None
345349
_chain: str
346350
runtime_config: RuntimeConfigurationObject
347351
type_registry: Optional[dict]
@@ -713,7 +717,7 @@ def apply_type_registry_presets(
713717
type_registry_preset_dict = load_type_registry_preset(
714718
type_registry_name
715719
)
716-
logging.debug(
720+
logger.debug(
717721
f"Auto set type_registry_preset to {type_registry_name} ..."
718722
)
719723
self.type_registry_preset = type_registry_name

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "async-substrate-interface"
3-
version = "1.0.0rc11"
3+
version = "1.0.0"
44
description = "Asyncio library for interacting with substrate. Mostly API-compatible with py-substrate-interface"
55
readme = "README.md"
66
license = { file = "LICENSE" }

0 commit comments

Comments
 (0)