Skip to content
Merged
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
12 changes: 9 additions & 3 deletions async_substrate_interface/substrate_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ def __init__(
ss58_format=self.ss58_format, implements_scale_info=True
)
self.__metadata_cache = {}
self._nonces = {}
self.metadata_version_hex = "0x0f000000" # v15
self.event_loop = event_loop or asyncio.get_event_loop()
self.sync_calls = sync_calls
Expand Down Expand Up @@ -3166,7 +3167,7 @@ async def create_signed_extrinsic(

# Retrieve nonce
if nonce is None:
nonce = await self.get_account_nonce(keypair.ss58_address) or 0
nonce = await self.get_account_next_index(keypair.ss58_address) or 0

# Process era
if era is None:
Expand Down Expand Up @@ -3358,8 +3359,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