Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 12 additions & 4 deletions async_substrate_interface/async_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down