diff --git a/CHANGELOG.md b/CHANGELOG.md index 07681b1..7c8a824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ -## 1.0.0rc1 /2025-01-13 +# Changelog + +## 1.0.0rc3 /2025-01-17 + +## What's Changed +* Adds nonce implementation @ibraheem-opentensor in https://github.com/opentensor/async-substrate-interface/pull/8 + +## 1.0.0rc2 /2025-01-15 + +## What's Changed +* Improve ScaleObj by @roman-opentensor in https://github.com/opentensor/async-substrate-interface/pull/2 + +## 1.0.0rc1 /2025-01-15 ## What's Changed * New Async Substrate Interface by @thewhaleking and @roman-opentensor in https://github.com/opentensor/async-substrate-interface/tree/main diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index b1f33a6..9c46a37 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -699,7 +699,8 @@ def __init__( self.runtime_config = RuntimeConfigurationObject( ss58_format=self.ss58_format, implements_scale_info=True ) - self._metadata_cache = {} + self.__metadata_cache = {} + self._nonces = {} self.metadata_version_hex = "0x0f000000" # v15 self.reload_type_registry() self._initializing = False @@ -2578,7 +2579,9 @@ async def get_account_nonce(self, account_address: str) -> int: async def get_account_next_index(self, account_address: str) -> int: """ - Returns next index for the given account address, taking into account the transaction pool. + This method maintains a cache of nonces for each account ss58address. + Upon subsequent calls, it will return the cached nonce + 1 instead of fetching from the chain. + This allows for correct nonce management in-case of async context when gathering co-routines. Args: account_address: SS58 formatted address @@ -2590,8 +2593,13 @@ async def get_account_next_index(self, account_address: str) -> int: # Unlikely to happen, this is a common RPC method raise Exception("account_nextIndex not supported") - nonce_obj = await self.rpc_request("account_nextIndex", [account_address]) - return nonce_obj["result"] + async with self._lock: + if self._nonces.get(account_address) is None: + nonce_obj = await self.rpc_request("account_nextIndex", [account_address]) + self._nonces[account_address] = nonce_obj["result"] + else: + self._nonces[account_address] += 1 + return self._nonces[account_address] async def get_metadata_constant(self, module_name, constant_name, block_hash=None): """ diff --git a/pyproject.toml b/pyproject.toml index 6f82643..ef6e883 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "async-substrate-interface" -version = "1.0.0rc1" +version = "1.0.0rc4" description = "Asyncio library for interacting with substrate. Mostly API-compatible with py-substrate-interface" readme = "README.md" license = { file = "LICENSE" }